add logging, move actions to top level

This commit is contained in:
Oleh Polisan 2024-06-02 00:42:21 +03:00
parent 0157b85ae1
commit 08a9b60803

View file

@ -16,26 +16,37 @@ import { mainWin } from "./mainWindow";
const xdgRuntimeDir = process.env.XDG_RUNTIME_DIR || process.env.TMP || "/tmp"; const xdgRuntimeDir = process.env.XDG_RUNTIME_DIR || process.env.TMP || "/tmp";
const socketFile = join(xdgRuntimeDir, "vesktop-ipc"); const socketFile = join(xdgRuntimeDir, "vesktop-ipc");
const Actions = new Set([IpcEvents.TOGGLE_SELF_DEAF, IpcEvents.TOGGLE_SELF_MUTE]);
export function initKeybinds() { export function initKeybinds() {
spawnSync("mkfifo", [socketFile]); try {
open(socketFile, constants.O_RDONLY | constants.O_NONBLOCK, (err, fd) => { spawnSync("mkfifo", [socketFile]);
if (err) { } catch (err) {
console.error("Error opening pipe:", err); console.log("Failed to create mkfifo while initializing keybinds:", err);
return; return;
} }
const pipe = new Socket({ fd }); try {
pipe.on("data", data => { open(socketFile, constants.O_RDONLY | constants.O_NONBLOCK, (err, fd) => {
const Actions = new Set([IpcEvents.TOGGLE_SELF_DEAF, IpcEvents.TOGGLE_SELF_MUTE]); if (err) {
const action = data.toString().trim(); console.error("Error opening pipe while initializing keybinds:", err);
if (Actions.has(action as IpcEvents)) { return;
mainWin.webContents.send(action);
} }
});
pipe.once("end", () => { const pipe = new Socket({ fd });
pipe.destroy(); pipe.on("data", data => {
initKeybinds(); const action = data.toString().trim();
if (Actions.has(action as IpcEvents)) {
mainWin.webContents.send(action);
}
});
pipe.once("end", () => {
pipe.destroy();
initKeybinds();
});
}); });
}); } catch (err) {
console.log("Can't open socket file.", err);
}
} }