aboutsummaryrefslogtreecommitdiff
path: root/src/VencordNative.ts
diff options
context:
space:
mode:
authorVendicated <vendicated@riseup.net>2022-08-31 22:08:05 +0200
committerVendicated <vendicated@riseup.net>2022-08-31 22:08:05 +0200
commitf60ccb766f30e7518bc348013b72f071f86ecbc6 (patch)
tree5c1cdb5dfc1bbdc620f034308534eb19e0bcb881 /src/VencordNative.ts
parentbac8a648b6012e221fd2150062d2080b9ed0d702 (diff)
downloadVencord-f60ccb766f30e7518bc348013b72f071f86ecbc6.tar.gz
Vencord-f60ccb766f30e7518bc348013b72f071f86ecbc6.tar.bz2
Vencord-f60ccb766f30e7518bc348013b72f071f86ecbc6.zip
Add Plugin.start, make Settings actually start/stop plugins
Diffstat (limited to 'src/VencordNative.ts')
-rw-r--r--src/VencordNative.ts23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/VencordNative.ts b/src/VencordNative.ts
index 755c471..e5ccaaa 100644
--- a/src/VencordNative.ts
+++ b/src/VencordNative.ts
@@ -1,24 +1,31 @@
import IPC_EVENTS from './utils/IpcEvents';
import { IpcRenderer, ipcRenderer } from 'electron';
+function assertEventAllowed(event: string) {
+ if (!(event in IPC_EVENTS)) throw new Error(`Event ${event} not allowed.`);
+}
export default {
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.`);
+ assertEventAllowed(event);
+ ipcRenderer.send(event, ...args);
},
sendSync<T = any>(event: string, ...args: any[]): T {
- if (event in IPC_EVENTS) return ipcRenderer.sendSync(event, ...args);
- else throw new Error(`Event ${event} not allowed.`);
+ assertEventAllowed(event);
+ return ipcRenderer.sendSync(event, ...args);
},
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.`);
+ assertEventAllowed(event);
+ ipcRenderer.on(event, listener);
+ },
+ off(event: string, listener: Parameters<IpcRenderer["off"]>[1]) {
+ assertEventAllowed(event);
+ ipcRenderer.off(event, listener);
},
invoke<T = any>(event: string, ...args: any[]): Promise<T> {
- if (event in IPC_EVENTS) return ipcRenderer.invoke(event, ...args);
- else throw new Error(`Event ${event} not allowed.`);
+ assertEventAllowed(event);
+ return ipcRenderer.invoke(event, ...args);
}
},
require(mod: string) {