Файли
openidea/src/platform/dragOut.ts
T
Luis Felipeтаluisfelipe18 9f643af069 feat(web): openidea-server --web serves the IDE to a browser (#5134)
`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]>
2026-11-26 23:00:28 +08:00

49 рядки
1.7 KiB
TypeScript

/**
* Files dragged out of the window become an OS file drag, so the app they are dropped
* on (Explorer, Finder, an SFTP client) copies them, as from IDEA's Project view (#2867).
* Only a local project's files: a remote project's live on its server.
*/
import { call, commands, isTauri } from "./ipc";
import { isRemoteWindow } from "./remote";
import { isWebMode } from "./webBridge";
/** The running drag, until it ends or the next press shows none is live. */
let running: object | null = null;
const pressed = () => {
running = null;
};
/** Whether files can be dragged out of this window. */
export function canDragOut(): boolean {
return isTauri() && !isWebMode() && !isRemoteWindow();
}
/**
* Hands `paths` to an OS drag; call while the primary button is held, once the pointer
* left the window. Resolves when the drag ends: true when another app took the files.
*/
export async function dragOut(paths: readonly string[]): Promise<boolean> {
const drag = {};
running = drag;
// A backend that loses the drag never resolves; a fresh press means it is over anyway.
window.addEventListener("pointerdown", pressed, true);
try {
return await call(commands.windowDragFiles([...paths]));
} catch (e) {
console.warn("could not drag files out", e);
return false;
} finally {
if (running === drag) running = null;
window.removeEventListener("pointerdown", pressed, true);
}
}
/**
* Whether a drag out of this window is running. An OS file drop meanwhile is the
* dragged files coming back, which the window ignores instead of importing or
* opening its own files.
*/
export function isDraggingOut(): boolean {
return running !== null;
}