Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Toggle voice status using fifo pipe #609

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/main/keybinds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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 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";

const xdgRuntimeDir = process.env.XDG_RUNTIME_DIR || process.env.TMP || "/tmp";
const socketFile = path.join(xdgRuntimeDir, "vesktop-ipc");

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();
});
});
}
4 changes: 4 additions & 0 deletions src/main/mainWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import {
MIN_WIDTH,
VENCORD_FILES_DIR
} from "./constants";
import { initKeybinds } from "./keybinds";
import { isWayland } from "./screenShare";
import { Settings, State, VencordSettings } from "./settings";
import { createSplashWindow } from "./splash";
import { makeLinksOpenExternally } from "./utils/makeLinksOpenExternally";
Expand Down Expand Up @@ -467,6 +469,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();
Expand Down Expand Up @@ -497,4 +500,5 @@ export async function createWindows() {
});

initArRPC();
if (isWayland) initKeybinds();
}
2 changes: 1 addition & 1 deletion src/main/screenShare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { IpcEvents } from "shared/IpcEvents";

import { handle } from "./utils/ipcWrappers";

const isWayland =
export const isWayland =
process.platform === "linux" && (process.env.XDG_SESSION_TYPE === "wayland" || !!process.env.WAYLAND_DISPLAY);

export function registerScreenShareHandler() {
Expand Down
8 changes: 8 additions & 0 deletions src/preload/VesktopNative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,13 @@ export const VesktopNative = {
clipboard: {
copyImage: (imageBuffer: Uint8Array, imageSrc: string) =>
invoke<void>(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);
}
}
};
10 changes: 10 additions & 0 deletions src/renderer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,13 @@ VesktopNative.arrpc.onActivity(async data => {

arRPC.handleEvent(new MessageEvent("message", { data }));
});

const VoiceActions = findByPropsLazy("toggleSelfMute");

VesktopNative.voice.onToggleSelfMute(() => {
VoiceActions.toggleSelfMute();
});

VesktopNative.voice.onToggleSelfDeaf(() => {
VoiceActions.toggleSelfDeaf();
});
4 changes: 3 additions & 1 deletion src/shared/IpcEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Loading