discord-awesomeaudio/assets/vencord/VencordNativeStub.ts

44 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-10-14 17:16:34 -04:00
let webclass;
const promise = new Promise((resolve) => {
setTimeout(() => {
new QWebChannel(qt.webChannelTransport, function (channel) {
webclass = channel.objects.webclass;
resolve();
});
});
});
async function prepareWebclass() {
if (!webclass) await promise;
}
window.VencordNative = {
getVersions: () => ({}),
ipc: {
send: async (event: string, ...args: any[]) => {
await prepareWebclass();
webclass.vencordSend(event, args);
},
sendSync: (event: string, ...args: any[]) => {
2022-10-22 17:56:49 -04:00
// We need this hack because Vencord requires its settings right when it starts
2022-10-14 18:15:19 -04:00
if (event === "VencordGetSettings") {
2022-10-22 17:56:49 -04:00
return window.discordScreenaudioVencordSettings || "{}";
2022-10-14 18:15:19 -04:00
} else throw new Error("Synchroneous IPC not implemented");
2022-10-14 17:16:34 -04:00
},
on(event: string, listener: () => {}) {
// TODO quickCss
},
off(event: string, listener: () => {}) {
// not used for now
},
2022-10-14 18:15:19 -04:00
invoke: async (event: string, ...args: any[]) => {
await prepareWebclass();
2022-10-22 17:56:49 -04:00
if (event === "VencordSetSettings") {
window.discordScreenaudioVencordSettings = args[0];
}
2022-10-14 18:15:19 -04:00
return webclass.vencordSend(event, args);
},
2022-10-14 17:16:34 -04:00
},
};