-
Notifications
You must be signed in to change notification settings - Fork 13
/
consolePreload.js
28 lines (27 loc) · 946 Bytes
/
consolePreload.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
// Preload script.
const { contextBridge, ipcRenderer, remote } = require('electron'); // eslint-disable-line
// Expose protected methods that allow the renderer process to use
// the ipcRenderer without exposing the entire object.
// Big hat tip: https://stackoverflow.com/a/59814127/24215.
contextBridge.exposeInMainWorld(
'api', {
send: (channel, data) => {
// Approved channels
const validChannels = [];
if (validChannels.includes(channel)) {
ipcRenderer.send(channel, data);
} else {
console.error('Invalid message sent by console');
}
},
receive: (channel, func) => {
const validChannels = ['log_message'];
if (validChannels.includes(channel)) {
// Remove the event to avoid information leaks.
ipcRenderer.on(channel, (event, ...args) => func(...args));
} else {
console.error('Invalid message sent to console');
}
},
},
);