aboutsummaryrefslogtreecommitdiff
path: root/src/VencordNative.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/VencordNative.ts')
-rw-r--r--src/VencordNative.ts37
1 files changed, 29 insertions, 8 deletions
diff --git a/src/VencordNative.ts b/src/VencordNative.ts
index 7fbe6df..fc1e690 100644
--- a/src/VencordNative.ts
+++ b/src/VencordNative.ts
@@ -1,12 +1,33 @@
-import { IPC_QUICK_CSS_UPDATE, IPC_GET_QUICK_CSS } from './utils/ipcEvents';
-import { ipcRenderer } from 'electron';
+import IPC_EVENTS from './utils/IpcEvents';
+import { IpcRenderer, ipcRenderer } from 'electron';
export default {
- handleQuickCssUpdate(cb: (s: string) => void) {
- ipcRenderer.on(IPC_QUICK_CSS_UPDATE, (_, css) => {
- cb(css);
- });
+ 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.`);
+ }
},
- getQuickCss: () => ipcRenderer.invoke(IPC_GET_QUICK_CSS) as Promise<string>,
- getVersions: () => process.versions
+ 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);
+ }
}; \ No newline at end of file