diff --git a/webui/src/App.tsx b/webui/src/App.tsx index 7ef310c24..306d05f91 100644 --- a/webui/src/App.tsx +++ b/webui/src/App.tsx @@ -1113,11 +1113,26 @@ function Shell({ const { t, i18n } = useTranslation(); const remoteConnections = useRemoteConnections(); const localActive = remoteConnections?.localActive !== false; - const managingConnections = remoteConnections?.managing === true; + const managingConnections = remoteConnections?.managing === true && !remoteConnections?.activeHostId; + const { theme, toggle } = useTheme(); + const managementMain = useRef(null); + const reportManagementSurface = remoteConnections?.reportManagementSurface; + useEffect(() => { + const main = managementMain.current; + if (!main || !reportManagementSurface) return; + const report = () => { + const rect = main.getBoundingClientRect(); + reportManagementSurface({ left: rect.left, top: rect.top, width: rect.width, height: rect.height }, theme); + }; + const observer = new ResizeObserver(report); + observer.observe(main); + window.addEventListener("resize", report); + report(); + return () => { observer.disconnect(); window.removeEventListener("resize", report); }; + }, [reportManagementSurface, theme]); const remoteConnectionsRef = useRef(remoteConnections); remoteConnectionsRef.current = remoteConnections; const { client, getToken } = useClient(); - const { theme, toggle } = useTheme(); const { sessions, loading, @@ -1277,9 +1292,9 @@ function Shell({ const navigate = useCallback( (route: ShellRoute, options?: { replace?: boolean }) => { const leave = () => { - // Navigating the local sidebar is an explicit choice of a local view. - // Merely opening global connection management does not switch hosts. - if (remoteConnectionsRef.current?.managing) remoteConnectionsRef.current.selectLocal(); + // The visible sidebar always belongs to its existing host. Navigation + // dismisses global management without switching to a different host. + if (remoteConnectionsRef.current?.managing) remoteConnectionsRef.current.closeManagement(); setActiveKey(route.activeKey); setView(route.view); setSettingsInitialSection(route.settingsSection); @@ -2887,7 +2902,9 @@ function Shell({ /> ) : null} -
)} - {managingConnections &&
+ {managingConnections && !remoteConnections?.embeddedManagement &&
void; +}) { + const { t } = useTranslation(); + // Radix keeps closed content mounted until its exit animation finishes. + const lastProfile = useRef(profile); + useEffect(() => { if (profile) lastProfile.current = profile; }, [profile]); + const displayedProfile = profile || lastProfile.current; + const report = displayedProfile?.compatibility; + const status = report?.status || "unchecked"; + const compatible = status === "compatible"; + return { if (!open) onClose(); }}> + + + {t("remote.compatibility.title")} + {displayedProfile?.name} · {displayedProfile?.host} + + +
+ {[{ label: t("remote.compatibility.client"), version: report?.client_version || clientVersion }, + { label: t("remote.compatibility.host"), version: report?.host_version }].map(({ label, version }) => +
+
{label}
+
{version || t("remote.compatibility.unreported")}
+
)} +
+
+
+ {compatible ? + : } +

{t(`remote.compatibility.${status}`)}

+

{t(`remote.compatibility.${status}Hint`)}

+
+ {report && !compatible &&
+ {t("remote.compatibility.preparation")} +

{t(status === "update_client" ? "remote.compatibility.localUpdateHint" : "remote.compatibility.serverUpdateHint")}

+
} +
+ + {report && !compatible && } +
+
+
; +} diff --git a/webui/src/components/remote/HostSwitcher.tsx b/webui/src/components/remote/HostSwitcher.tsx index d37c9e954..ea5baba7d 100644 --- a/webui/src/components/remote/HostSwitcher.tsx +++ b/webui/src/components/remote/HostSwitcher.tsx @@ -21,6 +21,7 @@ export interface HostPicker { pending: { id: string; name: string } | null; error: string; offline: boolean; + offlineLabel?: string; select: (id: string | null) => void; manage: () => void; cancel: () => void; @@ -133,13 +134,18 @@ export function HostSwitcher({ collapsed = false, portalContainer }: { collapsed const shell = picker.kind === "shell" ? picker : null; const remote = picker.kind === "embedded" || !!shell?.currentId; const pendingName = picker.kind === "shell" ? picker.pending?.name : picker.pendingName; + const currentStatus = shell?.currentId + ? (shell.pending?.id === shell.currentId || shell.profiles.find((profile) => profile.id === shell.currentId)?.state === "connecting" ? "connecting" : shell.offline ? "closed" : "open") + : status; // A failed switch describes the destination, not the still-active connection. - const failed = !!shell?.offline || status === "error" || status === "closed"; - const waiting = !!pendingName || status === "connecting" || status === "reconnecting"; + const failed = !!shell?.offline || currentStatus === "error" || currentStatus === "closed"; + const waiting = !!pendingName || currentStatus === "connecting" || currentStatus === "reconnecting"; // The old host stays interactive until the new one is ready. Keep its identity // visible; progress belongs to the target's row and the accessible status. const label = picker.name; - const current = `${picker.name} · ${picker.hostname} · ${t(failed ? "remote.offline" : `connection.${status}`)}`; + const currentLabel = failed ? shell?.offlineLabel || t("remote.offline") : t(`connection.${currentStatus}`); + const identity = picker.name === picker.hostname ? picker.name : `${picker.name} · ${picker.hostname}`; + const current = `${identity} · ${currentLabel}`; const detail = pendingName ? `${current} · ${t("remote.preparing", { name: pendingName })}` : current; const title = picker.error ? `${detail} — ${picker.error}` : detail; const button =
diff --git a/webui/src/components/remote/QuickPairSetup.tsx b/webui/src/components/remote/QuickPairSetup.tsx index 455735f9c..33424a225 100644 --- a/webui/src/components/remote/QuickPairSetup.tsx +++ b/webui/src/components/remote/QuickPairSetup.tsx @@ -14,13 +14,14 @@ import { pairingReturnOrigin, type PairReturn } from "@/lib/remote-pair-return"; import type { ConnectionStatus } from "@/lib/types"; import { useRemoteConnections } from "./RemoteInstances"; import { PairRouteSettings } from "./PairRouteSettings"; +import "./remote-layout.css"; type Request = { id: string; command: string; expires: number }; type Preview = { id: string; host: string; hostname: string; fingerprint: string; authorized_until: number; revoke_command: string; existing_connection?: { id: string; name: string; connected: boolean } }; /** Public invitation → encrypted receipt → explicit confirmation. No private key inputs. */ -export function QuickPairSetup({ returned, onSSH, onClose }: { returned?: PairReturn | null; onSSH: () => void; onClose: () => void }) { +export function QuickPairSetup({ returned, active = true, onSSH, onClose }: { returned?: PairReturn | null; active?: boolean; onSSH: () => void; onClose: () => void }) { const { t } = useTranslation(); const { client } = useClient(); const connections = useRemoteConnections(); @@ -56,14 +57,14 @@ export function QuickPairSetup({ returned, onSSH, onClose }: { returned?: PairRe }, [pending]); useEffect(() => { - alive.current = true; + alive.current = active; return () => { alive.current = false; // A link opens in a new tab. Closing/reloading the originating page must // not destroy its key before the new page can validate the receipt. // Pending invitations are bounded and expire in PairStore. }; - }, [client]); + }, [client, active]); useEffect(() => { if (!request?.expires || saved) return; const timer = window.setTimeout(() => setExpired(true), Math.max(0, request.expires * 1000 - Date.now())); @@ -75,7 +76,10 @@ export function QuickPairSetup({ returned, onSSH, onClose }: { returned?: PairRe try { await action(); } catch (reason) { const localFailure = reason instanceof Error && "status" in reason && [503, 504].includes(Number(reason.status)); - if (alive.current) setError(`remote.errors.${localFailure ? "local_connection_unavailable" : reason instanceof Error ? reason.message : "unknown"}`); + if (alive.current) { + const code = localFailure ? "local_connection_unavailable" : reason instanceof Error ? reason.message : "unknown"; + setError(`remote.errors.${code}`); + } } finally { if (alive.current) setBusy(false); } }; const start = () => run(async () => { @@ -106,7 +110,7 @@ export function QuickPairSetup({ returned, onSSH, onClose }: { returned?: PairRe }); useEffect(() => { - if (initialized.current) return; + if (!active || initialized.current) return; // A return link mounts immediately after bootstrap, before the local socket // opens. Wait for it; rejecting here would mislabel a valid link as invalid. if (status !== "open") { @@ -118,7 +122,7 @@ export function QuickPairSetup({ returned, onSSH, onClose }: { returned?: PairRe else void start(); // One invitation per mounted dialog, never one per re-render. The returned // receipt is reviewed only; saving/connecting still requires a user click. - }, [status]); + }, [status, active]); const copyCommand = () => { if (!request) return; void copyTextToClipboard(request.command).then((ok) => { @@ -128,44 +132,46 @@ export function QuickPairSetup({ returned, onSSH, onClose }: { returned?: PairRe }); }; const invalidReturn = ["pair_invalid", "pair_expired", "pair_used"].some((code) => error === `remote.errors.${code}`); - const restartAvailable = !saved && (expired || (!!error && !request?.command && !preview && (!returned || invalidReturn))); - const reviewingReturn = !!returned && !request?.command && !preview && !manual && !restartAvailable; - const title = preview ? preview.existing_connection ? "remote.sameInstance.title" : "remote.pair.confirmTitle" : reviewingReturn ? "remote.pair.review" : restartAvailable ? "remote.add" + const requestUnavailable = error === "remote.errors.pair_expired" || error === "remote.errors.pair_used"; + const restartAvailable = !saved && (expired || requestUnavailable || (!!error && !request?.command && !preview && (!returned || invalidReturn))); + const visiblePreview = restartAvailable ? null : preview; + const reviewingReturn = !!returned && !request?.command && !visiblePreview && !manual && !restartAvailable; + const title = visiblePreview ? visiblePreview.existing_connection ? "remote.sameInstance.title" : "remote.pair.confirmTitle" : reviewingReturn ? "remote.pair.review" : restartAvailable ? "remote.add" : manual ? "remote.pair.code" : copied ? "remote.pair.copiedTitle" : "remote.add"; - const description = preview || reviewingReturn ? "remote.pair.confirmLinkDescription" : restartAvailable ? "remote.pair.introHint" + const description = visiblePreview || reviewingReturn ? "remote.pair.confirmLinkDescription" : restartAvailable ? "remote.pair.introHint" : manual ? "remote.pair.codeHint" : copied ? "remote.pair.afterCopyHint" : "remote.pair.introHint"; - const showCopied = copied && !manual && !preview && !restartAvailable; - const showIllustration = !preview && !manual && !reviewingReturn && !restartAvailable; + const showCopied = copied && !manual && !visiblePreview && !restartAvailable; + const showIllustration = !visiblePreview && !manual && !reviewingReturn && !restartAvailable; const showBusy = pending && busyVisible; - const actionLabel = restartAvailable ? "remote.pair.restart" : reviewingReturn ? error ? "remote.retry" : "remote.pair.review" : preview ? saved ? "remote.retry" : preview.existing_connection ? "remote.sameInstance.saveAndOpen" : "remote.connect" + const actionLabel = restartAvailable ? "remote.pair.restart" : reviewingReturn ? error ? "remote.retry" : "remote.pair.review" : visiblePreview ? saved ? "remote.retry" : visiblePreview.existing_connection ? "remote.sameInstance.saveAndOpen" : "remote.connect" : manual ? "remote.pair.review" : copied ? "remote.pair.copyAgain" : "remote.pair.copy"; - const busyLabel = waitingForLocal ? "remote.pair.waitingForLocal" : preview ? "remote.connecting" : !restartAvailable && (manual || returned) + const busyLabel = waitingForLocal ? "remote.pair.waitingForLocal" : visiblePreview ? "remote.connecting" : !restartAvailable && (manual || returned) ? "remote.pair.checkingLink" : "remote.pair.preparing"; - return
+ return
{showIllustration && }
{showCopied && {t(description)}
- {preview ?
+ {visiblePreview ?
-

{preview.existing_connection?.name || preview.hostname}

-

{preview.host}

+

{visiblePreview.existing_connection?.name || visiblePreview.hostname}

+

{visiblePreview.host}

- {preview.existing_connection &&

{t("remote.sameInstance.pairHint")}

} + {visiblePreview.existing_connection &&

{t("remote.sameInstance.pairHint")}

}

{t("remote.pair.access")}

-

{t("remote.pair.expiry", { date: new Date(preview.authorized_until * 1000).toLocaleDateString() })}

+

{t("remote.pair.expiry", { date: new Date(visiblePreview.authorized_until * 1000).toLocaleDateString() })}

{t("remote.pair.security")}}> -

{t("remote.pair.fingerprint")}

{preview.fingerprint} -

{t("remote.pair.revoke")}

+

{t("remote.pair.fingerprint")}

{visiblePreview.fingerprint} +

{t("remote.pair.revoke")}

{saved && error &&

{t("remote.pair.retryHint")}

- {request?.command} + {request?.command}
@@ -192,21 +198,21 @@ export function QuickPairSetup({ returned, onSSH, onClose }: { returned?: PairRe
} {expired && !saved &&

{t("remote.pair.expired")}

} - {error &&

} + {error &&

}
-
- {preview && (!saved ? - : +
+ {visiblePreview && (!saved ? + : )} - - {!preview &&
- {request?.command ? manual ? - : : } + {!visiblePreview &&
+ {!restartAvailable && request?.command ? manual ? + : : } - + { if (focusManual.current) { event.preventDefault(); focusManual.current = false; manualInput.current?.focus(); } }}> diff --git a/webui/src/components/remote/RemoteConnectionsPage.tsx b/webui/src/components/remote/RemoteConnectionsPage.tsx index 46308932f..05126b8d2 100644 --- a/webui/src/components/remote/RemoteConnectionsPage.tsx +++ b/webui/src/components/remote/RemoteConnectionsPage.tsx @@ -9,7 +9,7 @@ import { DisclosureContent } from "@/components/ui/disclosure"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "@/components/ui/dialog"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"; import { useClient } from "@/providers/ClientProvider"; -import { groupRemoteProfiles, remoteAction, type RemoteInspection, type RemoteProfile } from "@/lib/remote-instances"; +import { groupRemoteProfiles, isCompatibilityError, remoteAction, type RemoteInspection, type RemoteProfile } from "@/lib/remote-instances"; import { cn } from "@/lib/utils"; import { parseSSHAddress } from "@/lib/ssh-address"; import { clearPairReturn, readPairReturn, subscribePairReturn } from "@/lib/remote-pair-return"; @@ -18,6 +18,8 @@ import { SSHHostPicker } from "./SSHHostPicker"; import { QuickPairSetup } from "./QuickPairSetup"; import { PairRouteSettings } from "./PairRouteSettings"; import { HostConnectionStatus } from "./HostConnectionStatus"; +import { HostCompatibilityDialog } from "./HostCompatibilityDialog"; +import "./remote-layout.css"; const emptyProfile = (): Omit => ({ name: "", host: "", port: null, ssh_config: "", identity_file: "", @@ -37,8 +39,12 @@ export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChro const [editorOpen, setEditorOpen] = useState(false); const returnedPair = useSyncExternalStore(subscribePairReturn, readPairReturn); const [quickOpen, setQuickOpen] = useState(!!returnedPair); + const [quickReturn, setQuickReturn] = useState(returnedPair); const [pairRoute, setPairRoute] = useState(""); const [details, setDetails] = useState(""); + const [detailsOpen, setDetailsOpen] = useState(false); + const [routeOpen, setRouteOpen] = useState(false); + const [versionId, setVersionId] = useState(""); const [renaming, setRenaming] = useState(null); const [name, setName] = useState(""); const [renameError, setRenameError] = useState(""); @@ -73,7 +79,7 @@ export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChro useEffect(() => { if (removing) lastRemoval.current = removing; }, [removing]); useEffect(() => { if (disconnecting) lastDisconnect.current = disconnecting; }, [disconnecting]); - useEffect(() => { if (returnedPair) setQuickOpen(true); }, [returnedPair]); + useEffect(() => { if (returnedPair) { setQuickReturn(returnedPair); setQuickOpen(true); } }, [returnedPair]); useEffect(() => { mounted.current = true; @@ -168,6 +174,15 @@ export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChro if (wanted(attempt)) { setEditorOpen(false); setFingerprint(null); } } catch (reason) { if (!wanted(attempt)) return; + if (reason instanceof Error && reason.message === "local_webui_unavailable") { + showError(reason); + return; + } + if (reason instanceof Error && isCompatibilityError(reason.message)) { + await refresh?.().catch(() => {}); + if (wanted(attempt)) { setEditorOpen(false); setVersionId(id); showError(reason); } + return; + } if (reason instanceof Error && reason.message === "host_key_unknown") { try { const result = await remoteAction<{ fingerprint: string; challenge: string }>(client, "fingerprint", { id }); @@ -269,10 +284,10 @@ export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChro const detailConnection = detailGroup?.connections.find((profile) => profile.connected || connections.openHostIds.includes(profile.id)); const removalIsShared = groups.some((group) => group.connections.length > 1 && group.connections.some((profile) => profile.id === removalProfile?.id)); const connectionActions = (profile: RemoteProfile, grouped = false) => <> - {!profile.paired && { setDetails(""); beginEditor(profile); }}>{t("remote.edit")}} - {profile.paired && { setDetails(""); setPairRoute(profile.id); }}>{t("remote.pair.route")}} - {(profile.connected || connections.openHostIds.includes(profile.id)) && { setDetails(""); setError(""); setDisconnecting(profile); }}>{t("remote.disconnect")}} - { setDetails(""); setError(""); setRemoving(profile); }}>{t(grouped ? "remote.sameInstance.forgetConnection" : "remote.forget")} + {!profile.paired && { setDetailsOpen(false); beginEditor(profile); }}>{t("remote.edit")}} + {profile.paired && { setDetailsOpen(false); setPairRoute(profile.id); setRouteOpen(true); }}>{t("remote.pair.route")}} + {(profile.connected || connections.openHostIds.includes(profile.id)) && { setDetailsOpen(false); setError(""); setDisconnecting(profile); }}>{t("remote.disconnect")}} + { setDetailsOpen(false); setError(""); setRemoving(profile); }}>{t(grouped ? "remote.sameInstance.forgetConnection" : "remote.forget")} ; return
@@ -309,6 +324,9 @@ export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChro {profile.name}{profile.host} {groups.some((other) => other.id !== groupId && other.profile.name === profile.name && other.profile.host === profile.host) && {profile.port ? `:${profile.port} · ` : ""}{profile.config_path}} + {profile.compatibility && profile.compatibility.status !== "compatible" && + {t(`remote.compatibility.${profile.compatibility.status}`)} + } {profile.paired && typeof profile.authorized_until === "number" && Number.isFinite(profile.authorized_until) && profile.authorized_until * 1000 <= Date.now() + 7 * 86_400_000 && {t(profile.authorized_until * 1000 <= Date.now() ? "remote.pair.expiredDevice" : "remote.pair.expiringDevice", { @@ -324,7 +342,8 @@ export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChro aria-label={t("remote.manage", { name: profile.name })}> { setRenaming(profile); setName(profile.name); setRenameError(""); }}>{t("remote.rename.action")} - {entries.length > 1 ? setDetails(groupId)}>{t("remote.sameInstance.details")} : connectionActions(profile)} + setVersionId(profile.id)}>{t("remote.compatibility.title")} + {entries.length > 1 ? { setDetails(groupId); setDetailsOpen(true); }}>{t("remote.sameInstance.details")} : connectionActions(profile)}
)} @@ -333,14 +352,14 @@ export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChro

{t("remote.preparing", { name: openingProfile.name })}

} -
} {!directory && !directoryError &&
{t("remote.loading")}
} {directory && !directory.available &&

{t("remote.unavailable")}

} {pageError && !editorOpen && !fingerprint && !removing && !disconnecting &&
-

+

{directoryError && } @@ -349,8 +368,10 @@ export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChro
+ profile.id === versionId)} + clientVersion={directory?.client_version} onClose={() => setVersionId("")} /> { if (!open && !busy) setRenaming(null); }}> - { + { event.preventDefault(); nameInput.current?.focus(); nameInput.current?.select(); }} onCloseAutoFocus={(event) => { event.preventDefault(); editorTrigger.current?.focus({ preventScroll: true }); }}> @@ -358,14 +379,12 @@ export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChro {t("remote.rename.hint")}
{ event.preventDefault(); void rename(); }}> -
- - { setName(event.target.value); setRenameError(""); }} /> -
+ { setName(event.target.value); setRenameError(""); }} /> {renameError && } -
+
- { if (!open) setDetails(""); }}> - + { if (!open) setDetailsOpen(false); }}> + {t("remote.sameInstance.details")}{t("remote.sameInstance.detailsHint")}
{detailGroup?.connections.map((profile, index) =>
{ setQuickOpen(open); if (!open) clearPairReturn(); }}> - - {quickOpen && { clearPairReturn(); setQuickOpen(false); beginEditor(); }} onClose={() => { clearPairReturn(); setQuickOpen(false); }} />} + + { clearPairReturn(); setQuickOpen(false); beginEditor(); }} onClose={() => { clearPairReturn(); setQuickOpen(false); }} /> - { if (!open) setPairRoute(""); }}> - {t("remote.pair.route")}{t("remote.pair.routeDescription")} - {pairRoute && setPairRoute("")} />} + + {t("remote.pair.route")}{t("remote.pair.routeHint")} + {pairRoute && setRouteOpen(false)} />} { if (!open) closeEditor(); }}> - { + { if (!fingerprint) { event.preventDefault(); hostInput.current?.focus(); } }} onCloseAutoFocus={(event) => { event.preventDefault(); @@ -423,15 +442,15 @@ export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChro {fingerprint.fingerprint}

{t("remote.verifyHint")}

- {error &&

} -
- {editorOpen && } + {error &&

} +
+ {editorOpen && }
:
{ event.preventDefault(); if (!busy && form.host.trim() && (!locationStep || form.config_path.trim())) void save(); }} className="flex min-h-0 flex-col gap-4">
- {!editing &&
    + {!editing &&
    1. {locationStep ? : 1}{t("remote.setup.server")}
: <>
{error &&
-

+

{!sshOptions && /^(ssh_|local_file_not_found)/.test(errorCode) && }
} {busy.startsWith("pick-") &&

{t("remote.setup.pickingFile")}

} -
+
@@ -504,17 +523,17 @@ export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChro { if (!value && !busy) setDisconnecting(null); }}> - {t("remote.disconnectTitle", { name: disconnectProfile?.name })}{t("remote.disconnectDescription")} - {error &&

} -
+ {t("remote.disconnectTitle", { name: disconnectProfile?.name })}{t("remote.disconnectDescription")} + {error &&

} +
{ if (!value && !busy) setRemoving(null); }}> - {t(removalIsShared ? "remote.sameInstance.forgetTitle" : "remote.forgetTitle", { name: removalProfile?.name })}{t(removalIsShared ? "remote.sameInstance.forgetHint" : "remote.forgetDescription")} + {t(removalIsShared ? "remote.sameInstance.forgetTitle" : "remote.forgetTitle", { name: removalProfile?.name })}{t(removalIsShared ? "remote.sameInstance.forgetHint" : "remote.forgetDescription")} {removalProfile && (removalProfile.connected || connections.openHostIds.includes(removalProfile.id)) &&

{t("remote.activeForgetWarning")}

} - {removalProfile?.paired &&

{t("remote.pair.forgetHint")}

{removalProfile.revoke_command && }
} - {error &&

} -
+ {removalProfile?.paired &&

{t("remote.pair.forgetHint")}

{removalProfile.revoke_command && }
} + {error &&

} +
; diff --git a/webui/src/components/remote/RemoteInstances.tsx b/webui/src/components/remote/RemoteInstances.tsx index a161073ae..4e4525b90 100644 --- a/webui/src/components/remote/RemoteInstances.tsx +++ b/webui/src/components/remote/RemoteInstances.tsx @@ -2,7 +2,11 @@ import { createContext, useContext, useEffect, useLayoutEffect, useRef, useState import { Loader2, PlugZap } from "lucide-react"; import { useTranslation } from "react-i18next"; import { Button } from "@/components/ui/button"; -import { groupRemoteProfiles, needsRemoteSetup, type RemoteDirectory } from "@/lib/remote-instances"; +import { groupRemoteProfiles, isCompatibilityError, needsRemoteSetup, type RemoteDirectory } from "@/lib/remote-instances"; +import { HostCompatibilityDialog } from "./HostCompatibilityDialog"; +import { RemoteConnectionsPage } from "./RemoteConnectionsPage"; +import type { HostAnchor } from "./host-bridge"; +import { ThemeProvider } from "@/hooks/useTheme"; import { useHostSessions } from "./useHostSessions"; import { HostNavigationContext, HostSwitcher, RemoteHostMenu, type HostPicker } from "./HostSwitcher"; import { useSidebarHostBridge } from "./useSidebarHostBridge"; @@ -15,6 +19,8 @@ const RemoteContext = createContext<{ activeHostId: string | null; hostStates: Record; managing: boolean; + embeddedManagement?: boolean; + reportManagementSurface?: (rect: HostAnchor, theme: "light" | "dark") => void; closeManagement: () => void; selectLocal: () => void; openHostIds: string[]; @@ -33,6 +39,7 @@ export function RemoteInstances({ children }: { children: ReactNode }) { const { t } = useTranslation(); const hosts = useHostSessions(); const [managing, setManaging] = useState(false); + const [versionOpen, setVersionOpen] = useState(false); const managementOpen = useRef(false); const managementConnect = useRef(false); const legacyFooter = useRef(null); @@ -49,7 +56,16 @@ export function RemoteInstances({ children }: { children: ReactNode }) { if (lastLocalFocus.current?.isConnected) lastLocalFocus.current.focus({ preventScroll: true }); }; const message = error ? t(`remote.errors.${error}`, { defaultValue: t("remote.errors.unknown") }) : ""; - const bridge = useSidebarHostBridge(frames, selected?.id, frameNodes, restoreLocalFocus, { pendingName: pending?.name, error: message }); + const bridge = useSidebarHostBridge(frames, selected?.id, frameNodes, restoreLocalFocus, { pendingName: pending?.name, error: message }, managing, () => changeManagement(false)); + useEffect(() => { + if (!managing || !selected || !bridge.surface?.theme) return; + // Management is drawn by the local shell, beside this host's sidebar. + // Match its appearance temporarily without changing either saved preference. + const root = document.documentElement; + const wasDark = root.classList.contains("dark"); + root.classList.toggle("dark", bridge.surface.theme === "dark"); + return () => { root.classList.toggle("dark", wasDark); }; + }, [managing, selected?.id, bridge.surface?.theme]); useEffect(() => { // A verified remote app can be interactive before optional images/fonts // finish loading. Older bundles still use the iframe load fallback. @@ -68,6 +84,10 @@ export function RemoteInstances({ children }: { children: ReactNode }) { const activeFrame = frames.find((frame) => frame.connection.id === selected?.id); const offline = !!selected && (activeFrame?.offline || (!activeFrame && pending?.id !== selected.id)); const recoveryCode = (hosts.errorId === selected?.id ? error : "") || activeFrame?.error || ""; + const compatibilityFailure = isCompatibilityError(recoveryCode); + const recoveryTitle = compatibilityFailure + ? `remote.compatibility.${recoveryCode === "host_update_required" ? "update_host" : recoveryCode === "client_update_required" ? "update_client" : "unknown"}` + : "remote.offline"; const recoveryMessage = recoveryCode ? t(`remote.errors.${recoveryCode}`, { defaultValue: t("remote.errors.unknown") }) : t("remote.noFallback"); const changeManagement = (open: boolean) => { managementOpen.current = open; @@ -104,7 +124,7 @@ export function RemoteInstances({ children }: { children: ReactNode }) { localName: directory?.machine_name || "nanobot", currentId: selected?.id || null, recentIds: hosts.recentIds, profiles: groupRemoteProfiles(directory?.profiles || [], selected?.id || null) .map(({ profile: { id, name, host } }) => ({ id, name, host, state: hostStates[id] })), - pending, error: message, offline: !!offline, + pending, error: message, offline: !!offline, offlineLabel: compatibilityFailure ? t(recoveryTitle) : undefined, select: (id) => { if (!id) selectLocal(); else if (managing) void connect(id).catch(() => {}); @@ -137,19 +157,21 @@ export function RemoteInstances({ children }: { children: ReactNode }) { }, [selected]); return changeManagement(false), selectLocal, + activeHostId: selected?.id || null, hostStates, managing: bridge.embedded ? bridge.hostedManagement : managing, + embeddedManagement: !!bridge.embedded, reportManagementSurface: bridge.embedded ? bridge.reportSurface : undefined, + closeManagement: bridge.embedded ? bridge.leaveManagement : () => changeManagement(false), selectLocal, openHostIds: frames.map((frame) => frame.connection.id), directoryError: hosts.directoryError, refresh: hosts.refresh, rename: hosts.rename, connect, disconnect: hosts.disconnect, cancel: hosts.cancel }}>
-
+
{children}
{frames.map((frame) => { - const active = !managing && selected?.id === frame.connection.id; + const active = (!managing || !!bridge.surface) && selected?.id === frame.connection.id; return
@@ -160,18 +182,26 @@ export function RemoteInstances({ children }: { children: ReactNode }) { onLoad={() => { bridge.initialize(frame.connection.id); hosts.loaded(frame.connection.id); }} />
; })} - {!managing && selected && (offline || !activeFrame?.loaded) &&
+ {managing && selected &&
+ + changeManagement(false)} mainNavigationExpanded={!!bridge.surface?.left} /> + +
} + {!managing && selected && (offline || !activeFrame?.loaded) &&
{offline ? : } -

{selected.name} · {selected.hostname}

-

{t(offline ? "remote.offline" : "remote.opening")}

-

{recoveryMessage}

-
- {offline && (needsRemoteSetup(recoveryCode) ? : } + {offline && (needsRemoteSetup(recoveryCode) && !compatibilityFailure ? : )}
-
} +
}
{/* Older remote bundles cannot host the control. Keep an explicit exit in a compact bottom strip, never cover their sidebar controls. */} @@ -179,6 +209,8 @@ export function RemoteInstances({ children }: { children: ReactNode }) {
} + profile.id === selected?.id) : undefined} + clientVersion={directory?.client_version} onClose={() => setVersionOpen(false)} />
; diff --git a/webui/src/components/remote/SSHHostPicker.tsx b/webui/src/components/remote/SSHHostPicker.tsx index 58e55fcac..02f0050c5 100644 --- a/webui/src/components/remote/SSHHostPicker.tsx +++ b/webui/src/components/remote/SSHHostPicker.tsx @@ -82,9 +82,9 @@ export function SSHHostPicker({ disabled, value, configFile, imported, suggestio }} />

{t(imported ? "remote.commandImported" : suggestions ? "remote.commandHint" : "remote.addressHint")}

{suggestions && (!!hosts.length || !!error) &&
-
+
{t("remote.sshHosts")} - @@ -102,8 +102,8 @@ export function SSHHostPicker({ disabled, value, configFile, imported, suggestio } }} onClick={() => { onChange(host.host); inputRef.current?.focus(); }}> - {host.host} - {value === host.host && } + {host.host} + {value === host.host && } )}
{error &&

{error}

} diff --git a/webui/src/components/remote/remote-layout.css b/webui/src/components/remote/remote-layout.css new file mode 100644 index 000000000..c4d038503 --- /dev/null +++ b/webui/src/components/remote/remote-layout.css @@ -0,0 +1,70 @@ +/* Remote dialogs share typography and action sizing without changing app-wide controls. */ +.remote-dialog { + min-inline-size: 0; + max-block-size: min(85dvh, calc(100dvh - 2rem)); + overscroll-behavior: contain; + overflow-wrap: anywhere; + outline: none; +} + +.remote-dialog h2 { + line-height: 1.35; + text-wrap: balance; +} + +.remote-dialog :is(p, label, summary) { + text-wrap: pretty; +} + +.remote-action:is(button, a), +.remote-dialog-actions > :is(button, a) { + min-inline-size: 0; + max-inline-size: 100%; + block-size: auto; + min-block-size: 2.5rem; + padding-block: 0.5rem; + white-space: normal; + overflow-wrap: anywhere; + text-wrap: pretty; + line-height: 1.4; +} + +.remote-action svg, +.remote-dialog-actions > :is(button, a) svg { + flex-shrink: 0; +} + +.remote-dialog-actions { + display: grid; + grid-template-columns: repeat(2, minmax(0, 1fr)); + align-items: stretch; + gap: 0.5rem; +} + +.remote-alert { + display: grid; + grid-template-columns: auto minmax(0, 1fr); +} + +/* Keep secondary actions readable when translations need a second line. */ +.remote-pair-alternatives { + display: grid; + grid-template-columns: repeat(2, minmax(0, 1fr)); + align-items: stretch; +} + +@media (max-width: 380px) { + .remote-dialog-actions > :is(button, a) { + padding-inline: 0.75rem; + } +} + +@media (max-height: 540px) { + .remote-dialog[role="dialog"] { + overflow-y: auto; + } + .remote-dialog form, + .remote-dialog .remote-pair { + flex-shrink: 0; + } +} diff --git a/webui/src/components/remote/useSidebarHostBridge.ts b/webui/src/components/remote/useSidebarHostBridge.ts index 3c1fe44ac..7cd682d32 100644 --- a/webui/src/components/remote/useSidebarHostBridge.ts +++ b/webui/src/components/remote/useSidebarHostBridge.ts @@ -5,14 +5,16 @@ import type { HostFrame } from "./useHostSessions"; interface Peer { source: Window; origin: string; nonce: string } export function useSidebarHostBridge(frames: HostFrame[], selectedId: string | undefined, nodes: RefObject>, restoreLocalFocus: () => void, - activity: { pendingName?: string; error?: string }) { + activity: { pendingName?: string; error?: string }, managing = false, onLeaveManagement?: () => void) { const [embedded, setEmbedded] = useState(null); const [readyIds, setReadyIds] = useState([]); const [anchor, setAnchor] = useState(null); + const [surfaces, setSurfaces] = useState>({}); + const [hostedManagement, setHostedManagement] = useState(false); const parent = useRef(null); const peers = useRef(new Map()); - const latest = useRef({ frames, selectedId, restoreLocalFocus, activity }); - latest.current = { frames, selectedId, restoreLocalFocus, activity }; + const latest = useRef({ frames, selectedId, restoreLocalFocus, activity, managing, onLeaveManagement }); + latest.current = { frames, selectedId, restoreLocalFocus, activity, managing, onLeaveManagement }; const initialize = useCallback((id: string) => { const frame = latest.current.frames.find((item) => item.connection.id === id); const source = nodes.current?.get(id)?.contentWindow; @@ -27,6 +29,7 @@ export function useSidebarHostBridge(frames: HostFrame[], selectedId: string | u // Deliberately only public display identity, never SSH metadata or secrets. source.postMessage({ channel: HOST_BRIDGE, type: "init", nonce: peer.nonce, name: frame.connection.name, hostname: frame.connection.hostname, + managing: latest.current.selectedId === id && latest.current.managing, ...(latest.current.selectedId === id ? latest.current.activity : {}) }, origin); }, [nodes]); useEffect(() => { @@ -42,6 +45,7 @@ export function useSidebarHostBridge(frames: HostFrame[], selectedId: string | u if (!host || typeof message.nonce !== "string" || !/^[a-f0-9-]{36}$/.test(message.nonce)) return; parent.current = { source: window.parent, origin: event.origin, nonce: message.nonce }; setEmbedded(host); + setHostedManagement(message.managing === true); window.parent.postMessage({ channel: HOST_BRIDGE, type: "ready", nonce: message.nonce }, event.origin); } else if (message.type === "focus" && current) latest.current.restoreLocalFocus(); return; @@ -60,6 +64,12 @@ export function useSidebarHostBridge(frames: HostFrame[], selectedId: string | u const rect = readHostAnchor(message.anchor); const outer = nodes.current?.get(id)?.getBoundingClientRect(); if (rect && outer) setAnchor({ ...rect, left: outer.left + rect.left, top: outer.top + rect.top }); + } else if (message.type === "surface" && !frame.offline) { + const rect = readHostAnchor(message.rect); + const theme = message.theme === "light" || message.theme === "dark" ? message.theme : undefined; + if (rect && rect.left >= 0 && rect.top >= 0) setSurfaces((previous) => ({ ...previous, [id]: { ...rect, theme } })); + } else if (message.type === "leave-management" && latest.current.selectedId === id) { + latest.current.onLeaveManagement?.(); } // No select/connect/disconnect action is accepted from an embedded page. }; @@ -72,16 +82,29 @@ export function useSidebarHostBridge(frames: HostFrame[], selectedId: string | u const selectedName = frames.find((frame) => frame.connection.id === selectedId)?.connection.name; useEffect(() => { if (selectedId && peers.current.has(selectedId)) initialize(selectedId); - }, [initialize, selectedId, selectedName, activity.pendingName, activity.error]); + }, [initialize, selectedId, selectedName, activity.pendingName, activity.error, managing]); useEffect(() => { for (const id of peers.current.keys()) if (!frames.some((frame) => frame.connection.id === id)) peers.current.delete(id); + setSurfaces((previous) => { + const entries = Object.entries(previous).filter(([id]) => frames.some((frame) => frame.connection.id === id)); + return entries.length === Object.keys(previous).length ? previous : Object.fromEntries(entries); + }); }, [frames]); const focus = (id: string) => { const peer = peers.current.get(id); if (peer && readyIds.includes(id)) peer.source.postMessage({ channel: HOST_BRIDGE, type: "focus", nonce: peer.nonce }, peer.origin); else nodes.current?.get(id)?.focus({ preventScroll: true }); }; - return { anchor, close: () => setAnchor(null), readyIds, initialize, focus, + const reportSurface = useCallback((rect: HostAnchor, theme: "light" | "dark") => { + const peer = parent.current; + peer?.source.postMessage({ channel: HOST_BRIDGE, type: "surface", nonce: peer.nonce, rect, theme }, peer.origin); + }, []); + const leaveManagement = () => { + const peer = parent.current; + peer?.source.postMessage({ channel: HOST_BRIDGE, type: "leave-management", nonce: peer.nonce }, peer.origin); + }; + return { anchor, close: () => setAnchor(null), readyIds, initialize, focus, hostedManagement, reportSurface, leaveManagement, + surface: selectedId ? surfaces[selectedId] || null : null, embedded: embedded ? { ...embedded, kind: "embedded" as const, open: (position: HostAnchor) => { const peer = parent.current; peer?.source.postMessage({ channel: HOST_BRIDGE, type: "open", nonce: peer.nonce, anchor: position }, peer.origin); diff --git a/webui/src/components/settings/shared/SettingsTextEditor.tsx b/webui/src/components/settings/shared/SettingsTextEditor.tsx index d5598f7e4..b0ee1c6ae 100644 --- a/webui/src/components/settings/shared/SettingsTextEditor.tsx +++ b/webui/src/components/settings/shared/SettingsTextEditor.tsx @@ -21,6 +21,8 @@ export function SettingsTextEditor({ id, title, description, value, placeholder, const [saving, setSaving] = useState(false); const [error, setError] = useState(""); const editor = useRef(null); + const help = description?.trim(); + const hasDescription = !!help && help !== title.trim(); const save = async () => { setSaving(true); setError(""); @@ -49,12 +51,13 @@ export function SettingsTextEditor({ id, title, description, value, placeholder, {t("settings.actions.edit")} { event.preventDefault(); editor.current?.focus(); }} onEscapeKeyDown={(event) => { if (saving) event.preventDefault(); }} onPointerDownOutside={(event) => { if (saving) event.preventDefault(); }}> {title} - {description || title} + {hasDescription && {help}}