-
Notifications
You must be signed in to change notification settings - Fork 0
/
preload.js
32 lines (28 loc) · 1.07 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
const {
contextBridge,
ipcRenderer
} = require("electron");
// window.api.receive("fromMain", (data) => {
// console.log(`Received ${data} from main process`);
// });
// window.api.send("toMain", "some data");
// Expose protected methods that allow the renderer process to use
// the ipcRenderer without exposing the entire object
contextBridge.exposeInMainWorld(
"api", {
send: (channel, data) => {
// whitelist channels
let validChannels = ["save-file", "open-file", "create-file", "toggle-dictate", "start-speak", "set-theme", "get-theme","get-speechSpeed","set-speechSpeed","open-link","auth-location","start-ocr", "auto-save"];
if (validChannels.includes(channel)) {
ipcRenderer.send(channel, data);
}
},
receive: (channel, func) => {
let validChannels = ["new-file", "text-dictate", "audio-speak", "current-theme","current-speechSpeed","result-ocr","fail-ocr"];
if (validChannels.includes(channel)) {
// Deliberately strip event as it includes `sender`
ipcRenderer.on(channel, (event, ...args) => func(...args));
}
}
}
);