2021-08-05 10:02:56 +05:00
|
|
|
const { ipcMain } = require("electron-better-ipc");
|
2021-07-07 00:56:34 +05:00
|
|
|
const { getAction } = require("./actions");
|
2021-08-05 10:02:56 +05:00
|
|
|
const { getCall } = require("./calls");
|
2021-07-07 00:56:34 +05:00
|
|
|
|
|
|
|
|
ipcMain.on("fromRenderer", async (event, args) => {
|
|
|
|
|
const { type } = args;
|
|
|
|
|
const action = getAction(type);
|
|
|
|
|
if (!action) return;
|
2021-08-05 10:02:56 +05:00
|
|
|
await action(args);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ipcMain.answerRenderer("fromRenderer", async (args, win) => {
|
|
|
|
|
const { type } = args;
|
|
|
|
|
const call = getCall(type);
|
|
|
|
|
if (!call) return;
|
|
|
|
|
return await call(args, win);
|
2021-07-07 00:56:34 +05:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
module.exports.sendMessageToRenderer = function (type, payload = {}) {
|
|
|
|
|
global.win.webContents.send("fromMain", {
|
|
|
|
|
type,
|
|
|
|
|
...payload,
|
|
|
|
|
});
|
|
|
|
|
};
|