bitburner-src/electron/preload.js

34 lines
941 B
JavaScript
Raw Normal View History

/* eslint-disable @typescript-eslint/no-var-requires */
2022-04-07 01:30:08 +02:00
const { ipcRenderer, contextBridge } = require("electron");
2022-04-07 01:30:08 +02:00
contextBridge.exposeInMainWorld("electronBridge", {
send: (channel, data) => {
// whitelist channels
let validChannels = [
"get-save-data-response",
"get-save-info-response",
"push-game-saved",
"push-game-ready",
"push-import-result",
"push-disable-restore",
];
if (validChannels.includes(channel)) {
ipcRenderer.send(channel, data);
}
2022-04-07 01:30:08 +02:00
},
receive: (channel, func) => {
let validChannels = [
"get-save-data-request",
"get-save-info-request",
"push-save-request",
"trigger-save",
"trigger-game-export",
"trigger-scripts-export",
];
if (validChannels.includes(channel)) {
// Deliberately strip event as it includes `sender`
ipcRenderer.on(channel, (event, ...args) => func(...args));
}
},
});