mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 06:59:31 +01:00
23 lines
678 B
JavaScript
23 lines
678 B
JavaScript
|
|
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
|
||
|
|
let validChannels = ["fromRenderer"];
|
||
|
|
if (validChannels.includes(channel)) {
|
||
|
|
ipcRenderer.send(channel, data);
|
||
|
|
}
|
||
|
|
},
|
||
|
|
receive: (channel, func) => {
|
||
|
|
let validChannels = ["fromMain"];
|
||
|
|
if (validChannels.includes(channel)) {
|
||
|
|
// Deliberately strip event as it includes `sender`
|
||
|
|
ipcRenderer.on(channel, (event, args) => {
|
||
|
|
func(args);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
},
|
||
|
|
});
|