diff options
author | Vendicated <vendicated@riseup.net> | 2022-10-04 00:52:42 +0200 |
---|---|---|
committer | Vendicated <vendicated@riseup.net> | 2022-10-04 00:52:50 +0200 |
commit | cc257533148419b1c94a1cd257e756d2688a403c (patch) | |
tree | 84affcf23ec84304efcb381626ac4d995db0ec95 /browser/VencordNativeStub.ts | |
parent | a9eae106c7cc6cccbb5c3f030130d3c7b6461c3e (diff) | |
download | Vencord-cc257533148419b1c94a1cd257e756d2688a403c.tar.gz Vencord-cc257533148419b1c94a1cd257e756d2688a403c.tar.bz2 Vencord-cc257533148419b1c94a1cd257e756d2688a403c.zip |
feat: Experimental browser support
Diffstat (limited to 'browser/VencordNativeStub.ts')
-rw-r--r-- | browser/VencordNativeStub.ts | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/browser/VencordNativeStub.ts b/browser/VencordNativeStub.ts new file mode 100644 index 0000000..bdcae4e --- /dev/null +++ b/browser/VencordNativeStub.ts @@ -0,0 +1,39 @@ +import IpcEvents from "../src/utils/IpcEvents"; + +// Discord deletes this so need to store in variable +var localStorage = window.localStorage; + +const handlers = { + [IpcEvents.GET_REPO]: () => "", // TODO + [IpcEvents.GET_SETTINGS_DIR]: () => "LocalStorage", + + [IpcEvents.GET_QUICK_CSS]: () => localStorage.getItem("VencordQuickCss"), + [IpcEvents.GET_SETTINGS]: () => localStorage.getItem("VencordSettings") || "{}", + [IpcEvents.SET_SETTINGS]: (s: string) => localStorage.setItem("VencordSettings", s), + + [IpcEvents.GET_UPDATES]: () => ({ ok: true, value: [] }), + + [IpcEvents.OPEN_EXTERNAL]: (url: string) => open(url, "_blank"), + [IpcEvents.OPEN_QUICKCSS]: () => { } // TODO +}; + +function onEvent(event: string, ...args: any[]) { + const handler = handlers[event]; + if (!handler) throw new Error(`Event ${event} not implemented.`); + return handler(...args); +} + +window.VencordNative = { + getVersions: () => ({}), + ipc: { + send: (event: string, ...args: any[]) => void onEvent(event, ...args), + sendSync: onEvent, + on(event: string, listener: () => {}) { + // TODO quickCss + }, + off(event: string, listener: () => {}) { + // not used for now + }, + invoke: (event: string, ...args: any[]) => Promise.resolve(onEvent(event, ...args)) + }, +}; |