forked from myadmin/actions-electron-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreload.js
41 lines (39 loc) · 1.41 KB
/
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const { contextBridge, ipcRenderer, remote, shell } = require('electron');
const ipc = {
render: {
// From render to main.
send: ["toMain", "render-send", "checkForUpdate", "isUpdateNow", "checkAppVersion"],
// From main to render.
receive: ["updateAvailable", "message", "downloadProgress", "checking-for-update", "update-not-available", "isUpdateNow", "version"],
// From render to main and back again.
sendReceive: []
}
};
contextBridge.exposeInMainWorld('electron', {
ipcRenderer,
remote,
shell,
'ipcRender': {
send: (channel, data) => {
// whitelist channels
let validChannels = ipc.render.send;
if (validChannels.includes(channel)) {
ipcRenderer.send(channel, data);
}
},
receive: (channel, func) => {
let validChannels = ipc.render.receive;
// console.log('validChannels', validChannels);
if (validChannels.includes(channel)) {
// Deliberately strip event as it includes `sender`
ipcRenderer.on(`${channel}`, (event, ...args) => func(...args));
}
},
invoke: (channel, args) => {
let validChannels = ipc.render.sendReceive;
if (validChannels.includes(channel)) {
return ipcRenderer.invoke(channel, args);
}
}
}
});