diff options
author | Vendicated <vendicated@riseup.net> | 2022-10-21 23:58:41 +0200 |
---|---|---|
committer | Vendicated <vendicated@riseup.net> | 2022-10-21 23:58:41 +0200 |
commit | 4b1e96b76ee4eea16fcb3b5cae74e173541b3c74 (patch) | |
tree | 34da83427a29bae343e34681a9d7a08704b6d51d /browser/VencordNativeStub.ts | |
parent | e93111fb67e415b0828418b23811152d7e4eee86 (diff) | |
download | Vencord-4b1e96b76ee4eea16fcb3b5cae74e173541b3c74.tar.gz Vencord-4b1e96b76ee4eea16fcb3b5cae74e173541b3c74.tar.bz2 Vencord-4b1e96b76ee4eea16fcb3b5cae74e173541b3c74.zip |
Vencord Web: QuickCss Monaco Editor
Diffstat (limited to 'browser/VencordNativeStub.ts')
-rw-r--r-- | browser/VencordNativeStub.ts | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/browser/VencordNativeStub.ts b/browser/VencordNativeStub.ts index b6d1121..ee093fa 100644 --- a/browser/VencordNativeStub.ts +++ b/browser/VencordNativeStub.ts @@ -1,20 +1,28 @@ import IpcEvents from "../src/utils/IpcEvents"; +import * as DataStore from "../src/api/DataStore"; // Discord deletes this so need to store in variable -var { localStorage } = window; +const { localStorage } = window; + +// listeners for ipc.on +const listeners = {} as Record<string, Set<Function>>; const handlers = { - [IpcEvents.GET_REPO]: () => "", // TODO + [IpcEvents.GET_REPO]: () => "https://github.com/Vendicated/Vencord", // shrug [IpcEvents.GET_SETTINGS_DIR]: () => "LocalStorage", - [IpcEvents.GET_QUICK_CSS]: () => localStorage.getItem("VencordQuickCss"), + [IpcEvents.GET_QUICK_CSS]: () => DataStore.get("VencordQuickCss").then(s => s ?? ""), + [IpcEvents.SET_QUICK_CSS]: (css: string) => { + DataStore.set("VencordQuickCss", css); + listeners[IpcEvents.QUICK_CSS_UPDATE]?.forEach(l => l(null, css)); + }, + [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[]) { @@ -23,16 +31,17 @@ function onEvent(event: string, ...args: any[]) { return handler(...args); } +// probably should make this less cursed at some point window.VencordNative = { getVersions: () => ({}), ipc: { send: (event: string, ...args: any[]) => void onEvent(event, ...args), sendSync: onEvent, on(event: string, listener: () => {}) { - // TODO quickCss + (listeners[event] ??= new Set()).add(listener); }, off(event: string, listener: () => {}) { - // not used for now + return listeners[event]?.delete(listener); }, invoke: (event: string, ...args: any[]) => Promise.resolve(onEvent(event, ...args)) }, |