2022-08-31 02:07:16 +00:00
|
|
|
import IPC_EVENTS from './utils/IpcEvents';
|
|
|
|
import { IpcRenderer, ipcRenderer } from 'electron';
|
2022-08-29 16:11:44 +00:00
|
|
|
|
|
|
|
export default {
|
2022-08-31 02:07:16 +00:00
|
|
|
getVersions: () => process.versions,
|
|
|
|
ipc: {
|
|
|
|
send(event: string, ...args: any[]) {
|
|
|
|
if (event in IPC_EVENTS) ipcRenderer.send(event, ...args);
|
|
|
|
else throw new Error(`Event ${event} not allowed.`);
|
|
|
|
},
|
|
|
|
sendSync(event: string, ...args: any[]) {
|
|
|
|
if (event in IPC_EVENTS) return ipcRenderer.sendSync(event, ...args);
|
|
|
|
else throw new Error(`Event ${event} not allowed.`);
|
|
|
|
},
|
|
|
|
on(event: string, listener: Parameters<IpcRenderer["on"]>[1]) {
|
|
|
|
if (event in IPC_EVENTS) ipcRenderer.on(event, listener);
|
|
|
|
else throw new Error(`Event ${event} not allowed.`);
|
|
|
|
},
|
|
|
|
invoke(event: string, ...args: any[]) {
|
|
|
|
if (event in IPC_EVENTS) return ipcRenderer.invoke(event, ...args);
|
|
|
|
else throw new Error(`Event ${event} not allowed.`);
|
|
|
|
}
|
2022-08-29 16:11:44 +00:00
|
|
|
},
|
2022-08-31 02:07:16 +00:00
|
|
|
require(mod: string) {
|
|
|
|
const settings = ipcRenderer.sendSync(IPC_EVENTS.GET_SETTINGS);
|
|
|
|
try {
|
|
|
|
if (!JSON.parse(settings).unsafeRequire) throw "no";
|
|
|
|
} catch {
|
|
|
|
throw new Error("Unsafe require is not allowed. Enable it in settings and try again.");
|
|
|
|
}
|
|
|
|
return require(mod);
|
|
|
|
}
|
2022-08-29 16:11:44 +00:00
|
|
|
};
|