-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreload.js
More file actions
39 lines (37 loc) · 1.4 KB
/
Copy pathpreload.js
File metadata and controls
39 lines (37 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const { contextBridge, ipcRenderer } = require("electron");
/**
* Preload (runs in isolated context).
* Exposes a minimal, typed-like API to the renderer.
*
* Renderer is intentionally "Vanilla web" (no Node access).
*/
contextBridge.exposeInMainWorld("AiFlow", {
env: {
// ID уже загружен в процессе main.js через dotenv,
// так что мы просто безопасно прокидываем его сюда
googleOAuthClientId: String(process.env.GOOGLE_OAUTH_CLIENT_ID || "").trim(),
},
models: {
list: () => ipcRenderer.invoke("models:list"),
add: (payload) => ipcRenderer.invoke("models:add", payload),
delete: (payload) => ipcRenderer.invoke("models:delete", payload),
togglePin: (payload) => ipcRenderer.invoke("models:togglePin", payload),
},
oauth: {
// Renderer -> Main
start: (payload) => ipcRenderer.invoke("oauth:start", payload),
logout: () => ipcRenderer.invoke("oauth:logout"),
// Backward compatibility with previous channel name.
startLegacy: (payload) => ipcRenderer.invoke("oauth", payload),
// Main -> Renderer
onOAuth: (handler) => {
ipcRenderer.on("oauth", (_event, data) => handler(data));
},
onAuth: (handler) => {
ipcRenderer.on("auth", (_event, data) => handler(data));
},
},
google: {
openWebSessionBridge: () => ipcRenderer.invoke("google:openWebSessionBridge"),
},
});