Refactored to use fifo pipe
This commit is contained in:
parent
e8b1cbd030
commit
a3eea96bb1
3 changed files with 33 additions and 9 deletions
|
@ -4,17 +4,38 @@
|
||||||
* Copyright (c) 2023 Vendicated and Vencord contributors
|
* 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 { IpcEvents } from "shared/IpcEvents";
|
||||||
|
|
||||||
import { mainWin } from "./mainWindow";
|
import { mainWin } from "./mainWindow";
|
||||||
|
|
||||||
export function initKeybinds() {
|
const xdgRuntimeDir = process.env.XDG_RUNTIME_DIR || process.env.TMP || "/tmp";
|
||||||
process.title = "Vesktop";
|
const socketFile = path.join(xdgRuntimeDir, "vesktop-ipc");
|
||||||
process.on("SIGPIPE", async () => {
|
|
||||||
mainWin.webContents.send(IpcEvents.TOGGLE_SELF_MUTE);
|
|
||||||
});
|
|
||||||
|
|
||||||
process.on("SIGUSR2", () => {
|
export function initKeybinds() {
|
||||||
mainWin.webContents.send(IpcEvents.TOGGLE_SELF_DEAF);
|
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();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -468,6 +468,7 @@ const runVencordMain = once(() => require(join(VENCORD_FILES_DIR, "vencordDeskto
|
||||||
export async function createWindows() {
|
export async function createWindows() {
|
||||||
const startMinimized = process.argv.includes("--start-minimized");
|
const startMinimized = process.argv.includes("--start-minimized");
|
||||||
const splash = createSplashWindow(startMinimized);
|
const splash = createSplashWindow(startMinimized);
|
||||||
|
process.title = "Vesktop";
|
||||||
// SteamOS letterboxes and scales it terribly, so just full screen it
|
// SteamOS letterboxes and scales it terribly, so just full screen it
|
||||||
if (isDeckGameMode) splash.setFullScreen(true);
|
if (isDeckGameMode) splash.setFullScreen(true);
|
||||||
await ensureVencordFiles();
|
await ensureVencordFiles();
|
||||||
|
|
|
@ -60,10 +60,12 @@ VesktopNative.arrpc.onActivity(async data => {
|
||||||
arRPC.handleEvent(new MessageEvent("message", { data }));
|
arRPC.handleEvent(new MessageEvent("message", { data }));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const VoiceActions = findByPropsLazy("toggleSelfMute");
|
||||||
|
|
||||||
VesktopNative.voice.onToggleSelfMute(() => {
|
VesktopNative.voice.onToggleSelfMute(() => {
|
||||||
findByPropsLazy("toggleSelfMute").toggleSelfMute();
|
VoiceActions.toggleSelfMute();
|
||||||
});
|
});
|
||||||
|
|
||||||
VesktopNative.voice.onToggleSelfDeaf(() => {
|
VesktopNative.voice.onToggleSelfDeaf(() => {
|
||||||
findByPropsLazy("toggleSelfDeaf").toggleSelfDeaf();
|
VoiceActions.toggleSelfDeaf();
|
||||||
});
|
});
|
||||||
|
|
Reference in a new issue