Refactored to use fifo pipe
This commit is contained in:
		
							parent
							
								
									e8b1cbd030
								
							
						
					
					
						commit
						a3eea96bb1
					
				
					 3 changed files with 33 additions and 9 deletions
				
			
		|  | @ -4,17 +4,38 @@ | |||
|  * Copyright (c) 2023 Vendicated and Vencord contributors | ||||
|  */ | ||||
| 
 | ||||
| import child_process from "node:child_process"; | ||||
| import fs from "node:fs"; | ||||
| import path from "node:path"; | ||||
| 
 | ||||
| import net from "net"; | ||||
| import { IpcEvents } from "shared/IpcEvents"; | ||||
| 
 | ||||
| import { mainWin } from "./mainWindow"; | ||||
| 
 | ||||
| export function initKeybinds() { | ||||
|     process.title = "Vesktop"; | ||||
|     process.on("SIGPIPE", async () => { | ||||
|         mainWin.webContents.send(IpcEvents.TOGGLE_SELF_MUTE); | ||||
|     }); | ||||
| const xdgRuntimeDir = process.env.XDG_RUNTIME_DIR || process.env.TMP || "/tmp"; | ||||
| const socketFile = path.join(xdgRuntimeDir, "vesktop-ipc"); | ||||
| 
 | ||||
|     process.on("SIGUSR2", () => { | ||||
|         mainWin.webContents.send(IpcEvents.TOGGLE_SELF_DEAF); | ||||
| export function initKeybinds() { | ||||
|     child_process.spawnSync("mkfifo", [socketFile]); | ||||
|     fs.open(socketFile, fs.constants.O_RDONLY | fs.constants.O_NONBLOCK, (err, fd) => { | ||||
|         if (err) { | ||||
|             console.error("Error opening pipe:", err); | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         const pipe = new net.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); | ||||
|             } | ||||
|         }); | ||||
| 
 | ||||
|         pipe.on("end", () => { | ||||
|             pipe.destroy(); | ||||
|             initKeybinds(); | ||||
|         }); | ||||
|     }); | ||||
| } | ||||
|  |  | |||
|  | @ -468,6 +468,7 @@ const runVencordMain = once(() => require(join(VENCORD_FILES_DIR, "vencordDeskto | |||
| export async function createWindows() { | ||||
|     const startMinimized = process.argv.includes("--start-minimized"); | ||||
|     const splash = createSplashWindow(startMinimized); | ||||
|     process.title = "Vesktop"; | ||||
|     // SteamOS letterboxes and scales it terribly, so just full screen it
 | ||||
|     if (isDeckGameMode) splash.setFullScreen(true); | ||||
|     await ensureVencordFiles(); | ||||
|  |  | |||
|  | @ -60,10 +60,12 @@ VesktopNative.arrpc.onActivity(async data => { | |||
|     arRPC.handleEvent(new MessageEvent("message", { data })); | ||||
| }); | ||||
| 
 | ||||
| const VoiceActions = findByPropsLazy("toggleSelfMute"); | ||||
| 
 | ||||
| VesktopNative.voice.onToggleSelfMute(() => { | ||||
|     findByPropsLazy("toggleSelfMute").toggleSelfMute(); | ||||
|     VoiceActions.toggleSelfMute(); | ||||
| }); | ||||
| 
 | ||||
| VesktopNative.voice.onToggleSelfDeaf(() => { | ||||
|     findByPropsLazy("toggleSelfDeaf").toggleSelfDeaf(); | ||||
|     VoiceActions.toggleSelfDeaf(); | ||||
| }); | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue
	
	 Oleh Polisan
						Oleh Polisan