mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-08 22:23:02 -04:00
feat: Experimental browser support
This commit is contained in:
parent
a9eae106c7
commit
cc25753314
14 changed files with 212 additions and 41 deletions
39
browser/VencordNativeStub.ts
Normal file
39
browser/VencordNativeStub.ts
Normal file
|
@ -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))
|
||||
},
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue