diff options
author | Vendicated <vendicated@riseup.net> | 2022-08-31 04:07:16 +0200 |
---|---|---|
committer | Vendicated <vendicated@riseup.net> | 2022-08-31 04:07:16 +0200 |
commit | 98cb301df53305f397ac6e1b4e603c930820f228 (patch) | |
tree | 8c3bc642d0871a38f99aa2c2e8586bd7310cb361 /src/VencordNative.ts | |
parent | cb288e204dd531b31f957f82150398d22930fdeb (diff) | |
download | Vencord-98cb301df53305f397ac6e1b4e603c930820f228.tar.gz Vencord-98cb301df53305f397ac6e1b4e603c930820f228.tar.bz2 Vencord-98cb301df53305f397ac6e1b4e603c930820f228.zip |
Make Settings & Settings Page
Diffstat (limited to 'src/VencordNative.ts')
-rw-r--r-- | src/VencordNative.ts | 37 |
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 |