diff --git a/src/main/keybinds.ts b/src/main/keybinds.ts index 242f098..5289cae 100644 --- a/src/main/keybinds.ts +++ b/src/main/keybinds.ts @@ -4,17 +4,38 @@ * Copyright (c) 2023 Vendicated and Vencord contributors */ +import child_process from "node:child_process"; +import fs from "node:fs"; +import path from "node:path"; + +import net from "net"; import { IpcEvents } from "shared/IpcEvents"; import { mainWin } from "./mainWindow"; -export function initKeybinds() { - process.title = "Vesktop"; - process.on("SIGPIPE", async () => { - mainWin.webContents.send(IpcEvents.TOGGLE_SELF_MUTE); - }); +const xdgRuntimeDir = process.env.XDG_RUNTIME_DIR || process.env.TMP || "/tmp"; +const socketFile = path.join(xdgRuntimeDir, "vesktop-ipc"); - process.on("SIGUSR2", () => { - mainWin.webContents.send(IpcEvents.TOGGLE_SELF_DEAF); +export function initKeybinds() { + child_process.spawnSync("mkfifo", [socketFile]); + fs.open(socketFile, fs.constants.O_RDONLY | fs.constants.O_NONBLOCK, (err, fd) => { + if (err) { + console.error("Error opening pipe:", err); + return; + } + + const pipe = new net.Socket({ fd }); + pipe.on("data", data => { + const Actions = new Set([IpcEvents.TOGGLE_SELF_DEAF, IpcEvents.TOGGLE_SELF_MUTE]); + const action = data.toString().trim(); + if (Actions.has(action as IpcEvents)) { + mainWin.webContents.send(action); + } + }); + + pipe.on("end", () => { + pipe.destroy(); + initKeybinds(); + }); }); } diff --git a/src/main/mainWindow.ts b/src/main/mainWindow.ts index 65c3677..cdde947 100644 --- a/src/main/mainWindow.ts +++ b/src/main/mainWindow.ts @@ -468,6 +468,7 @@ const runVencordMain = once(() => require(join(VENCORD_FILES_DIR, "vencordDeskto export async function createWindows() { const startMinimized = process.argv.includes("--start-minimized"); const splash = createSplashWindow(startMinimized); + process.title = "Vesktop"; // SteamOS letterboxes and scales it terribly, so just full screen it if (isDeckGameMode) splash.setFullScreen(true); await ensureVencordFiles(); diff --git a/src/renderer/index.ts b/src/renderer/index.ts index 03f7397..a0b3c1f 100644 --- a/src/renderer/index.ts +++ b/src/renderer/index.ts @@ -60,10 +60,12 @@ VesktopNative.arrpc.onActivity(async data => { arRPC.handleEvent(new MessageEvent("message", { data })); }); +const VoiceActions = findByPropsLazy("toggleSelfMute"); + VesktopNative.voice.onToggleSelfMute(() => { - findByPropsLazy("toggleSelfMute").toggleSelfMute(); + VoiceActions.toggleSelfMute(); }); VesktopNative.voice.onToggleSelfDeaf(() => { - findByPropsLazy("toggleSelfDeaf").toggleSelfDeaf(); + VoiceActions.toggleSelfDeaf(); });