diff --git a/src/main/arrpc.ts b/src/main/arrpc.ts index e0fd023..1899d9c 100644 --- a/src/main/arrpc.ts +++ b/src/main/arrpc.ts @@ -5,6 +5,7 @@ */ import Server from "arrpc"; +import { IpcEvents } from "shared/IpcEvents"; import { mainWin } from "./mainWindow"; import { Settings } from "./settings"; @@ -17,11 +18,8 @@ export async function initArRPC() { if (server || !Settings.store.arRPC) return; try { - // This module starts a server as a side effect, so it needs to be lazy imported - const { send: sendToBridge } = await import("arrpc/src/bridge"); - server = await new Server(); - server.on("activity", sendToBridge); + server.on("activity", (data: any) => mainWin.webContents.send(IpcEvents.ARRPC_ACTIVITY, JSON.stringify(data))); server.on("invite", (invite: string, callback: (valid: boolean) => void) => { invite = String(invite); if (!inviteCodeRegex.test(invite)) return callback(false); diff --git a/src/preload/VesktopNative.ts b/src/preload/VesktopNative.ts index 1706bed..f99656a 100644 --- a/src/preload/VesktopNative.ts +++ b/src/preload/VesktopNative.ts @@ -58,5 +58,10 @@ export const VesktopNative = { }, capturer: { getLargeThumbnail: (id: string) => invoke(IpcEvents.CAPTURER_GET_LARGE_THUMBNAIL, id) + }, + arrpc: { + onActivity(cb: (data: string) => void) { + ipcRenderer.on(IpcEvents.ARRPC_ACTIVITY, (_, data: string) => cb(data)); + } } }; diff --git a/src/renderer/index.ts b/src/renderer/index.ts index e7871d3..9f75644 100644 --- a/src/renderer/index.ts +++ b/src/renderer/index.ts @@ -47,14 +47,12 @@ customSettingsSections.push(() => ({ className: "vc-vesktop-settings" })); -const arRPC = Vencord.Plugins.plugins["WebRichPresence (arRPC)"]; +const arRPC = Vencord.Plugins.plugins["WebRichPresence (arRPC)"] as any as { + handleEvent(e: MessageEvent): void; +}; -arRPC.required = !!Settings.store.arRPC; +VesktopNative.arrpc.onActivity(data => { + if (!Settings.store.arRPC) return; -Settings.addChangeListener("arRPC", v => { - arRPC.required = !!v; - if (v && !arRPC.started) Vencord.Plugins.startPlugin(arRPC); - else if (arRPC.started) { - Vencord.Plugins.stopPlugin(arRPC); - } + arRPC.handleEvent(new MessageEvent("message", { data })); }); diff --git a/src/shared/IpcEvents.ts b/src/shared/IpcEvents.ts index 2d453e3..1f46a5a 100644 --- a/src/shared/IpcEvents.ts +++ b/src/shared/IpcEvents.ts @@ -40,5 +40,7 @@ export const enum IpcEvents { AUTOSTART_ENABLED = "VCD_AUTOSTART_ENABLED", ENABLE_AUTOSTART = "VCD_ENABLE_AUTOSTART", - DISABLE_AUTOSTART = "VCD_DISABLE_AUTOSTART" + DISABLE_AUTOSTART = "VCD_DISABLE_AUTOSTART", + + ARRPC_ACTIVITY = "VCD_ARRPC_ACTIVITY" }