diff --git a/package.json b/package.json index 0441e88..e71324c 100644 --- a/package.json +++ b/package.json @@ -82,11 +82,11 @@ "mac": { "target": [ { - "target": "default", - "arch": [ - "x64", - "arm64" - ] + "target": "default", + "arch": [ + "x64", + "arm64" + ] } ], "category": "Network" @@ -105,5 +105,8 @@ "provider": "github", "releaseType": "release" } + }, + "dependencies": { + "arrpc": "^3.1.0" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5492c22..22b617d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,5 +1,10 @@ lockfileVersion: '6.0' +dependencies: + arrpc: + specifier: ^3.1.0 + version: 3.1.0 + devDependencies: '@fal-works/esbuild-plugin-global-externals': specifier: ^2.1.2 @@ -889,6 +894,15 @@ packages: es-shim-unscopables: 1.0.0 dev: true + /arrpc@3.1.0: + resolution: {integrity: sha512-QKagtB5fUDqDXT31tTUzcG3+rFxsMlrjKb3iE68/b2NbT1c6+0WYkkrJh4GaVPqH0Tlqy13sEgPW3XJ/VNmBDQ==} + dependencies: + ws: 8.13.0 + transitivePeerDependencies: + - bufferutil + - utf-8-validate + dev: false + /asar@3.2.0: resolution: {integrity: sha512-COdw2ZQvKdFGFxXwX3oYh2/sOsJWJegrdJCGxnN4MZ7IULgRBp9P6665aqj9z1v9VwP4oP1hRBojRDQ//IGgAg==} engines: {node: '>=10.12.0'} @@ -3785,6 +3799,19 @@ packages: resolution: {integrity: sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==} dev: true + /ws@8.13.0: + resolution: {integrity: sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA==} + engines: {node: '>=10.0.0'} + peerDependencies: + bufferutil: ^4.0.1 + utf-8-validate: '>=5.0.2' + peerDependenciesMeta: + bufferutil: + optional: true + utf-8-validate: + optional: true + dev: false + /xmlbuilder@15.1.1: resolution: {integrity: sha512-yMqGBqtXyeN1e3TGYvgNgDVZ3j84W4cwkOXQswghol6APgZWaff9lnbvN7MHYJOiXsvGPXtjTYJEiC9J2wv9Eg==} engines: {node: '>=8.0'} diff --git a/src/main/arrpc.ts b/src/main/arrpc.ts new file mode 100644 index 0000000..9ea348d --- /dev/null +++ b/src/main/arrpc.ts @@ -0,0 +1,21 @@ +/* + * SPDX-License-Identifier: GPL-3.0 + * Vencord Desktop, a desktop app aiming to give you a snappier Discord Experience + * Copyright (c) 2023 Vendicated and Vencord contributors + */ + +import Server from "arrpc"; +import { send as sendToBridge } from "arrpc/src/bridge"; + +import { Settings } from "./settings"; + +let server: any; + +export async function initArRPC() { + if (server || !Settings.store.arRPC) return; + + server = await new Server(); + server.on("activity", sendToBridge); +} + +Settings.addChangeListener("arRPC", initArRPC); diff --git a/src/main/index.ts b/src/main/index.ts index 4827664..4101a96 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -12,6 +12,7 @@ import { checkUpdates } from "updater/main"; import { ICON_PATH } from "../shared/paths"; import { once } from "../shared/utils/once"; +import { initArRPC } from "./arrpc"; import { DATA_DIR, VENCORD_FILES_DIR } from "./constants"; import { createMainWindow } from "./mainWindow"; import { Settings } from "./settings"; @@ -94,6 +95,8 @@ async function createWindows() { mainWin!.maximize(); } }); + + initArRPC(); } app.on("window-all-closed", () => { diff --git a/src/renderer/components/Settings.tsx b/src/renderer/components/Settings.tsx index 13f46a3..adb5dc6 100644 --- a/src/renderer/components/Settings.tsx +++ b/src/renderer/components/Settings.tsx @@ -22,6 +22,7 @@ export default function SettingsUi() { true, () => Settings.tray ?? true ], + ["arRPC", "Rich Presence", "Enables Rich Presence via arRPC", false], [ "disableMinSize", "Disable minimum window size", diff --git a/src/renderer/index.ts b/src/renderer/index.ts index c2c76ca..8d1442d 100644 --- a/src/renderer/index.ts +++ b/src/renderer/index.ts @@ -9,4 +9,17 @@ import "./fixes"; console.log("read if cute :3"); export * as Components from "./components"; -export { Settings } from "./settings"; +import { Settings } from "./settings"; +export { Settings }; + +const arRPC = Vencord.Plugins.plugins["WebRichPresence (arRPC)"]; + +arRPC.required = !!Settings.store.arRPC; + +Settings.addChangeListener("arRPC", v => { + arRPC.required = !!v; + if (v && !arRPC.started) Vencord.Plugins.startPlugin(arRPC); + else if (arRPC.started) { + Vencord.Plugins.stopPlugin(arRPC); + } +}); diff --git a/src/shared/settings.d.ts b/src/shared/settings.d.ts index 14d1ec7..1b3fb49 100644 --- a/src/shared/settings.d.ts +++ b/src/shared/settings.d.ts @@ -18,4 +18,5 @@ export interface Settings { minimizeToTray?: boolean; skippedUpdate?: string; staticTitle?: boolean; + arRPC?: boolean; }