This repository has been archived on 2025-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
project-client/src/main/keybinds.ts
2024-05-24 16:57:19 +03:00

41 lines
1.2 KiB
TypeScript

/*
* 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();
});
});
}