-
Notifications
You must be signed in to change notification settings - Fork 87.4k
Expand file tree
/
Copy pathpreload.js
More file actions
32 lines (29 loc) · 1.08 KB
/
preload.js
File metadata and controls
32 lines (29 loc) · 1.08 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
/**
* preload.js — Electron context bridge
*
* Exposes a safe, minimal API to the renderer (dashboard/app.js and
* dashboard/member.js) so they can read/write the shared tasks.json file
* without exposing the full Node.js API.
*
* contextIsolation is ON (nodeIntegration is OFF), so this is the only
* channel between the renderer and the main process.
*/
const { contextBridge, ipcRenderer } = require('electron');
contextBridge.exposeInMainWorld('electronAPI', {
/**
* Load all data from tasks.json.
* Returns { tasks, team, sync } or null if file doesn't exist yet.
* Called synchronously — app waits for data before first render.
*/
loadData: () => ipcRenderer.sendSync('load-data'),
/**
* Persist data to tasks.json.
* Fire-and-forget — renderer does not wait for the write to complete.
* @param {{ tasks: Array, team: Array, sync: string }} data
*/
saveData: (data) => ipcRenderer.send('save-data', data),
/**
* Returns the absolute path to tasks.json (shown in the sync bar).
*/
getDataPath: () => ipcRenderer.sendSync('get-data-path'),
});