-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathpreload.js
26 lines (24 loc) · 811 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
const { shell, contextBridge, ipcRenderer } = require("electron");
contextBridge.exposeInMainWorld(
"api", {
patreon: () => {
shell.openExternal("http://patreon.com/mrprimate");
},
// to backend
send: (channel, data) => {
// whitelist channels
let validChannels = ["loadConfig", "outputDir", "books", "generate", "user"];
if (validChannels.includes(channel)) {
ipcRenderer.send(channel, data);
}
},
// to frontend
receive: (channel, func) => {
let validChannels = ["config", "books", "generate", "user", "stateMessage", "directoryConfig"];
if (validChannels.includes(channel)) {
// Deliberately strip event as it includes `sender`
ipcRenderer.on(channel, (event, ...args) => func(...args));
}
}
}
);