diff options
author | Vendicated <vendicated@riseup.net> | 2022-08-31 22:08:05 +0200 |
---|---|---|
committer | Vendicated <vendicated@riseup.net> | 2022-08-31 22:08:05 +0200 |
commit | f60ccb766f30e7518bc348013b72f071f86ecbc6 (patch) | |
tree | 5c1cdb5dfc1bbdc620f034308534eb19e0bcb881 /src/VencordNative.ts | |
parent | bac8a648b6012e221fd2150062d2080b9ed0d702 (diff) | |
download | Vencord-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.ts | 23 |
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) { |