arrpc: migrate from websocket + plugin to electron ipc
This commit is contained in:
parent
bf47918de0
commit
44aa861359
4 changed files with 16 additions and 13 deletions
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import Server from "arrpc";
|
import Server from "arrpc";
|
||||||
|
import { IpcEvents } from "shared/IpcEvents";
|
||||||
|
|
||||||
import { mainWin } from "./mainWindow";
|
import { mainWin } from "./mainWindow";
|
||||||
import { Settings } from "./settings";
|
import { Settings } from "./settings";
|
||||||
|
@ -17,11 +18,8 @@ export async function initArRPC() {
|
||||||
if (server || !Settings.store.arRPC) return;
|
if (server || !Settings.store.arRPC) return;
|
||||||
|
|
||||||
try {
|
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 = 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) => {
|
server.on("invite", (invite: string, callback: (valid: boolean) => void) => {
|
||||||
invite = String(invite);
|
invite = String(invite);
|
||||||
if (!inviteCodeRegex.test(invite)) return callback(false);
|
if (!inviteCodeRegex.test(invite)) return callback(false);
|
||||||
|
|
|
@ -65,5 +65,10 @@ export const VesktopNative = {
|
||||||
list: () => invoke<string[] | null>(IpcEvents.VIRT_MIC_LIST),
|
list: () => invoke<string[] | null>(IpcEvents.VIRT_MIC_LIST),
|
||||||
start: (target: string) => invoke<void>(IpcEvents.VIRT_MIC_START, target),
|
start: (target: string) => invoke<void>(IpcEvents.VIRT_MIC_START, target),
|
||||||
kill: () => invoke<void>(IpcEvents.VIRT_MIC_KILL)
|
kill: () => invoke<void>(IpcEvents.VIRT_MIC_KILL)
|
||||||
|
},
|
||||||
|
arrpc: {
|
||||||
|
onActivity(cb: (data: string) => void) {
|
||||||
|
ipcRenderer.on(IpcEvents.ARRPC_ACTIVITY, (_, data: string) => cb(data));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -47,14 +47,12 @@ customSettingsSections.push(() => ({
|
||||||
className: "vc-vesktop-settings"
|
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.handleEvent(new MessageEvent("message", { data }));
|
||||||
arRPC.required = !!v;
|
|
||||||
if (v && !arRPC.started) Vencord.Plugins.startPlugin(arRPC);
|
|
||||||
else if (arRPC.started) {
|
|
||||||
Vencord.Plugins.stopPlugin(arRPC);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -44,5 +44,7 @@ export const enum IpcEvents {
|
||||||
|
|
||||||
VIRT_MIC_LIST = "VCD_VIRT_MIC_LIST",
|
VIRT_MIC_LIST = "VCD_VIRT_MIC_LIST",
|
||||||
VIRT_MIC_START = "VCD_VIRT_MIC_START",
|
VIRT_MIC_START = "VCD_VIRT_MIC_START",
|
||||||
VIRT_MIC_KILL = "VCD_VIRT_MIC_STOP"
|
VIRT_MIC_KILL = "VCD_VIRT_MIC_STOP",
|
||||||
|
|
||||||
|
ARRPC_ACTIVITY = "VCD_ARRPC_ACTIVITY"
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue