2021-08-05 10:02:56 +05:00
|
|
|
const { contextBridge } = require("electron");
|
|
|
|
|
const { ipcRenderer } = require("electron-better-ipc");
|
2021-07-07 00:56:34 +05:00
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
});
|
2021-08-05 10:02:56 +05:00
|
|
|
|
|
|
|
|
// Expose protected methods that allow the renderer process to use
|
|
|
|
|
// the ipcRenderer without exposing the entire object
|
|
|
|
|
contextBridge.exposeInMainWorld("config", {
|
|
|
|
|
zoomFactor: () => {
|
|
|
|
|
return ipcRenderer.callMain("fromRenderer", { type: "getZoomFactor" });
|
|
|
|
|
},
|
|
|
|
|
});
|
2021-08-20 11:05:27 +05:00
|
|
|
|
|
|
|
|
contextBridge.exposeInMainWorld("native", {
|
|
|
|
|
selectDirectory: ({ title, buttonLabel, defaultPath }) => {
|
|
|
|
|
return ipcRenderer.callMain("fromRenderer", {
|
|
|
|
|
type: "selectDirectory",
|
|
|
|
|
title,
|
|
|
|
|
buttonLabel,
|
|
|
|
|
defaultPath,
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
});
|