2021-05-23 20:42:16 +00:00
|
|
|
const {
|
|
|
|
contextBridge,
|
|
|
|
ipcRenderer
|
|
|
|
} = require("electron");
|
|
|
|
|
|
|
|
// 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
|
2021-05-28 10:40:06 +00:00
|
|
|
let validChannels = ["openDownloadsFolder", "applogin", "selectDownloadFolder"];
|
2021-05-23 20:42:16 +00:00
|
|
|
if (validChannels.includes(channel)) {
|
|
|
|
ipcRenderer.send(channel, data);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
receive: (channel, func) => {
|
2021-05-28 10:40:06 +00:00
|
|
|
let validChannels = ["downloadFolderSelected", "applogin_arl"];
|
2021-05-23 20:42:16 +00:00
|
|
|
if (validChannels.includes(channel)) {
|
|
|
|
// Deliberately strip event as it includes `sender`
|
|
|
|
ipcRenderer.on(channel, (event, ...args) => func(...args));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|