/** * The only bridge between the desktop shell and the SPA. Keep it tiny: the * renderer is the normal web build and must not need Electron to work. */ import { contextBridge, ipcRenderer } from "electron"; contextBridge.exposeInMainWorld("j621Desktop", { isDesktop: true as const, platform: process.platform, // The SPA's own origin (`app://j621`), shown by the setup screen when it // has to explain which origin to allow in the backend's CORS settings. origin: window.location.origin, getVersion: (): Promise => ipcRenderer.invoke("j621:version"), }); // Menu → "Open backend in browser": read the SPA's stored backend URL and // hand it to the main process after checking it is a real web URL. ipcRenderer.on("j621:open-backend", () => { let url = ""; try { url = window.localStorage.getItem("j621.backend") ?? ""; } catch { // Storage can be unavailable in rare cases; nothing to open then. } if (url === "none") url = ""; if (url) void ipcRenderer.invoke("j621:open-external", url); });