From 08a9b60803eb607c8e9b7b019adc9a617f02f055 Mon Sep 17 00:00:00 2001 From: Oleh Polisan Date: Sun, 2 Jun 2024 00:42:21 +0300 Subject: [PATCH] add logging, move actions to top level --- src/main/keybinds.ts | 47 +++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/src/main/keybinds.ts b/src/main/keybinds.ts index d722bdfb..3a157657 100644 --- a/src/main/keybinds.ts +++ b/src/main/keybinds.ts @@ -16,26 +16,37 @@ import { mainWin } from "./mainWindow"; const xdgRuntimeDir = process.env.XDG_RUNTIME_DIR || process.env.TMP || "/tmp"; const socketFile = join(xdgRuntimeDir, "vesktop-ipc"); +const Actions = new Set([IpcEvents.TOGGLE_SELF_DEAF, IpcEvents.TOGGLE_SELF_MUTE]); + export function initKeybinds() { - spawnSync("mkfifo", [socketFile]); - open(socketFile, constants.O_RDONLY | constants.O_NONBLOCK, (err, fd) => { - if (err) { - console.error("Error opening pipe:", err); - return; - } - - const pipe = new 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); + try { + spawnSync("mkfifo", [socketFile]); + } catch (err) { + console.log("Failed to create mkfifo while initializing keybinds:", err); + return; + } + + try { + open(socketFile, constants.O_RDONLY | constants.O_NONBLOCK, (err, fd) => { + if (err) { + console.error("Error opening pipe while initializing keybinds:", err); + return; } - }); - pipe.once("end", () => { - pipe.destroy(); - initKeybinds(); + const pipe = new Socket({ fd }); + pipe.on("data", data => { + 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); + } }