2026-09-17 18:57:02 +03:00
|
|
|
/*
|
|
|
|
|
* Preload (2026-09-17, narrow-window wave): the ONLY bridge between the
|
|
|
|
|
* sandboxed renderer and the main process. contextIsolation + sandbox are
|
|
|
|
|
* on (electron/main.cjs), so this file is the renderer's entire access to
|
|
|
|
|
* Electron — keep it a minimal, explicit API surface.
|
|
|
|
|
*
|
2026-10-11 10:12:13 +03:00
|
|
|
* window.lh.platform — read-only OS identity for native window-control
|
|
|
|
|
* gutters (darwin: left traffic lights; win32/linux: right overlay).
|
|
|
|
|
*
|
2026-09-17 18:57:02 +03:00
|
|
|
* window.lh.expandWindow() — widen the window to the sidebar auto-close
|
|
|
|
|
* threshold (928px) when the sidebar is opened below it. The main
|
|
|
|
|
* process clamps: no-op if the window is already wide enough.
|
|
|
|
|
*
|
2026-10-05 05:42:27 +03:00
|
|
|
* window.lh.onZoom(cb) / window.lh.getZoom() — the zoom truth (owner
|
|
|
|
|
* round 7, 2026-10-05): every ⌘±/⌘0 change arrives as "lh:zoom" with
|
|
|
|
|
* the new factor; getZoom covers the first-paint race. The renderer
|
|
|
|
|
* publishes it as --lh-zoom so physical-constant lengths (the traffic-
|
|
|
|
|
* light gutter) can divide by it.
|
|
|
|
|
*
|
2026-10-10 14:11:19 +03:00
|
|
|
* window.lh.onUpdateStatus(cb) / window.lh.installUpdate() — the
|
|
|
|
|
* auto-update channel (Wave C, 2026-10-10): "lh:update-status" pushes
|
|
|
|
|
* {status:"downloaded", version} once an update is staged; installUpdate
|
|
|
|
|
* asks main to kill the server and quit-and-install. Browser builds:
|
|
|
|
|
* both absent, the banner never renders.
|
|
|
|
|
*
|
2026-09-17 18:57:02 +03:00
|
|
|
* Channel names are mirrored in electron/main.cjs — keep them in sync.
|
|
|
|
|
*/
|
|
|
|
|
const { contextBridge, ipcRenderer } = require("electron");
|
|
|
|
|
|
|
|
|
|
contextBridge.exposeInMainWorld("lh", {
|
2026-10-11 10:12:13 +03:00
|
|
|
platform: process.platform,
|
2026-10-24 12:17:08 +03:00
|
|
|
chatgpt: {
|
|
|
|
|
status: () => ipcRenderer.invoke("lh:chatgpt:control", { op: "status" }),
|
|
|
|
|
login: (id) => ipcRenderer.invoke("lh:chatgpt:control", { op: "login", id }),
|
|
|
|
|
cancel: () => ipcRenderer.invoke("lh:chatgpt:control", { op: "cancel" }),
|
|
|
|
|
select: (id) => ipcRenderer.invoke("lh:chatgpt:control", { op: "select", id }),
|
|
|
|
|
logout: (id) => ipcRenderer.invoke("lh:chatgpt:control", { op: "logout", id }),
|
|
|
|
|
consent: (id, enabled) => ipcRenderer.invoke("lh:chatgpt:control", { op: "consent", id, enabled }),
|
|
|
|
|
onChange: (cb) => {
|
|
|
|
|
const listener = () => cb();
|
|
|
|
|
ipcRenderer.on("lh:chatgpt:changed", listener);
|
|
|
|
|
return () => ipcRenderer.removeListener("lh:chatgpt:changed", listener);
|
|
|
|
|
},
|
|
|
|
|
},
|
2026-09-17 18:57:02 +03:00
|
|
|
expandWindow: () => ipcRenderer.send("lh:expand-window"),
|
2026-10-05 05:42:27 +03:00
|
|
|
onZoom: (cb) => {
|
|
|
|
|
const listener = (_event, factor) => cb(factor);
|
|
|
|
|
ipcRenderer.on("lh:zoom", listener);
|
|
|
|
|
return () => ipcRenderer.removeListener("lh:zoom", listener);
|
|
|
|
|
},
|
|
|
|
|
getZoom: () => ipcRenderer.invoke("lh:zoom:get"),
|
2026-10-10 14:11:19 +03:00
|
|
|
onUpdateStatus: (cb) => {
|
|
|
|
|
const listener = (_event, status) => cb(status);
|
|
|
|
|
ipcRenderer.on("lh:update-status", listener);
|
|
|
|
|
return () => ipcRenderer.removeListener("lh:update-status", listener);
|
|
|
|
|
},
|
|
|
|
|
installUpdate: () => ipcRenderer.send("lh:update-install"),
|
2026-09-17 18:57:02 +03:00
|
|
|
});
|