mirror of
https://github.com/getpaseo/paseo.git
synced 2026-08-15 04:42:45 +00:00
26 lines
644 B
TypeScript
26 lines
644 B
TypeScript
import { shell, ipcMain } from "electron";
|
|
|
|
const ALLOWED_EXTERNAL_URL_PROTOCOLS = new Set(["http:", "https:"]);
|
|
|
|
export function isAllowedExternalUrl(value: unknown): value is string {
|
|
if (typeof value !== "string") {
|
|
return false;
|
|
}
|
|
|
|
try {
|
|
const url = new URL(value);
|
|
return ALLOWED_EXTERNAL_URL_PROTOCOLS.has(url.protocol);
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
export function registerOpenerHandlers(): void {
|
|
ipcMain.handle("paseo:opener:openUrl", async (_event, url: unknown) => {
|
|
if (!isAllowedExternalUrl(url)) {
|
|
throw new Error("Unsupported external URL");
|
|
}
|
|
await shell.openExternal(url);
|
|
});
|
|
}
|