Repository navigation
Expand file tree
/
Copy pathpreload.js
More file actions
40 lines (40 loc) · 1.8 KB
/
Copy pathpreload.js
File metadata and controls
40 lines (40 loc) · 1.8 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
40
const { contextBridge, ipcRenderer } = require("electron");
const invoke = (channel) => () => ipcRenderer.invoke(channel);
const subscribe = (channel) => (callback) => {
if (typeof callback !== "function") throw new TypeError("Listener must be a function");
const listener = (_event, payload) => callback(payload);
ipcRenderer.on(channel, listener);
return () => ipcRenderer.removeListener(channel, listener);
};
contextBridge.exposeInMainWorld(
"cinder",
Object.freeze({
platform: process.platform,
minimize: invoke("window:minimize"),
close: invoke("window:close"),
toggleMaximize: invoke("window:toggle-maximize"),
isMaximized: invoke("window:is-maximized"),
collect: invoke("usage:collect"),
readPricing: invoke("pricing:read"),
savePricing: (rules) => ipcRenderer.invoke("pricing:save", rules),
calls: invoke("usage:calls"),
readLimits: invoke("limits:read"),
onLimitsProgress: subscribe("limits:progress"),
refreshLimits: invoke("limits:refresh"),
cursorAccountUsage: (input) => ipcRenderer.invoke("accounts:cursor-usage", input),
useResetCredit: (input) => ipcRenderer.invoke("limits:reset", input),
limitsProfiles: invoke("limits:profiles"),
addLimitsProfile: (provider) => ipcRenderer.invoke("limits:add-profile", provider),
removeLimitsProfile: (profile) => ipcRenderer.invoke("limits:remove-profile", profile),
cancelScan: invoke("usage:cancel"),
snapshotInfo: invoke("snapshot:info"),
snapshotUsage: invoke("snapshot:usage"),
snapshotCalls: invoke("snapshot:calls"),
setBackground: (color) => {
if (typeof color === "string") ipcRenderer.send("theme:background", color);
},
onWindowState: subscribe("window:state"),
onScanProgress: subscribe("usage:progress"),
onMenuRescan: subscribe("menu:rescan")
})
);