-
Notifications
You must be signed in to change notification settings - Fork 2
/
preload.js
26 lines (25 loc) · 936 Bytes
/
preload.js
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
const {
contextBridge,
ipcRenderer
} = require("electron");
//from https://github.com/electron/electron/issues/9920#issuecomment-575839738
// Expose protected methods that allow the renderer process to use
// the ipcRenderer without exposing the entire object
contextBridge.exposeInMainWorld(
"electronAPI", {
send: (channel, data) => {
// whitelist channels
let validChannels = ["ready", "update", "relaunch"];
if (validChannels.includes(channel)) {
ipcRenderer.send(channel, data);
}
},
on: (channel, func) => {
let validChannels = ["release-info", "available", "error", "update-downloaded"];
if (validChannels.includes(channel)) {
// Deliberately strip event as it includes `sender`
ipcRenderer.on(channel, (event, ...args) => func(...args));
}
}
}
);