forked from Vencord/Vesktop
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(voiceglobalkeybinds): add PR Vencord#609
- Loading branch information
1 parent
6a842b4
commit d376248
Showing
8 changed files
with
102 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* 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 { spawnSync } from "node:child_process"; | ||
import { constants, existsSync, open, unlinkSync } from "node:fs"; | ||
import { join } from "node:path"; | ||
|
||
import { Socket } from "net"; | ||
import { IpcEvents } from "shared/IpcEvents"; | ||
|
||
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]); | ||
|
||
function createFIFO() { | ||
if (existsSync(socketFile)) { | ||
try { | ||
unlinkSync(socketFile); | ||
} catch (err) { | ||
console.error("Failed to remove existing mkfifo file:", err); | ||
return false; | ||
} | ||
} | ||
|
||
try { | ||
spawnSync("mkfifo", [socketFile]); | ||
} catch (err) { | ||
console.error("Failed to create mkfifo while initializing keybinds:", err); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
function openFIFO() { | ||
try { | ||
open(socketFile, constants.O_RDONLY | constants.O_NONBLOCK, (err, fd) => { | ||
if (err) { | ||
console.error("Error opening pipe while initializing keybinds:", err); | ||
return; | ||
} | ||
|
||
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.on("end", () => { | ||
pipe.destroy(); | ||
openFIFO(); | ||
}); | ||
}); | ||
} catch (err) { | ||
console.error("Can't open socket file.", err); | ||
} | ||
} | ||
|
||
function cleanup() { | ||
try { | ||
unlinkSync(socketFile); | ||
} catch (err) { | ||
console.error("Failed to remove mkfifo file:", err); | ||
} | ||
} | ||
|
||
process.on("exit", cleanup); | ||
|
||
export function initKeybinds() { | ||
if (createFIFO()) { | ||
openFIFO(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters