From 29c12dc034fd01e2c3a5b3cbaa1166da637cdad0 Mon Sep 17 00:00:00 2001 From: Oleh Polisan Date: Sat, 18 May 2024 00:41:36 +0300 Subject: [PATCH] Added ability to toggle voice using proc signals --- src/main/keybinds.ts | 19 +++++++++++++++++++ src/main/mainWindow.ts | 2 ++ src/preload/VesktopNative.ts | 8 ++++++++ src/renderer/index.ts | 8 ++++++++ src/shared/IpcEvents.ts | 4 +++- 5 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/main/keybinds.ts diff --git a/src/main/keybinds.ts b/src/main/keybinds.ts new file mode 100644 index 0000000..1a8b578 --- /dev/null +++ b/src/main/keybinds.ts @@ -0,0 +1,19 @@ +/* + * 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 { IpcEvents } from "shared/IpcEvents"; + +import { mainWin } from "./mainWindow"; + +export function initKeybinds() { + process.on("SIGPIPE", async () => { + mainWin.webContents.send(IpcEvents.TOGGLE_SELF_MUTE); + }); + + process.on("SIGUSR2", () => { + mainWin.webContents.send(IpcEvents.TOGGLE_SELF_DEAF); + }); +} diff --git a/src/main/mainWindow.ts b/src/main/mainWindow.ts index 3ee1fd0..020b4f1 100644 --- a/src/main/mainWindow.ts +++ b/src/main/mainWindow.ts @@ -35,6 +35,7 @@ import { MIN_WIDTH, VENCORD_FILES_DIR } from "./constants"; +import { initKeybinds } from "./keybinds"; import { Settings, State, VencordSettings } from "./settings"; import { createSplashWindow } from "./splash"; import { makeLinksOpenExternally } from "./utils/makeLinksOpenExternally"; @@ -481,4 +482,5 @@ export async function createWindows() { }); initArRPC(); + initKeybinds(); } diff --git a/src/preload/VesktopNative.ts b/src/preload/VesktopNative.ts index 184b095..119c193 100644 --- a/src/preload/VesktopNative.ts +++ b/src/preload/VesktopNative.ts @@ -78,5 +78,13 @@ export const VesktopNative = { clipboard: { copyImage: (imageBuffer: Uint8Array, imageSrc: string) => invoke(IpcEvents.CLIPBOARD_COPY_IMAGE, imageBuffer, imageSrc) + }, + voice: { + onToggleSelfMute: (listener: (...args: any[]) => void) => { + ipcRenderer.on(IpcEvents.TOGGLE_SELF_MUTE, listener); + }, + onToggleSelfDeaf: (listener: (...args: any[]) => void) => { + ipcRenderer.on(IpcEvents.TOGGLE_SELF_DEAF, listener); + } } }; diff --git a/src/renderer/index.ts b/src/renderer/index.ts index 1ccc2e4..485edd1 100644 --- a/src/renderer/index.ts +++ b/src/renderer/index.ts @@ -57,3 +57,11 @@ VesktopNative.arrpc.onActivity(data => { arRPC.handleEvent(new MessageEvent("message", { data })); }); + +VesktopNative.voice.onToggleSelfMute(() => { + findByPropsLazy("toggleSelfMute").toggleSelfMute(); +}); + +VesktopNative.voice.onToggleSelfDeaf(() => { + findByPropsLazy("toggleSelfDeaf").toggleSelfDeaf(); +}); diff --git a/src/shared/IpcEvents.ts b/src/shared/IpcEvents.ts index df64403..5a53602 100644 --- a/src/shared/IpcEvents.ts +++ b/src/shared/IpcEvents.ts @@ -49,5 +49,7 @@ export const enum IpcEvents { ARRPC_ACTIVITY = "VCD_ARRPC_ACTIVITY", - CLIPBOARD_COPY_IMAGE = "VCD_CLIPBOARD_COPY_IMAGE" + CLIPBOARD_COPY_IMAGE = "VCD_CLIPBOARD_COPY_IMAGE", + TOGGLE_SELF_MUTE = "VCD_TOGGLE_SELF_MUTE", + TOGGLE_SELF_DEAF = "VCD_TOGGLE_SELF_DEAF" }