Files
openidea/src/features/remote-dev/RemoteStatus.tsx
T
l0ng-ai 458286b046 fix(remote): say when a remote window loses its connection and reconnect it (#3795)
A remote window whose SSH link, host or server went away kept showing its project and failed every command with "connection closed". The desktop now tells the window when its connection ends on its own (RemoteConnectionLost); the window shows it in the status bar, reconnects after 2, 5 and 15 s (a new server, so the project opens again on it), then offers Reconnect; commands on the closed connection say "Lost the connection to <host>".

Fixes #3697
2026-11-17 00:32:31 +08:00

53 lines
1.6 KiB
TypeScript

import { executeAction } from "@/platform/actions";
import { tx } from "@/platform/i18n";
import type { RemoteSession } from "@/platform/ipc";
import { useRemote } from "@/platform/remote";
import { BarButton, Icon, Spinner } from "@/ui";
import styles from "./RemoteDev.module.css";
const BADGE: Record<RemoteSession["target"]["kind"], string> = {
ssh: "SSH",
wsl: "WSL",
devContainer: "Dev Container",
};
/** Status bar label of a remote window: where its project runs. */
export function remoteBadge(session: Pick<RemoteSession, "target" | "host">): string {
return `${BADGE[session.target.kind]}: ${session.host}`;
}
export function RemoteStatus() {
const session = useRemote((s) => s.session);
const lost = useRemote((s) => s.lost !== null);
const reconnecting = useRemote((s) => s.reconnecting);
if (!session) return null;
const label = remoteBadge(session);
if (lost)
return (
<BarButton
tooltip={
reconnecting
? tx`Reconnecting to ${session.host}…`
: tx`Lost the connection to ${session.host}. Click to reconnect.`
}
aria-label={tx`${label} (disconnected)`}
disabled={reconnecting}
onClick={() => void executeAction("remote.reconnect")}
>
<span className={styles.lost}>
{reconnecting ? <Spinner size={10} /> : <Icon name="warning" size={13} />}
{label}
</span>
</BarButton>
);
return (
<BarButton
tooltip={tx`Project runs on ${label}`}
aria-label={label}
onClick={() => void executeAction("remote.connect")}
>
{label}
</BarButton>
);
}