From b7d40b35560584c7e86cccd753bd572a0061c9da Mon Sep 17 00:00:00 2001 From: Kylie C Date: Tue, 20 Aug 2024 15:43:46 -0400 Subject: [PATCH] support OBS auto streamer mode via an arrpc patch --- patches/arrpc@3.4.0.patch | 52 +++++++++++++++++++++++++--- scripts/build/build.mts | 8 +++++ src/renderer/index.ts | 12 +++++-- src/renderer/patches/index.ts | 1 + src/renderer/patches/streamerMode.ts | 20 +++++++++++ 5 files changed, 86 insertions(+), 7 deletions(-) create mode 100644 src/renderer/patches/streamerMode.ts diff --git a/patches/arrpc@3.4.0.patch b/patches/arrpc@3.4.0.patch index 8dfd9f6..68fb28a 100644 --- a/patches/arrpc@3.4.0.patch +++ b/patches/arrpc@3.4.0.patch @@ -1,14 +1,58 @@ diff --git a/src/process/index.js b/src/process/index.js -index 97ea6514b54dd9c5df588c78f0397d31ab5f882a..c2bdbd6aaa5611bc6ff1d993beeb380b1f5ec575 100644 +index 97ea651..28f0eb5 100644 --- a/src/process/index.js +++ b/src/process/index.js -@@ -5,8 +5,7 @@ import fs from 'node:fs'; - import { dirname, join } from 'path'; - import { fileURLToPath } from 'url'; +@@ -1,12 +1,7 @@ + const rgb = (r, g, b, msg) => `\x1b[38;2;${r};${g};${b}m${msg}\x1b[0m`; + const log = (...args) => console.log(`[${rgb(88, 101, 242, 'arRPC')} > ${rgb(237, 66, 69, 'process')}]`, ...args); +-import fs from 'node:fs'; +-import { dirname, join } from 'path'; +-import { fileURLToPath } from 'url'; +- -const __dirname = dirname(fileURLToPath(import.meta.url)); -const DetectableDB = JSON.parse(fs.readFileSync(join(__dirname, 'detectable.json'), 'utf8')); +const DetectableDB = require('./detectable.json'); import * as Natives from './native/index.js'; const Native = Natives[process.platform]; +@@ -38,7 +33,7 @@ export default class ProcessServer { + const path = _path.toLowerCase().replaceAll('\\', '/'); + const toCompare = []; + const splitPath = path.split('/'); +- for (let i = 1; i < splitPath.length; i++) { ++ for (let i = 0; i < splitPath.length; i++) { + toCompare.push(splitPath.slice(-i).join('/')); + } + +diff --git a/update_db.js b/update_db.js +index ed94923..3170685 100644 +--- a/update_db.js ++++ b/update_db.js +@@ -1,5 +1,5 @@ + #!/usr/bin/env node +-import { createWriteStream, readFileSync } from 'fs'; ++import { createWriteStream, readFileSync, writeFileSync} from 'fs'; + import { get } from 'https'; + + import { dirname, join } from 'path'; +@@ -25,5 +25,21 @@ get('https://discord.com/api/v9/applications/detectable', res => { + const oldNames = current.map(x => x.name); + const newNames = updated.map(x => x.name); + console.log(newNames.filter(x => !oldNames.includes(x))); ++ ++ // append obs for auto streammode ++ updated.push({ ++ aliases: ["Obs"], ++ executables: [ ++ { is_launcher: false, name: "obs", os: "linux" }, ++ { is_launcher: false, name: "obs.exe", os: "win32" }, ++ { is_launcher: false, name: "obs.app", os: "darwin" } ++ ], ++ hook: true, ++ id: "STREAMERMODE", ++ name: "OBS" ++ }); ++ writeFileSync(path, JSON.stringify(updated), 'utf8'); + }) + }); diff --git a/scripts/build/build.mts b/scripts/build/build.mts index 243381b..ebb40d0 100644 --- a/scripts/build/build.mts +++ b/scripts/build/build.mts @@ -4,6 +4,7 @@ * Copyright (c) 2023 Vendicated and Vencord contributors */ +import { execSync } from "child_process"; import { BuildContext, BuildOptions, context } from "esbuild"; import { copyFile } from "fs/promises"; @@ -49,8 +50,15 @@ async function copyVenmic() { ]).catch(() => console.warn("Failed to copy venmic. Building without venmic support")); } +async function updateArrpcDb() { + return Promise.all([execSync("node node_modules/arrpc/update_db.js")]).catch(() => + console.warn("Error running update_db.js Auto streamermode will not work.") + ); +} + await Promise.all([ copyVenmic(), + updateArrpcDb(), createContext({ ...NodeCommonOpts, entryPoints: ["src/main/index.ts"], diff --git a/src/renderer/index.ts b/src/renderer/index.ts index e8ad31c..9af3b21 100644 --- a/src/renderer/index.ts +++ b/src/renderer/index.ts @@ -12,7 +12,7 @@ import "./themedSplash"; console.log("read if cute :3"); export * as Components from "./components"; -import { findByPropsLazy, onceReady } from "@vencord/types/webpack"; +import { findByPropsLazy, findStore, onceReady } from "@vencord/types/webpack"; import { Alerts, FluxDispatcher } from "@vencord/types/webpack/common"; import SettingsUi from "./components/settings/Settings"; @@ -56,8 +56,14 @@ VesktopNative.arrpc.onActivity(async data => { if (!Settings.store.arRPC) return; await onceReady; - - arRPC.handleEvent(new MessageEvent("message", { data })); + const StreamerModeStore = findStore("StreamerModeStore"); + if (JSON.parse(data).socketId === "STREAMERMODE" && StreamerModeStore.autoToggle) { + FluxDispatcher.dispatch({ + type: "STREAMER_MODE_UPDATE", + key: "enabled", + value: JSON.parse(data).activity?.application_id === "STREAMERMODE" + }); + } else arRPC.handleEvent(new MessageEvent("message", { data })); }); // TODO: remove soon diff --git a/src/renderer/patches/index.ts b/src/renderer/patches/index.ts index aabff3e..6e5c912 100644 --- a/src/renderer/patches/index.ts +++ b/src/renderer/patches/index.ts @@ -12,3 +12,4 @@ import "./hideVenmicInput"; import "./screenShareFixes"; import "./spellCheck"; import "./windowsTitleBar"; +import "./streamerMode"; diff --git a/src/renderer/patches/streamerMode.ts b/src/renderer/patches/streamerMode.ts new file mode 100644 index 0000000..10bcc84 --- /dev/null +++ b/src/renderer/patches/streamerMode.ts @@ -0,0 +1,20 @@ +/* + * SPDX-License-Identifier: GPL-3.0 + * Vesktop, a desktop app aiming to give you a snappier Discord Experience + * Copyright (c) 2023 Vendicated and Vencord contributors + */ + +import { addPatch } from "./shared"; + +addPatch({ + patches: [ + { + find: ".STREAMER_MODE_ENABLE,", + replacement: { + // eslint-disable-next-line no-useless-escape + match: /\i\.isPlatformEmbedded/g, + replace: "true" + } + } + ] +});