|
| 1 | +/* |
| 2 | + * This file is part of Cockpit. |
| 3 | + * |
| 4 | + * Copyright (C) 2025 Red Hat, Inc. |
| 5 | + * |
| 6 | + * Cockpit is free software; you can redistribute it and/or modify it |
| 7 | + * under the terms of the GNU Lesser General Public License as published by |
| 8 | + * the Free Software Foundation; either version 2.1 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * Cockpit is distributed in the hope that it will be useful, but |
| 12 | + * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | + * Lesser General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU Lesser General Public License |
| 17 | + * along with Cockpit; If not, see <http://www.gnu.org/licenses/>. |
| 18 | + */ |
| 19 | + |
| 20 | +import React from 'react'; |
| 21 | +import cockpit from 'cockpit'; |
| 22 | + |
| 23 | +import { Button } from "@patternfly/react-core/dist/esm/components/Button"; |
| 24 | +import { Text, TextContent, TextVariants, TextList, TextListItem, TextListItemVariants, TextListVariants } from "@patternfly/react-core/dist/esm/components/Text"; |
| 25 | +import { ClipboardCopy } from "@patternfly/react-core/dist/esm/components/ClipboardCopy/index.js"; |
| 26 | +import { fmt_to_fragments } from 'utils.jsx'; |
| 27 | +import { domainDesktopConsole } from '../../../libvirtApi/domain.js'; |
| 28 | + |
| 29 | +const _ = cockpit.gettext; |
| 30 | + |
| 31 | +export function connection_address() { |
| 32 | + let address; |
| 33 | + if (cockpit.transport.host == "localhost") { |
| 34 | + const app = cockpit.transport.application(); |
| 35 | + if (app.startsWith("cockpit+=")) { |
| 36 | + address = app.substr(9); |
| 37 | + } else { |
| 38 | + address = window.location.hostname; |
| 39 | + } |
| 40 | + } else { |
| 41 | + address = cockpit.transport.host; |
| 42 | + const pos = address.indexOf("@"); |
| 43 | + if (pos >= 0) { |
| 44 | + address = address.substr(pos + 1); |
| 45 | + } |
| 46 | + } |
| 47 | + return address; |
| 48 | +} |
| 49 | + |
| 50 | +export function console_launch(vm, consoleDetail) { |
| 51 | + // fire download of the .vv file |
| 52 | + domainDesktopConsole({ name: vm.name, consoleDetail: { ...consoleDetail, address: connection_address() } }); |
| 53 | +} |
| 54 | + |
| 55 | +export const RemoteConnectionInfo = ({ hide, url, onEdit }) => { |
| 56 | + function TLI(term, description) { |
| 57 | + // What is this? Java? |
| 58 | + return ( |
| 59 | + <> |
| 60 | + <TextListItem component={TextListItemVariants.dt}>{term}</TextListItem> |
| 61 | + <TextListItem component={TextListItemVariants.dd}>{description}</TextListItem> |
| 62 | + </> |
| 63 | + ); |
| 64 | + } |
| 65 | + |
| 66 | + return ( |
| 67 | + <TextContent> |
| 68 | + <Text component={TextVariants.p}> |
| 69 | + {fmt_to_fragments(_("Clicking \"Launch viewer\" will download a $0 file and launch the Remote Viewer application on your system."), <code>.vv</code>)} |
| 70 | + </Text> |
| 71 | + <Text component={TextVariants.p}> |
| 72 | + {_("Remote Viewer is available for most operating systems. To install it, search for \"Remote Viewer\" in GNOME Software, KDE Discover, or run the following:")} |
| 73 | + </Text> |
| 74 | + <TextList component={TextListVariants.dl}> |
| 75 | + {TLI(_("RHEL, CentOS"), <code>sudo yum install virt-viewer</code>)} |
| 76 | + {TLI(_("Fedora"), <code>sudo dnf install virt-viewer</code>)} |
| 77 | + {TLI(_("Ubuntu, Debian"), <code>sudo apt-get install virt-viewer</code>)} |
| 78 | + {TLI(_("Windows"), |
| 79 | + fmt_to_fragments( |
| 80 | + _("Download the MSI from $0"), |
| 81 | + <a href="https://virt-manager.org/download" target="_blank" rel="noopener noreferrer"> |
| 82 | + virt-manager.org |
| 83 | + </a>))} |
| 84 | + </TextList> |
| 85 | + { url && |
| 86 | + <> |
| 87 | + <Text component={TextVariants.p}> |
| 88 | + {_("Other remote viewer applications can connect to the following address:")} |
| 89 | + </Text> |
| 90 | + <ClipboardCopy |
| 91 | + hoverTip={_("Copy to clipboard")} |
| 92 | + clickTip={_("Successfully copied to clipboard!")} |
| 93 | + variant="inline-compact" |
| 94 | + > |
| 95 | + {url} |
| 96 | + </ClipboardCopy> |
| 97 | + <Text component={TextVariants.p} /> |
| 98 | + </> |
| 99 | + } |
| 100 | + { onEdit && |
| 101 | + <Button isInline variant="link" onClick={() => { hide(); onEdit() }}> |
| 102 | + {_("Set port and password")} |
| 103 | + </Button> |
| 104 | + } |
| 105 | + </TextContent> |
| 106 | + ); |
| 107 | +}; |
0 commit comments