-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpreload.js
More file actions
executable file
·46 lines (44 loc) · 1.03 KB
/
Copy pathpreload.js
File metadata and controls
executable file
·46 lines (44 loc) · 1.03 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
41
42
43
44
45
46
const { contextBridge, ipcRenderer } = require('electron');
// White-listed channels.
const $ipc = {
// From main to render
listen: [
'chat-window-opened',
'chat-window-closed'
],
// From render to main
send: [
'chat-window-open',
'chat-window-close',
'settings-set',
],
// From render to main and back again
invoke: [
'get-themes',
'theme-load',
'settings-get',
'settings-reset',
'toggle-game-mode',
'get-widget-url',
]
};
contextBridge.exposeInMainWorld('ipcRenderer', {
listen: (channel, listener) => {
let validChannels = $ipc.listen;
if (validChannels.includes(channel)) {
ipcRenderer.on(channel, (_, ...args) => listener(...args));
}
},
send: (channel, args) => {
let validChannels = $ipc.send;
if (validChannels.includes(channel)) {
ipcRenderer.send(channel, args);
}
},
invoke: (channel, args) => {
let validChannels = $ipc.invoke;
if (validChannels.includes(channel)) {
return ipcRenderer.invoke(channel, args);
}
}
});