fix(webui): polish remote setup and simplify connection dialogs
This commit is contained in:
1 parent
5aa91b66cc
commit
0ffdf86619
28 files changed
+972
-149
No files matched your search
@@ -0,0 +1,60 @@
|
||||
import { useEffect, useRef } from "react";
|
||||
import { Check, CircleAlert, ExternalLink } from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
||||
import { SettingsGroup } from "@/components/settings/shared/SettingsControls";
|
||||
import type { RemoteProfile } from "@/lib/remote-instances";
|
||||
import "./remote-layout.css";
|
||||
|
||||
/** Informational only: installing packages and restarting a host need explicit consent. */
|
||||
export function HostCompatibilityDialog({ profile, clientVersion, onClose }: {
|
||||
profile: RemoteProfile | undefined;
|
||||
clientVersion?: string;
|
||||
onClose: () => 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 <Dialog open={!!profile} onOpenChange={(open) => { if (!open) onClose(); }}>
|
||||
<DialogContent className="remote-dialog max-w-md overflow-y-auto outline-none">
|
||||
<DialogHeader className="pr-5 text-left">
|
||||
<DialogTitle className="text-balance leading-snug">{t("remote.compatibility.title")}</DialogTitle>
|
||||
<DialogDescription className="text-pretty [overflow-wrap:anywhere]">{displayedProfile?.name} · {displayedProfile?.host}</DialogDescription>
|
||||
</DialogHeader>
|
||||
<SettingsGroup>
|
||||
<dl className="space-y-3 px-4 py-3 text-[13px] leading-5">
|
||||
{[{ label: t("remote.compatibility.client"), version: report?.client_version || clientVersion },
|
||||
{ label: t("remote.compatibility.host"), version: report?.host_version }].map(({ label, version }) =>
|
||||
<div key={label} className="grid grid-cols-[minmax(0,1fr)_fit-content(45%)] items-baseline gap-x-4">
|
||||
<dt className="min-w-0 text-pretty text-muted-foreground">{label}</dt>
|
||||
<dd className="min-w-0 text-pretty text-right tabular-nums [overflow-wrap:anywhere]">{version || t("remote.compatibility.unreported")}</dd>
|
||||
</div>)}
|
||||
</dl>
|
||||
</SettingsGroup>
|
||||
<div role="status" className="flex items-start gap-2 text-[13px] leading-5">
|
||||
{compatible ? <Check aria-hidden className="mt-0.5 h-4 w-4 shrink-0 text-emerald-600 dark:text-emerald-400" />
|
||||
: <CircleAlert aria-hidden className="mt-0.5 h-4 w-4 shrink-0 text-muted-foreground" />}
|
||||
<div className="min-w-0"><p className="text-pretty font-medium">{t(`remote.compatibility.${status}`)}</p>
|
||||
<p className="mt-1 text-pretty text-muted-foreground">{t(`remote.compatibility.${status}Hint`)}</p></div>
|
||||
</div>
|
||||
{report && !compatible && <details className="text-xs leading-5 text-muted-foreground">
|
||||
<summary className="cursor-pointer py-1">{t("remote.compatibility.preparation")}</summary>
|
||||
<p className="mt-2 text-pretty">{t(status === "update_client" ? "remote.compatibility.localUpdateHint" : "remote.compatibility.serverUpdateHint")}</p>
|
||||
</details>}
|
||||
<div className={report && !compatible ? "remote-dialog-actions" : "flex justify-end"}>
|
||||
<Button className="remote-action" variant="ghost" onClick={onClose}>{t("common.close")}</Button>
|
||||
{report && !compatible && <Button asChild className="remote-action gap-2">
|
||||
<a href="https://github.com/HKUDS/nanobot/blob/main/docs/quick-start.md#updating" target="_blank" rel="noopener noreferrer">
|
||||
{t("remote.compatibility.guide")}<ExternalLink aria-hidden className="h-3.5 w-3.5" />
|
||||
</a>
|
||||
</Button>}
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>;
|
||||
}
|
||||
@@ -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 = <Button ref={buttonRef} variant="ghost" size="sm" aria-label={t("remote.switchHost")} title={title}
|
||||
@@ -152,7 +158,7 @@ export function HostSwitcher({ collapsed = false, portalContainer }: { collapsed
|
||||
<span className="relative flex shrink-0 items-center justify-center">
|
||||
{waiting ? <Loader2 className="h-4 w-4 animate-spin motion-reduce:animate-none" /> : failed ? <CircleAlert className="h-4 w-4" />
|
||||
: remote ? <Server className="h-4 w-4" /> : <Laptop className="h-4 w-4" />}
|
||||
{!waiting && !failed && <span aria-hidden className={cn("absolute -bottom-0.5 -right-0.5 h-1.5 w-1.5 rounded-full ring-2 ring-sidebar", status === "open" ? "bg-emerald-500" : "bg-muted-foreground")} />}
|
||||
{!waiting && !failed && <span aria-hidden className={cn("absolute -bottom-0.5 -right-0.5 h-1.5 w-1.5 rounded-full ring-2 ring-sidebar", currentStatus === "open" ? "bg-emerald-500" : "bg-muted-foreground")} />}
|
||||
</span>
|
||||
{!collapsed && <><span className="truncate">{label}</span><ChevronUp className="ml-auto h-3 w-3 shrink-0 opacity-60" /></>}
|
||||
<span className="sr-only" role="status">{detail}</span>
|
||||
|
||||
@@ -8,7 +8,7 @@ import { remoteAction } from "@/lib/remote-instances";
|
||||
import { useRemoteConnections } from "./RemoteInstances";
|
||||
|
||||
/** An explicit escape hatch for a VPN/bound-interface route, not a new SSH form. */
|
||||
export function PairRouteSettings({ id, onSaved }: { id: string; onSaved?: () => void }) {
|
||||
export function PairRouteSettings({ id, onSaved, showHint = true }: { id: string; onSaved?: () => void; showHint?: boolean }) {
|
||||
const { t } = useTranslation();
|
||||
const { client } = useClient();
|
||||
const connections = useRemoteConnections();
|
||||
@@ -39,18 +39,18 @@ export function PairRouteSettings({ id, onSaved }: { id: string; onSaved?: () =>
|
||||
} finally { if (alive.current) setBusy(false); }
|
||||
};
|
||||
return <div className="space-y-3">
|
||||
<p className="text-xs leading-5 text-muted-foreground">{t("remote.pair.routeHint")}</p>
|
||||
<Select value={route} onValueChange={(value) => { setRoute(value); setError(""); setSaved(false); }} disabled={busy}><SelectTrigger aria-label={t("remote.pair.route")}><SelectValue /></SelectTrigger>
|
||||
{showHint && <p className="text-xs leading-5 text-muted-foreground">{t("remote.pair.routeHint")}</p>}
|
||||
<Select value={route} onValueChange={(value) => { setRoute(value); setError(""); setSaved(false); }} disabled={busy}><SelectTrigger className="w-full min-w-0" aria-label={t("remote.pair.route")}><SelectValue /></SelectTrigger>
|
||||
<SelectContent>
|
||||
{hasSavedRoute && <SelectItem value="saved">{t("remote.pair.savedRoute")}</SelectItem>}
|
||||
<SelectItem value="direct">{t("remote.pair.direct")}</SelectItem>
|
||||
{connections?.directory?.profiles.filter((profile) => !profile.paired).map((profile) => <SelectItem key={profile.id} value={profile.id}>{profile.name}</SelectItem>)}
|
||||
{connections?.directory?.profiles.filter((profile) => !profile.paired).map((profile) => <SelectItem key={profile.id} value={profile.id} className="h-auto min-h-9 max-w-[calc(100vw-3rem)] py-2 [overflow-wrap:anywhere]">{profile.name}</SelectItem>)}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
{error && <p role="alert" className="flex items-start gap-2 text-[13px] leading-5 text-foreground"><AlertCircle aria-hidden="true" className="mt-0.5 h-4 w-4 shrink-0 text-muted-foreground" />{error}</p>}
|
||||
<div className="flex items-center justify-end gap-3">
|
||||
{error && <p role="alert" className="remote-alert items-start gap-2 text-[13px] leading-5 text-foreground"><AlertCircle aria-hidden="true" className="mt-0.5 h-4 w-4 shrink-0 text-muted-foreground" /><span>{error}</span></p>}
|
||||
<div className="flex flex-wrap items-center justify-end gap-3">
|
||||
{saved && <p role="status" className="mr-auto flex items-center gap-1.5 text-xs text-muted-foreground"><Check aria-hidden className="h-3.5 w-3.5" />{t("remote.saved")}</p>}
|
||||
<Button size="sm" disabled={busy || route === original || route === "saved"} aria-busy={busy} onClick={() => { void save(); }}>
|
||||
<Button className="remote-action" size="sm" disabled={busy || route === original || route === "saved"} aria-busy={busy} onClick={() => { void save(); }}>
|
||||
{busy && <Loader2 aria-hidden className="mr-2 h-4 w-4 animate-spin motion-reduce:animate-none" />}{t(busy ? "remote.saving" : "remote.save")}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@@ -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 <div className="flex min-h-0 flex-col">
|
||||
return <div className="remote-pair flex min-h-0 flex-col">
|
||||
<div className="-mx-1 min-h-0 overflow-y-auto overscroll-contain px-1">
|
||||
<DialogHeader className={showIllustration ? "space-y-0 text-center sm:text-center" : "pr-5 text-left"}>
|
||||
{showIllustration && <RemoteConnectionIllustration />}
|
||||
<div aria-live="polite" aria-atomic="true" className="space-y-1.5">
|
||||
<DialogTitle className={showIllustration ? "flex min-h-5 items-center justify-center gap-2 text-xl leading-snug tracking-normal" : "flex min-h-5 items-center gap-2"}>
|
||||
{showCopied && <Check aria-hidden="true" className="h-5 w-5 shrink-0 motion-safe:animate-in motion-safe:fade-in duration-150" />}
|
||||
{t(title)}
|
||||
<span className="min-w-0 [overflow-wrap:anywhere]">{t(title)}</span>
|
||||
</DialogTitle>
|
||||
<DialogDescription>{t(description)}</DialogDescription>
|
||||
</div>
|
||||
</DialogHeader>
|
||||
{preview ? <div className="space-y-4 pt-4">
|
||||
{visiblePreview ? <div className="space-y-4 pt-4">
|
||||
<div className="rounded-2xl bg-muted/50 p-4">
|
||||
<p className="font-medium">{preview.existing_connection?.name || preview.hostname}</p>
|
||||
<p className="mt-1 break-all text-xs text-muted-foreground">{preview.host}</p>
|
||||
<p className="font-medium [overflow-wrap:anywhere]">{visiblePreview.existing_connection?.name || visiblePreview.hostname}</p>
|
||||
<p className="mt-1 break-all text-xs text-muted-foreground">{visiblePreview.host}</p>
|
||||
</div>
|
||||
{preview.existing_connection && <p role="status" className="text-xs leading-5 text-muted-foreground">{t("remote.sameInstance.pairHint")}</p>}
|
||||
{visiblePreview.existing_connection && <p role="status" className="text-xs leading-5 text-muted-foreground">{t("remote.sameInstance.pairHint")}</p>}
|
||||
<p className="text-[13px] leading-5">{t("remote.pair.access")}</p>
|
||||
<p className="text-xs leading-5 text-muted-foreground">{t("remote.pair.expiry", { date: new Date(preview.authorized_until * 1000).toLocaleDateString() })}</p>
|
||||
<p className="text-xs leading-5 text-muted-foreground">{t("remote.pair.expiry", { date: new Date(visiblePreview.authorized_until * 1000).toLocaleDateString() })}</p>
|
||||
<Disclosure className="text-xs text-muted-foreground" summaryClassName="flex min-h-9 items-center gap-2 rounded-xl focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
summary={<><ChevronDown aria-hidden className="h-3.5 w-3.5 shrink-0 transition-transform group-data-[state=open]/disclosure:rotate-180 motion-reduce:transition-none" />{t("remote.pair.security")}</>}>
|
||||
<p className="my-2 leading-5">{t("remote.pair.fingerprint")}</p><code className="block break-all">{preview.fingerprint}</code>
|
||||
<p className="mb-2 mt-4 leading-5">{t("remote.pair.revoke")}</p><CodeBlock language="bash" code={preview.revoke_command} highlight={false} className="min-w-0 [&_pre]:[overflow-wrap:anywhere]" />
|
||||
<p className="my-2 leading-5">{t("remote.pair.fingerprint")}</p><code className="block break-all">{visiblePreview.fingerprint}</code>
|
||||
<p className="mb-2 mt-4 leading-5">{t("remote.pair.revoke")}</p><CodeBlock language="bash" code={visiblePreview.revoke_command} highlight={false} className="min-w-0 [&_pre]:[overflow-wrap:anywhere]" />
|
||||
</Disclosure>
|
||||
{saved && error && <div className="space-y-2"><p className="text-xs leading-5 text-muted-foreground">{t("remote.pair.retryHint")}</p>
|
||||
<Disclosure summaryClassName="flex min-h-9 items-center gap-2 rounded-xl text-xs text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring" contentClassName="pt-2"
|
||||
@@ -178,7 +184,7 @@ export function QuickPairSetup({ returned, onSSH, onClose }: { returned?: PairRe
|
||||
<div>
|
||||
<DisclosureContent id={panelId} open={panel === "command" && !!request?.command} className="pt-4">
|
||||
<div className="rounded-2xl bg-muted/50 p-3">
|
||||
<code className="block max-h-32 select-text overflow-y-auto break-all text-[11px] leading-5" aria-label={t("remote.pair.command")}>{request?.command}</code>
|
||||
<code className="block max-h-32 select-text overflow-y-auto text-[11px] leading-5 [overflow-wrap:anywhere]" aria-label={t("remote.pair.command")}>{request?.command}</code>
|
||||
</div>
|
||||
</DisclosureContent>
|
||||
<DisclosureContent open={panel === "help"} className="pt-4">
|
||||
@@ -192,21 +198,21 @@ export function QuickPairSetup({ returned, onSSH, onClose }: { returned?: PairRe
|
||||
</div>
|
||||
</>}
|
||||
{expired && !saved && <p role="status" className="mt-4 text-xs leading-5 text-muted-foreground">{t("remote.pair.expired")}</p>}
|
||||
{error && <p role="alert" className="mt-4 flex items-start gap-2 text-[13px] leading-5 text-foreground"><AlertCircle aria-hidden="true" className="mt-0.5 h-4 w-4 shrink-0 text-muted-foreground" />{t(error, { defaultValue: t("remote.errors.unknown") })}</p>}
|
||||
{error && <p role="alert" className="remote-alert mt-4 items-start gap-2 text-[13px] leading-5 text-foreground"><AlertCircle aria-hidden="true" className="mt-0.5 h-4 w-4 shrink-0 text-muted-foreground" /><span>{t(error, { defaultValue: t("remote.errors.unknown") })}</span></p>}
|
||||
</div>
|
||||
<div className={preview ? "flex shrink-0 flex-col-reverse gap-2 pt-5 sm:flex-row sm:items-center sm:justify-between" : "flex shrink-0 flex-col gap-2 pt-5"}>
|
||||
{preview && (!saved ? <Button variant="ghost" disabled={busy} onClick={() => { setPreview(null); setError(""); if (!request?.command) setManual(true); }}><ArrowLeft className="mr-1 h-4 w-4" />{t("remote.back")}</Button>
|
||||
: <Button variant="ghost" onClick={() => { connections?.cancel(); onClose(); }}>{t("common.cancel")}</Button>
|
||||
<div className={visiblePreview ? "remote-dialog-actions shrink-0 pt-5" : "flex shrink-0 flex-col gap-2 pt-5"}>
|
||||
{visiblePreview && (!saved ? <Button className="remote-action" variant="ghost" disabled={busy} onClick={() => { setPreview(null); setError(""); if (!request?.command) setManual(true); }}><ArrowLeft className="mr-1 h-4 w-4" />{t("remote.back")}</Button>
|
||||
: <Button className="remote-action" variant="ghost" onClick={() => { connections?.cancel(); onClose(); }}>{t("common.cancel")}</Button>
|
||||
)}
|
||||
<Button variant={showCopied ? "outline" : "default"} className={showCopied ? "bg-transparent" : undefined} aria-label={t(showBusy ? busyLabel : actionLabel)} aria-busy={pending} disabled={busy || waitingForLocal || (!restartAvailable && (!request || (!preview && (manual || reviewingReturn ? !code.trim() : !request.command))))} onClick={() => { if (restartAvailable) void start(); else if (preview) void connect(); else if (manual || reviewingReturn) void review(); else copyCommand(); }}>
|
||||
{showBusy ? <Loader2 aria-hidden="true" className="mr-2 h-4 w-4 shrink-0 animate-spin motion-reduce:animate-none" /> : !restartAvailable && !preview && !manual && !reviewingReturn ? <Copy aria-hidden="true" className="mr-2 h-4 w-4 shrink-0" /> : null}
|
||||
<span role="status" className="min-w-0 truncate">{t(showBusy ? busyLabel : actionLabel)}</span>
|
||||
<Button variant={showCopied ? "outline" : "default"} className={showCopied ? "remote-action bg-transparent" : "remote-action"} aria-label={t(showBusy ? busyLabel : actionLabel)} aria-busy={pending} disabled={busy || waitingForLocal || (!restartAvailable && (!request || (!visiblePreview && (manual || reviewingReturn ? !code.trim() : !request.command))))} onClick={() => { if (restartAvailable) void start(); else if (visiblePreview) void connect(); else if (manual || reviewingReturn) void review(); else copyCommand(); }}>
|
||||
{showBusy ? <Loader2 aria-hidden="true" className="mr-2 h-4 w-4 shrink-0 animate-spin motion-reduce:animate-none" /> : !restartAvailable && !visiblePreview && !manual && !reviewingReturn ? <Copy aria-hidden="true" className="mr-2 h-4 w-4 shrink-0" /> : null}
|
||||
<span role="status" className="min-w-0">{t(showBusy ? busyLabel : actionLabel)}</span>
|
||||
</Button>
|
||||
{!preview && <div className="-mx-3 flex items-center justify-between gap-1">
|
||||
{request?.command ? manual ? <Button variant="ghost" size="sm" disabled={busy} onClick={() => { setManual(false); setPanel(null); setError(""); }}>{t("remote.back")}</Button>
|
||||
: <Button variant="ghost" size="sm" className="text-xs text-muted-foreground" disabled={expired} aria-expanded={panel === "command"} aria-controls={panelId} onClick={() => setPanel(panel === "command" ? null : "command")}>{t("remote.pair.showCommand")}</Button> : <span />}
|
||||
{!visiblePreview && <div className="remote-pair-alternatives -mx-3 gap-1">
|
||||
{!restartAvailable && request?.command ? manual ? <Button className="remote-action" variant="ghost" size="sm" disabled={busy} onClick={() => { setManual(false); setPanel(null); setError(""); }}>{t("remote.back")}</Button>
|
||||
: <Button variant="ghost" size="sm" className="remote-action justify-start text-left text-xs text-muted-foreground" disabled={expired} aria-expanded={panel === "command"} aria-controls={panelId} onClick={() => setPanel(panel === "command" ? null : "command")}>{t("remote.pair.showCommand")}</Button> : <span />}
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild><Button variant="ghost" size="sm" className="text-xs text-muted-foreground">{t("remote.pair.otherWays")}<ChevronDown aria-hidden="true" className="ml-1 h-3.5 w-3.5" /></Button></DropdownMenuTrigger>
|
||||
<DropdownMenuTrigger asChild><Button variant="ghost" size="sm" className="remote-action justify-end text-right text-xs text-muted-foreground">{t("remote.pair.otherWays")}<ChevronDown aria-hidden="true" className="ml-1 h-3.5 w-3.5 shrink-0" /></Button></DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" onCloseAutoFocus={(event) => {
|
||||
if (focusManual.current) { event.preventDefault(); focusManual.current = false; manualInput.current?.focus(); }
|
||||
}}>
|
||||
|
||||
@@ -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<RemoteProfile, "id" | "connected"> => ({
|
||||
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<RemoteProfile | null>(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 && <DropdownMenuItem disabled={profile.connected || connections.openHostIds.includes(profile.id)} onSelect={() => { setDetails(""); beginEditor(profile); }}>{t("remote.edit")}</DropdownMenuItem>}
|
||||
{profile.paired && <DropdownMenuItem disabled={profile.connected || connections.openHostIds.includes(profile.id)} onSelect={() => { setDetails(""); setPairRoute(profile.id); }}>{t("remote.pair.route")}</DropdownMenuItem>}
|
||||
{(profile.connected || connections.openHostIds.includes(profile.id)) && <DropdownMenuItem onSelect={() => { setDetails(""); setError(""); setDisconnecting(profile); }}>{t("remote.disconnect")}</DropdownMenuItem>}
|
||||
<DropdownMenuItem tone="destructive" onSelect={() => { setDetails(""); setError(""); setRemoving(profile); }}>{t(grouped ? "remote.sameInstance.forgetConnection" : "remote.forget")}</DropdownMenuItem>
|
||||
{!profile.paired && <DropdownMenuItem disabled={profile.connected || connections.openHostIds.includes(profile.id)} onSelect={() => { setDetailsOpen(false); beginEditor(profile); }}>{t("remote.edit")}</DropdownMenuItem>}
|
||||
{profile.paired && <DropdownMenuItem disabled={profile.connected || connections.openHostIds.includes(profile.id)} onSelect={() => { setDetailsOpen(false); setPairRoute(profile.id); setRouteOpen(true); }}>{t("remote.pair.route")}</DropdownMenuItem>}
|
||||
{(profile.connected || connections.openHostIds.includes(profile.id)) && <DropdownMenuItem onSelect={() => { setDetailsOpen(false); setError(""); setDisconnecting(profile); }}>{t("remote.disconnect")}</DropdownMenuItem>}
|
||||
<DropdownMenuItem tone="destructive" onSelect={() => { setDetailsOpen(false); setError(""); setRemoving(profile); }}>{t(grouped ? "remote.sameInstance.forgetConnection" : "remote.forget")}</DropdownMenuItem>
|
||||
</>;
|
||||
|
||||
return <div ref={page} tabIndex={-1} role="region" aria-label={t("remote.title")} className="flex min-h-0 flex-1 flex-col overflow-hidden bg-settings-canvas outline-none">
|
||||
@@ -309,6 +324,9 @@ export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChro
|
||||
<span className="min-w-0 flex-1"><span className="block truncate text-[14px] font-medium">{profile.name}</span><span className="mt-0.5 block truncate text-xs text-muted-foreground">{profile.host}</span>
|
||||
{groups.some((other) => other.id !== groupId && other.profile.name === profile.name && other.profile.host === profile.host) && <span className="mt-0.5 block truncate text-xs text-muted-foreground" title={profile.config_path}>{profile.port ? `:${profile.port} · ` : ""}{profile.config_path}</span>}
|
||||
<span id={`${statusId}-${profile.id}`} className="mt-1 block"><HostConnectionStatus state={connections.hostStates[profile.id] || "closed"} /></span>
|
||||
{profile.compatibility && profile.compatibility.status !== "compatible" && <span className="mt-1 block text-xs text-muted-foreground">
|
||||
{t(`remote.compatibility.${profile.compatibility.status}`)}
|
||||
</span>}
|
||||
{profile.paired && typeof profile.authorized_until === "number" && Number.isFinite(profile.authorized_until)
|
||||
&& profile.authorized_until * 1000 <= Date.now() + 7 * 86_400_000 && <span className="mt-1 block text-xs leading-5 text-muted-foreground">
|
||||
{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 })}><MoreHorizontal className="h-4 w-4" /></Button></DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem onSelect={() => { setRenaming(profile); setName(profile.name); setRenameError(""); }}>{t("remote.rename.action")}</DropdownMenuItem>
|
||||
{entries.length > 1 ? <DropdownMenuItem onSelect={() => setDetails(groupId)}>{t("remote.sameInstance.details")}</DropdownMenuItem> : connectionActions(profile)}
|
||||
<DropdownMenuItem onSelect={() => setVersionId(profile.id)}>{t("remote.compatibility.title")}</DropdownMenuItem>
|
||||
{entries.length > 1 ? <DropdownMenuItem onSelect={() => { setDetails(groupId); setDetailsOpen(true); }}>{t("remote.sameInstance.details")}</DropdownMenuItem> : connectionActions(profile)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>)}
|
||||
@@ -333,14 +352,14 @@ export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChro
|
||||
<p role="status" className="min-w-0 truncate text-xs text-muted-foreground">{t("remote.preparing", { name: openingProfile.name })}</p>
|
||||
<Button variant="ghost" size="sm" className="shrink-0" onClick={closeEditor}>{t("remote.cancelSwitch")}</Button>
|
||||
</div>}
|
||||
<div className="settings-list-inset"><Button variant="ghost" className="gap-2" disabled={!!busy} onClick={(event) => {
|
||||
editorTrigger.current = event.currentTarget; setQuickOpen(true);
|
||||
<div className="settings-list-inset"><Button variant="ghost" className="remote-action gap-2" disabled={!!busy} onClick={(event) => {
|
||||
editorTrigger.current = event.currentTarget; setQuickReturn(null); setQuickOpen(true);
|
||||
}}><Plus className="h-4 w-4" />{t("remote.add")}</Button></div>
|
||||
</>}
|
||||
{!directory && !directoryError && <div role="status" className="settings-list-inset flex items-center gap-2 text-sm text-muted-foreground"><Loader2 className="h-4 w-4 animate-spin" />{t("remote.loading")}</div>}
|
||||
{directory && !directory.available && <p className="settings-list-inset text-sm text-muted-foreground">{t("remote.unavailable")}</p>}
|
||||
{pageError && !editorOpen && !fingerprint && !removing && !disconnecting && <div className="settings-list-inset space-y-2">
|
||||
<p role="alert" className="flex items-start gap-2 text-[13px] leading-5 text-foreground"><AlertCircle aria-hidden="true" className="mt-0.5 h-4 w-4 shrink-0 text-muted-foreground" />{pageError}</p>
|
||||
<p role="alert" className="remote-alert items-start gap-2 text-[13px] leading-5 text-foreground"><AlertCircle aria-hidden="true" className="mt-0.5 h-4 w-4 shrink-0 text-muted-foreground" />{pageError}</p>
|
||||
{directoryError && <Button variant="ghost" size="sm" disabled={!!busy} onClick={() => {
|
||||
setBusy("refresh"); setError(""); void refresh?.().catch((reason: unknown) => { if (mounted.current) showError(reason); }).finally(() => { if (mounted.current) setBusy(""); });
|
||||
}}>{t("remote.retry")}</Button>}
|
||||
@@ -349,8 +368,10 @@ export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChro
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<HostCompatibilityDialog profile={directory?.profiles.find((profile) => profile.id === versionId)}
|
||||
clientVersion={directory?.client_version} onClose={() => setVersionId("")} />
|
||||
<Dialog open={!!renaming} onOpenChange={(open) => { if (!open && !busy) setRenaming(null); }}>
|
||||
<DialogContent className="max-h-[85dvh] max-w-sm overflow-y-auto" onOpenAutoFocus={(event) => {
|
||||
<DialogContent className="remote-dialog max-h-[85dvh] max-w-sm overflow-y-auto" onOpenAutoFocus={(event) => {
|
||||
event.preventDefault(); nameInput.current?.focus(); nameInput.current?.select();
|
||||
}} onCloseAutoFocus={(event) => { event.preventDefault(); editorTrigger.current?.focus({ preventScroll: true }); }}>
|
||||
<DialogHeader className="pr-5 text-left">
|
||||
@@ -358,14 +379,12 @@ export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChro
|
||||
<DialogDescription>{t("remote.rename.hint")}</DialogDescription>
|
||||
</DialogHeader>
|
||||
<form className="space-y-4" onSubmit={(event) => { event.preventDefault(); void rename(); }}>
|
||||
<div className="space-y-2">
|
||||
<label htmlFor={nameId} className="text-[13px] font-medium">{t("remote.rename.name")}</label>
|
||||
<Input ref={nameInput} id={nameId} value={name} maxLength={64} required disabled={!!busy}
|
||||
aria-invalid={!!renameError} aria-describedby={renameError ? `${nameId}-error` : undefined}
|
||||
onChange={(event) => { setName(event.target.value); setRenameError(""); }} />
|
||||
</div>
|
||||
<Input ref={nameInput} id={nameId} value={name} maxLength={64} required disabled={!!busy}
|
||||
aria-label={t("remote.rename.name")}
|
||||
aria-invalid={!!renameError} aria-describedby={renameError ? `${nameId}-error` : undefined}
|
||||
onChange={(event) => { setName(event.target.value); setRenameError(""); }} />
|
||||
{renameError && <p id={`${nameId}-error`} role="alert" className="text-[13px] leading-5 text-foreground">{renameError}</p>}
|
||||
<div className="flex justify-end gap-2">
|
||||
<div className="remote-dialog-actions">
|
||||
<Button type="button" variant="ghost" disabled={!!busy} onClick={() => setRenaming(null)}>{t("common.cancel")}</Button>
|
||||
<Button type="submit" disabled={!!busy || !name.trim() || name.trim() === renaming?.name} aria-busy={!!busy}>
|
||||
{busy && <Loader2 aria-hidden className="mr-2 h-4 w-4 animate-spin motion-reduce:animate-none" />}{t(busy ? "remote.saving" : "remote.save")}
|
||||
@@ -374,14 +393,14 @@ export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChro
|
||||
</form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
<Dialog open={!!detailGroup} onOpenChange={(open) => { if (!open) setDetails(""); }}>
|
||||
<DialogContent className="flex max-h-[85dvh] max-w-md flex-col overflow-hidden">
|
||||
<Dialog open={detailsOpen && !!detailGroup} onOpenChange={(open) => { if (!open) setDetailsOpen(false); }}>
|
||||
<DialogContent className="remote-dialog flex max-h-[85dvh] max-w-md flex-col overflow-hidden">
|
||||
<DialogHeader className="pr-5 text-left"><DialogTitle>{t("remote.sameInstance.details")}</DialogTitle><DialogDescription>{t("remote.sameInstance.detailsHint")}</DialogDescription></DialogHeader>
|
||||
<div className="min-h-0 space-y-2 overflow-y-auto">
|
||||
{detailGroup?.connections.map((profile, index) => <div key={profile.id} className="flex items-center gap-2 rounded-2xl bg-muted/40 p-3">
|
||||
<button type="button" disabled={!!busy || (!!detailConnection && detailConnection.id !== profile.id)} aria-current={connections.activeHostId === profile.id || undefined}
|
||||
className="min-w-0 flex-1 rounded-xl text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
onClick={() => { setDetails(""); void connect(profile.id); }}>
|
||||
onClick={() => { setDetailsOpen(false); void connect(profile.id); }}>
|
||||
<span className="flex items-center gap-2 text-[13px] font-medium">{t("remote.sameInstance.connection", { count: index + 1 })}{connections.activeHostId === profile.id && <Check aria-label={t("remote.current")} className="h-3.5 w-3.5" />}</span>
|
||||
<span className="mt-1 block truncate text-xs text-muted-foreground">{profile.host}</span>
|
||||
<HostConnectionStatus state={connections.hostStates[profile.id] || "closed"} />
|
||||
@@ -397,17 +416,17 @@ export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChro
|
||||
</Dialog>
|
||||
|
||||
<Dialog open={quickOpen} onOpenChange={(open) => { setQuickOpen(open); if (!open) clearPairReturn(); }}>
|
||||
<DialogContent className="flex max-h-[85dvh] max-w-md flex-col overflow-hidden">
|
||||
{quickOpen && <QuickPairSetup key={returnedPair?.code || "new"} returned={returnedPair} onSSH={() => { clearPairReturn(); setQuickOpen(false); beginEditor(); }} onClose={() => { clearPairReturn(); setQuickOpen(false); }} />}
|
||||
<DialogContent className="remote-dialog flex max-h-[85dvh] max-w-md flex-col overflow-hidden">
|
||||
<QuickPairSetup key={quickReturn?.code || "new"} returned={quickReturn} active={quickOpen} onSSH={() => { clearPairReturn(); setQuickOpen(false); beginEditor(); }} onClose={() => { clearPairReturn(); setQuickOpen(false); }} />
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
<Dialog open={!!pairRoute} onOpenChange={(open) => { if (!open) setPairRoute(""); }}>
|
||||
<DialogContent className="max-w-md"><DialogHeader><DialogTitle>{t("remote.pair.route")}</DialogTitle><DialogDescription>{t("remote.pair.routeDescription")}</DialogDescription></DialogHeader>
|
||||
{pairRoute && <PairRouteSettings id={pairRoute} onSaved={() => setPairRoute("")} />}
|
||||
<Dialog open={routeOpen} onOpenChange={setRouteOpen}>
|
||||
<DialogContent className="remote-dialog max-w-md overflow-y-auto"><DialogHeader className="pr-5 text-left"><DialogTitle>{t("remote.pair.route")}</DialogTitle><DialogDescription>{t("remote.pair.routeHint")}</DialogDescription></DialogHeader>
|
||||
{pairRoute && <PairRouteSettings key={pairRoute} id={pairRoute} showHint={false} onSaved={() => setRouteOpen(false)} />}
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
<Dialog open={editorOpen || !!fingerprint} onOpenChange={(open) => { if (!open) closeEditor(); }}>
|
||||
<DialogContent className="flex max-h-[85dvh] max-w-md flex-col overflow-hidden" onOpenAutoFocus={(event) => {
|
||||
<DialogContent className="remote-dialog flex max-h-[85dvh] max-w-md flex-col overflow-hidden" onOpenAutoFocus={(event) => {
|
||||
if (!fingerprint) { event.preventDefault(); hostInput.current?.focus(); }
|
||||
}} onCloseAutoFocus={(event) => {
|
||||
event.preventDefault();
|
||||
@@ -423,15 +442,15 @@ export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChro
|
||||
<code className="block select-text break-all text-xs text-muted-foreground">{fingerprint.fingerprint}</code>
|
||||
</div>
|
||||
<p className="text-xs leading-5 text-muted-foreground">{t("remote.verifyHint")}</p>
|
||||
{error && <p role="alert" className="flex items-start gap-2 text-[13px] leading-5 text-foreground"><AlertCircle aria-hidden="true" className="mt-0.5 h-4 w-4 shrink-0 text-muted-foreground" />{error}</p>}
|
||||
<div className="grid grid-cols-2 gap-2 sm:flex sm:flex-wrap sm:items-center sm:justify-end">
|
||||
{editorOpen && <Button variant="ghost" disabled={!!busy} className="mr-auto gap-1" onClick={() => { setFingerprint(null); setError(""); setErrorCode(""); setInspection(null); setInspectBeforeConnect(true); }}><ChevronLeft className="h-4 w-4" />{t("remote.back")}</Button>}
|
||||
{error && <p role="alert" className="remote-alert items-start gap-2 text-[13px] leading-5 text-foreground"><AlertCircle aria-hidden="true" className="mt-0.5 h-4 w-4 shrink-0 text-muted-foreground" /><span>{error}</span></p>}
|
||||
<div className="remote-dialog-actions">
|
||||
{editorOpen && <Button variant="ghost" disabled={!!busy} className="gap-1" onClick={() => { setFingerprint(null); setError(""); setErrorCode(""); setInspection(null); setInspectBeforeConnect(true); }}><ChevronLeft className="h-4 w-4" />{t("remote.back")}</Button>}
|
||||
<Button variant="ghost" onClick={closeEditor}>{t("common.cancel")}</Button>
|
||||
<Button className="col-span-2 h-auto min-h-10 whitespace-normal" disabled={!!busy} aria-busy={!!busy} onClick={() => { void trustHost(); }}>{busy && <Loader2 aria-hidden className="mr-2 h-4 w-4 shrink-0 animate-spin motion-reduce:animate-none" />}{t("remote.verifyConnect")}</Button>
|
||||
</div>
|
||||
</> : <form onSubmit={(event) => { event.preventDefault(); if (!busy && form.host.trim() && (!locationStep || form.config_path.trim())) void save(); }} className="flex min-h-0 flex-col gap-4">
|
||||
<div className="-mx-1 min-h-0 space-y-4 overflow-y-auto overscroll-contain px-1">
|
||||
{!editing && <ol aria-label={t("remote.setup.progress")} className="flex items-center gap-3 text-xs text-muted-foreground">
|
||||
{!editing && <ol aria-label={t("remote.setup.progress")} className="flex flex-wrap items-center gap-3 text-xs text-muted-foreground">
|
||||
<li aria-current={!locationStep ? "step" : undefined} className={cn("flex items-center gap-1.5", !locationStep && "text-foreground")}>
|
||||
{locationStep ? <Check className="h-3.5 w-3.5" /> : <span>1</span>}{t("remote.setup.server")}</li>
|
||||
<li aria-hidden="true" className="h-px w-5 bg-border" />
|
||||
@@ -440,7 +459,7 @@ export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChro
|
||||
{locationStep && !editing ? <div className="space-y-4">
|
||||
<div className="flex items-center justify-between gap-3 rounded-2xl bg-muted/40 px-3 py-2.5">
|
||||
<span className="min-w-0 text-[13px]"><span className="block font-medium">{t("remote.setup.signedIn")}</span><span className="block truncate text-xs text-muted-foreground">{form.host}</span></span>
|
||||
<Button type="button" size="sm" variant="ghost" disabled={!!busy} onClick={editSSH}>{t("remote.setup.changeServer")}</Button>
|
||||
<Button type="button" size="sm" variant="ghost" className="remote-action" disabled={!!busy} onClick={editSSH}>{t("remote.setup.changeServer")}</Button>
|
||||
</div>
|
||||
{!!inspection?.candidates.length && <fieldset className="space-y-2">
|
||||
<legend className="mb-2 text-[13px] font-medium">{t("remote.setup.chooseNanobot")}</legend>
|
||||
@@ -448,7 +467,7 @@ export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChro
|
||||
<input type="radio" name="nanobot-location" className="mt-1 accent-foreground" disabled={!!busy}
|
||||
checked={!manualLocation && form.config_path === candidate.config_path && form.runtime_user === candidate.runtime_user}
|
||||
onChange={() => { setManualLocation(false); setForm({ ...form, config_path: candidate.config_path, runtime_user: candidate.runtime_user }); setError(""); setErrorCode(""); }} />
|
||||
<span className="min-w-0 text-[13px]"><span className="block font-medium">{candidate.service || t("remote.setup.yourNanobot")}</span>
|
||||
<span className="min-w-0 text-[13px]"><span className="block font-medium [overflow-wrap:anywhere]">{candidate.service || t("remote.setup.yourNanobot")}</span>
|
||||
<span className="block break-all text-xs leading-5 text-muted-foreground">{candidate.config_path}</span>
|
||||
{candidate.runtime_user && <span className="mt-1 block text-xs leading-5 text-muted-foreground">{t("remote.setup.serviceAccount", { user: candidate.runtime_user })}</span>}
|
||||
</span>
|
||||
@@ -459,7 +478,7 @@ export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChro
|
||||
<p className="text-xs leading-5 text-muted-foreground">{t("remote.setup.notFoundHint")}</p>
|
||||
</div>}
|
||||
{inspection?.incomplete && <p className="text-xs leading-5 text-muted-foreground">{t("remote.setup.limitedSearch")}</p>}
|
||||
{!manualLocation && <Button type="button" variant="ghost" size="sm" disabled={!!busy} onClick={() => setManualLocation(true)}>{t("remote.setup.manualLocation")}</Button>}
|
||||
{!manualLocation && <Button type="button" variant="ghost" size="sm" className="remote-action" disabled={!!busy} onClick={() => setManualLocation(true)}>{t("remote.setup.manualLocation")}</Button>}
|
||||
</div> : <>
|
||||
<SSHHostPicker inputRef={hostInput} disabled={!!busy} value={form.host} configFile={form.ssh_config} imported={commandImported}
|
||||
suggestions={!editingProfile || form.host !== editingProfile.host || form.ssh_config !== editingProfile.ssh_config}
|
||||
@@ -488,15 +507,15 @@ export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChro
|
||||
</div>
|
||||
<div className="shrink-0 space-y-3 pt-1">
|
||||
{error && <div className="space-y-1">
|
||||
<p role="alert" className="flex items-start gap-2 text-[13px] leading-5 text-foreground"><AlertCircle aria-hidden="true" className="mt-0.5 h-4 w-4 shrink-0 text-muted-foreground" />{error}</p>
|
||||
<p role="alert" className="remote-alert items-start gap-2 text-[13px] leading-5 text-foreground"><AlertCircle aria-hidden="true" className="mt-0.5 h-4 w-4 shrink-0 text-muted-foreground" /><span>{error}</span></p>
|
||||
{!sshOptions && /^(ssh_|local_file_not_found)/.test(errorCode) && <Button type="button" variant="ghost" size="sm" disabled={!!busy} onClick={editSSH}>{t("remote.setup.sshSettings")}</Button>}
|
||||
</div>}
|
||||
{busy.startsWith("pick-") && <p role="status" className="text-xs text-muted-foreground">{t("remote.setup.pickingFile")}</p>}
|
||||
<div className="grid grid-cols-[auto_minmax(0,1fr)] items-center gap-2">
|
||||
<div className="remote-dialog-actions">
|
||||
<Button type="button" variant="ghost" onClick={closeEditor}>{t("common.cancel")}</Button>
|
||||
<Button type="submit" className="min-w-0" title={t(editorLabel)} aria-label={t(editorLabel)} aria-busy={!!busy} disabled={!!busy || !form.host.trim() || (locationStep && !form.config_path.trim())}>
|
||||
{busy && !busy.startsWith("pick-") && <Loader2 aria-hidden className="mr-2 h-4 w-4 shrink-0 animate-spin motion-reduce:animate-none" />}
|
||||
<span role={busy && !busy.startsWith("pick-") ? "status" : undefined} className="truncate">{t(editorLabel)}</span>
|
||||
<span role={busy && !busy.startsWith("pick-") ? "status" : undefined} className="min-w-0">{t(editorLabel)}</span>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -504,17 +523,17 @@ export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChro
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
<Dialog open={!!disconnecting} onOpenChange={(value) => { if (!value && !busy) setDisconnecting(null); }}>
|
||||
<DialogContent className="max-h-[85dvh] max-w-sm overflow-y-auto"><DialogHeader className="pr-5 text-left"><DialogTitle className="break-words leading-snug">{t("remote.disconnectTitle", { name: disconnectProfile?.name })}</DialogTitle><DialogDescription>{t("remote.disconnectDescription")}</DialogDescription></DialogHeader>
|
||||
{error && <p role="alert" className="flex items-start gap-2 text-[13px] leading-5 text-foreground"><AlertCircle aria-hidden="true" className="mt-0.5 h-4 w-4 shrink-0 text-muted-foreground" />{error}</p>}
|
||||
<div className="grid grid-cols-2 gap-2"><Button variant="ghost" disabled={!!busy} onClick={() => setDisconnecting(null)}>{t("common.cancel")}</Button><Button variant="outline" className="min-w-0" disabled={!!busy} aria-busy={!!busy} onClick={() => { if (disconnecting) void disconnect(disconnecting.id); }}>{busy && <Loader2 aria-hidden className="mr-2 h-4 w-4 shrink-0 animate-spin motion-reduce:animate-none" />}<span className="truncate">{t("remote.disconnect")}</span></Button></div>
|
||||
<DialogContent className="remote-dialog max-h-[85dvh] max-w-sm overflow-y-auto"><DialogHeader className="pr-5 text-left"><DialogTitle className="leading-snug [overflow-wrap:anywhere]">{t("remote.disconnectTitle", { name: disconnectProfile?.name })}</DialogTitle><DialogDescription>{t("remote.disconnectDescription")}</DialogDescription></DialogHeader>
|
||||
{error && <p role="alert" className="remote-alert items-start gap-2 text-[13px] leading-5 text-foreground"><AlertCircle aria-hidden="true" className="mt-0.5 h-4 w-4 shrink-0 text-muted-foreground" /><span>{error}</span></p>}
|
||||
<div className="remote-dialog-actions"><Button variant="ghost" disabled={!!busy} onClick={() => setDisconnecting(null)}>{t("common.cancel")}</Button><Button variant="outline" className="min-w-0" disabled={!!busy} aria-busy={!!busy} onClick={() => { if (disconnecting) void disconnect(disconnecting.id); }}>{busy && <Loader2 aria-hidden className="mr-2 h-4 w-4 shrink-0 animate-spin motion-reduce:animate-none" />}<span>{t("remote.disconnect")}</span></Button></div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
<Dialog open={!!removing} onOpenChange={(value) => { if (!value && !busy) setRemoving(null); }}>
|
||||
<DialogContent className="max-h-[85dvh] max-w-sm overflow-y-auto"><DialogHeader className="pr-5 text-left"><DialogTitle className="break-words leading-snug">{t(removalIsShared ? "remote.sameInstance.forgetTitle" : "remote.forgetTitle", { name: removalProfile?.name })}</DialogTitle><DialogDescription>{t(removalIsShared ? "remote.sameInstance.forgetHint" : "remote.forgetDescription")}</DialogDescription></DialogHeader>
|
||||
<DialogContent className="remote-dialog max-h-[85dvh] max-w-sm overflow-y-auto"><DialogHeader className="pr-5 text-left"><DialogTitle className="leading-snug [overflow-wrap:anywhere]">{t(removalIsShared ? "remote.sameInstance.forgetTitle" : "remote.forgetTitle", { name: removalProfile?.name })}</DialogTitle><DialogDescription>{t(removalIsShared ? "remote.sameInstance.forgetHint" : "remote.forgetDescription")}</DialogDescription></DialogHeader>
|
||||
{removalProfile && (removalProfile.connected || connections.openHostIds.includes(removalProfile.id)) && <p role="note" className="rounded-xl bg-muted/40 p-3 text-xs leading-5">{t("remote.activeForgetWarning")}</p>}
|
||||
{removalProfile?.paired && <div className="space-y-2 text-xs text-muted-foreground"><p>{t("remote.pair.forgetHint")}</p>{removalProfile.revoke_command && <CodeBlock language="bash" code={removalProfile.revoke_command} highlight={false} className="min-w-0 [&_pre]:[overflow-wrap:anywhere]" />}</div>}
|
||||
{error && <p role="alert" className="flex items-start gap-2 text-[13px] leading-5 text-foreground"><AlertCircle aria-hidden="true" className="mt-0.5 h-4 w-4 shrink-0 text-muted-foreground" />{error}</p>}
|
||||
<div className="grid grid-cols-2 gap-2"><Button variant="ghost" disabled={!!busy} onClick={() => setRemoving(null)}>{t("common.cancel")}</Button><Button variant="destructive" className="h-auto min-h-10 min-w-0" disabled={!!busy} aria-busy={!!busy} onClick={() => { void remove(); }}>{busy && <Loader2 aria-hidden className="mr-2 h-4 w-4 shrink-0 animate-spin motion-reduce:animate-none" />}<span className="whitespace-normal break-words">{t(removalIsShared ? "remote.sameInstance.forgetAction" : "remote.forget")}</span></Button></div>
|
||||
{removalProfile?.paired && <div className="space-y-2 text-xs leading-5 text-muted-foreground"><p>{t("remote.pair.forgetHint")}</p>{removalProfile.revoke_command && <CodeBlock language="bash" code={removalProfile.revoke_command} highlight={false} className="min-w-0 [&_pre]:[overflow-wrap:anywhere]" />}</div>}
|
||||
{error && <p role="alert" className="remote-alert items-start gap-2 text-[13px] leading-5 text-foreground"><AlertCircle aria-hidden="true" className="mt-0.5 h-4 w-4 shrink-0 text-muted-foreground" /><span>{error}</span></p>}
|
||||
<div className="remote-dialog-actions"><Button variant="ghost" disabled={!!busy} onClick={() => setRemoving(null)}>{t("common.cancel")}</Button><Button variant="destructive" className="h-auto min-h-10 min-w-0" disabled={!!busy} aria-busy={!!busy} onClick={() => { void remove(); }}>{busy && <Loader2 aria-hidden className="mr-2 h-4 w-4 shrink-0 animate-spin motion-reduce:animate-none" />}<span className="whitespace-normal break-words">{t(removalIsShared ? "remote.sameInstance.forgetAction" : "remote.forget")}</span></Button></div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</div>;
|
||||
|
||||
@@ -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<string, HostConnectionState>;
|
||||
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<HTMLDivElement>(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 <RemoteContext.Provider value={{ available, localActive: !selected, directory,
|
||||
activeHostId: selected?.id || null, hostStates, managing, closeManagement: () => 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 }}>
|
||||
<HostNavigationContext.Provider value={bridge.embedded || (available || selected ? picker : null)}>
|
||||
<div className="flex h-full min-h-0 flex-col bg-background">
|
||||
<div className="relative min-h-0 flex-1 overflow-hidden">
|
||||
<div ref={localPanel} data-host-view="local" aria-hidden={!!selected && !managing} {...(selected && !managing ? { inert: "" } : {})}
|
||||
style={{ visibility: selected && !managing ? "hidden" : "visible" }}
|
||||
className={`absolute inset-0 transition-opacity duration-150 motion-reduce:transition-none ${selected && !managing ? "invisible pointer-events-none opacity-0" : "visible opacity-100"}`}>
|
||||
<div ref={localPanel} data-host-view="local" aria-hidden={!!selected} {...(selected ? { inert: "" } : {})}
|
||||
style={{ visibility: selected ? "hidden" : "visible" }}
|
||||
className={`absolute inset-0 transition-opacity duration-150 motion-reduce:transition-none ${selected ? "invisible pointer-events-none opacity-0" : "visible opacity-100"}`}>
|
||||
{children}
|
||||
</div>
|
||||
{frames.map((frame) => {
|
||||
const active = !managing && selected?.id === frame.connection.id;
|
||||
const active = (!managing || !!bridge.surface) && selected?.id === frame.connection.id;
|
||||
return <div key={`${frame.connection.id}:${frame.connection.gateway_id}:${frame.connection.view_id || ""}`} data-host-view={frame.connection.id} aria-hidden={!active || offline}
|
||||
{...(!active || offline ? { inert: "" } : {})} style={{ visibility: active ? "visible" : "hidden" }}
|
||||
className={`absolute inset-0 transition-opacity duration-150 motion-reduce:transition-none ${active ? "visible opacity-100" : "invisible pointer-events-none opacity-0"}`}>
|
||||
@@ -160,18 +182,26 @@ export function RemoteInstances({ children }: { children: ReactNode }) {
|
||||
onLoad={() => { bridge.initialize(frame.connection.id); hosts.loaded(frame.connection.id); }} />
|
||||
</div>;
|
||||
})}
|
||||
{!managing && selected && (offline || !activeFrame?.loaded) && <div className="absolute inset-0 flex flex-col items-center justify-center gap-3 bg-background px-6 text-center">
|
||||
{managing && selected && <main data-testid="remote-management-surface"
|
||||
className="absolute bottom-0 right-0 flex min-h-0 flex-col bg-background"
|
||||
style={{ left: offline ? 0 : Math.min(bridge.surface?.left || 0, Math.max(0, window.innerWidth - 280)), top: offline ? 0 : Math.min(bridge.surface?.top || 0, Math.max(0, window.innerHeight - 280)) }}>
|
||||
<ThemeProvider theme={bridge.surface?.theme || "light"}>
|
||||
<RemoteConnectionsPage onBackToChat={() => changeManagement(false)} mainNavigationExpanded={!!bridge.surface?.left} />
|
||||
</ThemeProvider>
|
||||
</main>}
|
||||
{!managing && selected && (offline || !activeFrame?.loaded) && <div className="absolute inset-0 overflow-y-auto bg-background p-6 text-center"><div className="flex min-h-full flex-col items-center justify-center gap-3">
|
||||
{offline ? <PlugZap className="h-7 w-7 text-muted-foreground" /> : <Loader2 className="h-6 w-6 animate-spin text-muted-foreground" />}
|
||||
<p className="max-w-full break-words text-xs text-muted-foreground">{selected.name} · {selected.hostname}</p>
|
||||
<p className="font-medium">{t(offline ? "remote.offline" : "remote.opening")}</p>
|
||||
<p className="max-w-sm text-sm text-muted-foreground">{recoveryMessage}</p>
|
||||
<div className="flex flex-wrap items-center justify-center gap-2">
|
||||
{offline && (needsRemoteSetup(recoveryCode) ? <Button onClick={manage}>{t("remote.manageConnections")}</Button> : <Button disabled={!!pending} aria-busy={!!pending} onClick={() => switchHost(selected.id)}>
|
||||
<p className="max-w-full text-pretty text-xs text-muted-foreground [overflow-wrap:anywhere]">{selected.name} · {selected.hostname}</p>
|
||||
<p className="font-medium">{t(offline ? recoveryTitle : "remote.opening")}</p>
|
||||
<p className="max-w-sm text-pretty text-sm text-muted-foreground">{recoveryMessage}</p>
|
||||
<div className="flex max-w-full flex-wrap items-stretch justify-center gap-2 [&>button]:h-auto [&>button]:min-h-10 [&>button]:min-w-0 [&>button]:max-w-full [&>button]:whitespace-normal">
|
||||
{offline && compatibilityFailure && <Button onClick={() => setVersionOpen(true)}>{t("remote.compatibility.title")}</Button>}
|
||||
{offline && (needsRemoteSetup(recoveryCode) && !compatibilityFailure ? <Button onClick={manage}>{t("remote.manageConnections")}</Button> : <Button variant={compatibilityFailure ? "ghost" : "default"} disabled={!!pending} aria-busy={!!pending} onClick={() => switchHost(selected.id)}>
|
||||
{pending && <Loader2 aria-hidden className="mr-2 h-4 w-4 animate-spin motion-reduce:animate-none" />}{t(pending ? "remote.connecting" : "remote.reconnect")}
|
||||
</Button>)}
|
||||
<Button variant="ghost" onClick={hosts.local}>{t("remote.returnLocal")}</Button>
|
||||
</div>
|
||||
</div>}
|
||||
</div></div>}
|
||||
</div>
|
||||
{/* 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 }) {
|
||||
<div className="flex w-52 min-w-0"><HostSwitcher /></div>
|
||||
</div>}
|
||||
<RemoteHostMenu picker={picker} anchor={bridge.anchor} onClose={bridge.close} />
|
||||
<HostCompatibilityDialog profile={versionOpen ? directory?.profiles.find((profile) => profile.id === selected?.id) : undefined}
|
||||
clientVersion={directory?.client_version} onClose={() => setVersionOpen(false)} />
|
||||
</div>
|
||||
</HostNavigationContext.Provider>
|
||||
</RemoteContext.Provider>;
|
||||
|
||||
@@ -82,9 +82,9 @@ export function SSHHostPicker({ disabled, value, configFile, imported, suggestio
|
||||
}} />
|
||||
<p id={`${id}-hint`} role={imported ? "status" : undefined} className="text-xs leading-5 text-muted-foreground">{t(imported ? "remote.commandImported" : suggestions ? "remote.commandHint" : "remote.addressHint")}</p>
|
||||
{suggestions && (!!hosts.length || !!error) && <div className="rounded-2xl bg-muted/40 p-1.5">
|
||||
<div className="flex h-8 items-center justify-between gap-2 px-2">
|
||||
<div className="flex min-h-8 items-center justify-between gap-2 px-2">
|
||||
<span className="text-xs text-muted-foreground">{t("remote.sshHosts")}</span>
|
||||
<Button type="button" variant="ghost" size="icon" className="h-7 w-7" aria-label={t("remote.refreshHosts")}
|
||||
<Button type="button" variant="ghost" size="icon" className="h-7 w-7 shrink-0" aria-label={t("remote.refreshHosts")}
|
||||
disabled={busy || disabled} onClick={() => { void load(file); }}>
|
||||
<RefreshCw className={`h-3.5 w-3.5 ${busy ? "animate-spin" : ""}`} />
|
||||
</Button>
|
||||
@@ -102,8 +102,8 @@ export function SSHHostPicker({ disabled, value, configFile, imported, suggestio
|
||||
}
|
||||
}}
|
||||
onClick={() => { onChange(host.host); inputRef.current?.focus(); }}>
|
||||
<Server className="h-4 w-4 shrink-0 text-muted-foreground" /><span className="flex-1 truncate">{host.host}</span>
|
||||
{value === host.host && <Check className="h-3.5 w-3.5 text-muted-foreground" />}
|
||||
<Server className="h-4 w-4 shrink-0 text-muted-foreground" /><span className="min-w-0 flex-1 truncate">{host.host}</span>
|
||||
{value === host.host && <Check className="h-3.5 w-3.5 shrink-0 text-muted-foreground" />}
|
||||
</button>)}
|
||||
</div>
|
||||
{error && <p role="alert" className="px-2 py-1 text-xs leading-5 text-muted-foreground">{error}</p>}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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<Map<string, HTMLIFrameElement>>, restoreLocalFocus: () => void,
|
||||
activity: { pendingName?: string; error?: string }) {
|
||||
activity: { pendingName?: string; error?: string }, managing = false, onLeaveManagement?: () => void) {
|
||||
const [embedded, setEmbedded] = useState<EmbeddedHost | null>(null);
|
||||
const [readyIds, setReadyIds] = useState<string[]>([]);
|
||||
const [anchor, setAnchor] = useState<HostAnchor | null>(null);
|
||||
const [surfaces, setSurfaces] = useState<Record<string, HostAnchor & { theme?: "light" | "dark" }>>({});
|
||||
const [hostedManagement, setHostedManagement] = useState(false);
|
||||
const parent = useRef<Peer | null>(null);
|
||||
const peers = useRef(new Map<string, Peer>());
|
||||
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);
|
||||
|
||||
Reference in new issue
Block a user