дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 17:47:08 +02:00
`openidea-server --web` serves the built frontend and the IDE backend over one HTTP + WebSocket port, directly or behind a reverse proxy that strips or keeps its path prefix. - The rpc dispatcher gains an async `invoke` with a channel sink, so project-host commands, streaming channels and IDE events run over WebSockets as they do over `--stdio`. - Token auth is on by default (a random token unless `--token` or `--no-auth`), binds 127.0.0.1 by default, and WebSocket upgrades must be same-origin. - The browser serves the desktop shell commands with the trust classes the desktop declares (a test keeps them in step), and the desktop menu spec, now in `ide_host::menu`. Recent-project recording and project rename are shared ide-host ops. - WebSocket output is queued without dropping channel data or events. A reloaded page gets back the project its window still has open; after a server restart the page reloads. One tab per window, with Take Over. - Browser fallbacks for the title bar menu, path chooser, clipboard, dialogs, Settings and external links; a reconnecting banner and an unsaved-changes guard. - `scripts/start-web.sh` and the guide (English and Chinese). Co-authored-by: luisfelipe18 <[email protected]>
66 рядки
2.7 KiB
TypeScript
66 рядки
2.7 KiB
TypeScript
import { isTauri } from "@/platform/ipc";
|
|
import { isRemoteWindow } from "@/platform/remote";
|
|
import type { DialogFilter, SaveDialogOptions } from "@/platform/dialog";
|
|
import { isWebMode } from "@/platform/webBridge";
|
|
|
|
export interface ChoosePathOptions {
|
|
directory: boolean;
|
|
title?: string;
|
|
defaultPath?: string;
|
|
filters?: DialogFilter[];
|
|
}
|
|
|
|
export interface HostPathOptions extends ChoosePathOptions {
|
|
multiple?: boolean;
|
|
save?: boolean;
|
|
signal?: AbortSignal;
|
|
}
|
|
|
|
type HostChooser = (opts: HostPathOptions) => Promise<string[] | null>;
|
|
let hostChooser: HostChooser | null = null;
|
|
|
|
const shouldUseHostChooser = () => isRemoteWindow() || isWebMode();
|
|
|
|
/**
|
|
* Registers the in-app chooser that browses the remote host (the workbench's, in `inputDialogs`):
|
|
* the desktop's own dialog would show this machine's files.
|
|
*/
|
|
export function registerHostPathChooser(chooser: HostChooser): () => void {
|
|
hostChooser = chooser;
|
|
return () => {
|
|
if (hostChooser === chooser) hostChooser = null;
|
|
};
|
|
}
|
|
|
|
/**
|
|
* File / folder chooser for a path on the host this window's commands run on: the desktop's dialog
|
|
* locally, the in-app chooser in a remote or web-server window. Null when cancelled or outside Tauri.
|
|
*/
|
|
export async function choosePath(opts: ChoosePathOptions, signal?: AbortSignal): Promise<string | null> {
|
|
if (!isTauri() || signal?.aborted) return null;
|
|
if (shouldUseHostChooser()) return (await hostChooser?.({ ...opts, signal }))?.[0] ?? null;
|
|
// Lazy on purpose: loading platform/dialog starts its GTK capability probe at module load.
|
|
const { open } = await import("@/platform/dialog");
|
|
if (signal?.aborted) return null;
|
|
const picked = await open({ ...opts, multiple: false, defaultPath: opts.defaultPath || undefined });
|
|
return (Array.isArray(picked) ? picked[0] : picked) ?? null;
|
|
}
|
|
|
|
/** Pick multiple existing paths on the project host. */
|
|
export async function choosePaths(opts: ChoosePathOptions): Promise<string[]> {
|
|
if (!isTauri()) return [];
|
|
if (shouldUseHostChooser()) return (await hostChooser?.({ ...opts, multiple: true })) ?? [];
|
|
const { open } = await import("@/platform/dialog");
|
|
const picked = await open({ ...opts, multiple: true });
|
|
return typeof picked === "string" ? [picked] : (picked ?? []);
|
|
}
|
|
|
|
/** Choose a destination on the project host and confirm replacement if it exists. */
|
|
export async function chooseSavePath(opts: SaveDialogOptions, signal?: AbortSignal): Promise<string | null> {
|
|
if (signal?.aborted) return null;
|
|
if (shouldUseHostChooser())
|
|
return (await hostChooser?.({ ...opts, directory: false, save: true, ...(signal && { signal }) }))?.[0] ?? null;
|
|
const { save } = await import("@/platform/dialog");
|
|
return signal?.aborted ? null : save(opts);
|
|
}
|