Files
openidea/src/platform/openUrl.ts
T
rohitkumardandaandrohitdanda 8df59cf5a7 fix(remote): decide routing, trust and accepted events on the desktop (#2999)
In a remote window the desktop took several decisions about itself from the server: it routed commands by the server's `commands` reply (a command the server left out ran locally), authorized its own commands from the server's `project_current().trusted`, and showed or ran whatever events the server forwarded, including any workbench action named by a plugin `executeCommand` event.

- Routing: commands go by `rpc::client_commands()`, the list a server of this build serves, compiled into the desktop; a test builds the server's dispatcher and compares the two.
- Trust: commands that run on the desktop follow the desktop's own decision, stored in `remote-project-trust.json` by target and root (a dev container also follows its local folder). The trust prompt appears unless the desktop's and the server's decisions agree; the answer and Revoke Trust update both. New commands `remote_trust_status` / `remote_trust_set`.
- Events: server `event`s pass an exhaustive allow-list (MCP approvals, update notices and window-group events are dropped); plugin `executeCommand` may only name `plugin.<id>.<command>`; `openProject` is dropped.
- Paths: a project root that the desktop would read as a share or device path is refused at connect.
- A remote plugin's `openUrl` and `copyToClipboard` ask first, showing the full address or the text.

Co-authored-by: rohitdanda <10144914+rohitdanda@users.noreply.github.com>
2026-11-13 11:05:12 +08:00

25 lines
802 B
TypeScript

import { isTauri } from "./ipc";
const OPENABLE_PROTOCOLS = new Set(["http:", "https:", "mailto:"]);
/** Plugins and rendered content reach this with arbitrary strings: never hand `file:` or app-launching schemes to the OS. */
export function isOpenable(url: string): boolean {
if (url !== url.trim()) return false;
try {
return OPENABLE_PROTOCOLS.has(new URL(url).protocol);
} catch {
return false;
}
}
/** Opens a web or `mailto:` URL with the system handler (the default browser); other schemes are ignored. */
export async function openExternalUrl(url: string): Promise<void> {
if (!isOpenable(url)) return;
if (!isTauri()) {
window.open(url, "_blank", "noopener");
return;
}
const { openUrl } = await import("@tauri-apps/plugin-opener");
await openUrl(url);
}