Skip to content

Commit

Permalink
add logging, move actions to top level
Browse files Browse the repository at this point in the history
  • Loading branch information
PolisanTheEasyNick committed Jun 1, 2024
1 parent 0157b85 commit 08a9b60
Showing 1 changed file with 29 additions and 18 deletions.
47 changes: 29 additions & 18 deletions src/main/keybinds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 08a9b60

Please sign in to comment.