support OBS auto streamer mode via an arrpc patch

This commit is contained in:
Kylie C 2024-08-20 15:43:46 -04:00
parent af9ed58eef
commit b7d40b3556
5 changed files with 86 additions and 7 deletions

View file

@ -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');
})
});

View file

@ -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"],

View file

@ -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

View file

@ -12,3 +12,4 @@ import "./hideVenmicInput";
import "./screenShareFixes";
import "./spellCheck";
import "./windowsTitleBar";
import "./streamerMode";

View file

@ -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"
}
}
]
});