Файли
openidea/src/features/remote-dev/index.ts
T
l0ng-ai f70f362a3d feat(ui): open New Project, Get from VCS and Remote Development in their own windows (#6208)
* feat(ui): open New Project, Get from VCS and Remote Development in their own windows

Each dialog gets a native window over its project window: a full-height
sidebar under the traffic lights, the title heading the content and the
buttons in its corner. The windows hand their result back to the project
window, which opens the created or cloned project or makes the remote
connection and reports its progress. Remote windows and the browser build
keep the dialogs in the page.

* feat(ui): show dialogs in the page as sheets without window buttons on macOS

The title heads the content instead of a title bar with drawn traffic
lights; Esc and Cancel close the dialog, and the title dims while the
window is inactive.

* fix(ui): give a macOS dialog without footer buttons a Close button

A sheet has no window buttons, so a dialog with neither buttons nor a
footer could only be closed with Esc. The Extract Interface members
table may shrink to two rows so the dialog still fits a short window
under the taller sheet title.
2026-11-27 08:59:33 +08:00

188 рядки
6.5 KiB
TypeScript

/**
* Remote development: a window whose project lives on an SSH host, in a WSL distribution or in a
* dev container. The backend (`openidea-server`) runs there and this window routes its commands
* to it (platform/remote.ts).
*/
import { registerActions } from "@/platform/actions";
import { disconnectRemote, provideBackendBusyPrompt, stopRemoteBackend, useRemote } from "@/platform/remote";
import { lazyComponent } from "@/ui";
import { maybeEditorService, registerOverlay, registerStatusItem, registerToolWindow } from "@/workbench/contributions";
import { confirm } from "@/workbench/messages";
import { tx } from "@/platform/i18n";
import { confirmLeaveProject } from "@/platform/project";
import { ConnectHost } from "./ConnectDialog";
import { installConnectHandoff, showConnect } from "./connectWindow";
import { reopenInContainer } from "./container";
import { installDirenvNotifications, reloadEnvironment } from "./environment";
import { RemoteStatus } from "./RemoteStatus";
import { closeConnectDialog } from "./model";
import { restorePorts, usePorts } from "./ports";
import { installReconnect, reconnectNow } from "./reconnect";
/** Forwarded ports are available while this window is connected to an SSH host, a WSL distribution or a dev container. */
function trackPortsWindow(): () => void {
let off: (() => void) | null = null;
let session = useRemote.getState().session;
const sync = () => {
const next = useRemote.getState().session;
const connected =
next?.target.kind === "ssh" || next?.target.kind === "wsl" || next?.target.kind === "devContainer";
if (connected && (next !== session || !off)) {
usePorts.setState({ ports: [] });
void restorePorts();
}
session = next;
if (connected && !off) {
off = registerToolWindow({
id: "remote.ports",
title: "Ports",
icon: "web",
anchor: "bottom",
order: 40,
stripe: "onUse",
component: lazyComponent(() => import("./PortsView").then((m) => m.PortsView)),
});
} else if (!connected && off) {
off();
off = null;
usePorts.setState({ ports: [] });
}
};
sync();
const unsubscribe = useRemote.subscribe(sync);
return () => {
unsubscribe();
off?.();
};
}
export function activate(): () => void {
const disposers = [
provideBackendBusyPrompt(() =>
confirm({
title: tx("Stop Remote Backend"),
message: tx(
"The backend of another OpenIDEA build, for example the one from before an upgrade, still has this project open, so this build can't open it. Stop that backend and open the project? Its terminals, runs and agent sessions end, and changes it hasn't saved are lost.",
),
ok: tx("Stop Backend and Open"),
icon: "warning",
}),
),
trackPortsWindow(),
installReconnect(),
installDirenvNotifications(),
registerOverlay({ id: "remote.connect", component: ConnectHost }),
installConnectHandoff(),
registerStatusItem({
id: "remote.location",
title: "Remote Host",
align: "left",
priority: 100,
component: RemoteStatus,
}),
registerActions([
{
id: "remote.connect",
title: "Remote Development…",
description: "Opens a project folder on an SSH host; the IDE backend runs on that host.",
category: "File",
icon: "remote",
keywords: ["ssh", "remote", "server", "gateway", "connect", "host"],
run: () => showConnect(),
},
{
id: "remote.reconnect",
title: "Reconnect to Remote Host",
description: "Connects this window to its remote project again after the connection was lost.",
category: "File",
keywords: ["ssh", "remote", "reconnect", "connection", "lost"],
when: "remoteConnectionLost",
run: () => reconnectNow(),
},
{
id: "remote.disconnect",
title: "Disconnect from Remote Host",
category: "File",
keywords: ["ssh", "remote", "close"],
when: "projectOpen",
run: async () => {
if (!(await confirmLeaveProject(false))) return;
try {
await disconnectRemote();
} catch (e) {
maybeEditorService()?.cancelClose?.();
throw e;
}
},
},
{
id: "remote.stopBackend",
title: "Stop Remote Backend",
description:
"Stops the remote IDE backend and its terminals, runs and agent sessions, then closes the project.",
category: "File",
keywords: ["ssh", "remote", "stop", "shutdown", "backend", "server"],
when: "projectRemote && !remoteConnectionLost",
run: async () => {
const host = useRemote.getState().session?.host;
if (!host) return;
if (
!(await confirm({
title: tx("Stop Remote Backend"),
message: tx`Stop the IDE backend on ${host} and terminate its running terminals, runs and agent sessions?`,
ok: tx("Stop Backend"),
icon: "warning",
}))
)
return;
if (!(await confirmLeaveProject(false))) return;
try {
await stopRemoteBackend();
} catch (e) {
maybeEditorService()?.cancelClose?.();
throw e;
}
},
},
{
id: "remote.reopenInContainer",
title: "Reopen in Container",
description:
"Builds or starts the project's dev container (devcontainer.json) with the Dev Containers CLI and opens the project in it.",
category: "File",
icon: "folder",
keywords: ["devcontainer", "dev container", "docker", "container", "remote"],
when: "projectOpen",
run: () => reopenInContainer(),
},
{
id: "remote.reloadEnvironment",
title: "Reload Environment",
description:
"Reads the login shell's environment (and devcontainer.json remoteEnv on a remote host) again for new terminals and processes.",
category: "File",
keywords: [
"env",
"environment",
"variables",
"path",
"shell",
"remoteEnv",
"devcontainer",
"direnv",
"envrc",
"nix",
"flake",
"reload",
],
when: "projectOpen",
run: () => reloadEnvironment(),
},
]),
];
return () => {
disposers.reverse().forEach((d) => d());
closeConnectDialog();
};
}