add logging, move actions to top level
This commit is contained in:
parent
0157b85ae1
commit
08a9b60803
1 changed files with 28 additions and 17 deletions
|
@ -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;
|
||||
}
|
||||
try {
|
||||
spawnSync("mkfifo", [socketFile]);
|
||||
} catch (err) {
|
||||
console.log("Failed to create mkfifo while initializing keybinds:", 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 {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue