From 9748a036b6d34fe5f0ea2849bdac4d35c5b16809 Mon Sep 17 00:00:00 2001 From: Tuxinal <24763016+tuxinal@users.noreply.github.com> Date: Sat, 11 May 2024 19:53:43 +0330 Subject: [PATCH] Add keyup/keydown support for the cli TEMPORARY: show keybind ID in the keybind page --- src/main/index.ts | 8 +++++++- src/main/ipc.ts | 1 - src/renderer/patches/keybinds.ts | 10 ++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/index.ts b/src/main/index.ts index bfca49a..2569d40 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -63,7 +63,13 @@ function init() { const keybindIndex = cmdLine.indexOf("--keybind"); if (keybindIndex !== -1) { - mainWin.webContents.executeJavaScript(`Vesktop.keybindCallbacks[${cmdLine[keybindIndex + 1]}](false)`); + if (cmdLine[keybindIndex + 2] === "keyup" || cmdLine[keybindIndex + 2] === "keydown") { + mainWin.webContents.executeJavaScript( + `Vesktop.keybindCallbacks[${cmdLine[keybindIndex + 1]}](${cmdLine[keybindIndex + 2] === "keydown" ? "true" : "false"})` + ); + } else { + mainWin.webContents.executeJavaScript(`Vesktop.keybindCallbacks[${cmdLine[keybindIndex + 1]}](false)`); + } } else if (data.IS_DEV) app.quit(); else if (mainWin) { if (mainWin.isMinimized()) mainWin.restore(); diff --git a/src/main/ipc.ts b/src/main/ipc.ts index fb6dd44..4166c6d 100644 --- a/src/main/ipc.ts +++ b/src/main/ipc.ts @@ -134,7 +134,6 @@ const registered_keybinds = {}; handle(IpcEvents.KEYBIND_REGISTER, (_, id: number, shortcut: string, options: any) => { registered_keybinds[id] = shortcut; - console.log(registered_keybinds); }); handle(IpcEvents.KEYBIND_UNREGISTER, (_, id: number) => { delete registered_keybinds[id]; diff --git a/src/renderer/patches/keybinds.ts b/src/renderer/patches/keybinds.ts index 717113b..6ba1f90 100644 --- a/src/renderer/patches/keybinds.ts +++ b/src/renderer/patches/keybinds.ts @@ -22,8 +22,14 @@ addPatch({ }, { // eslint-disable-next-line no-useless-escape - match: /\(0,\i.isDesktop\)\(\)/g, + match: /\(0,\i\.isDesktop\)\(\)/g, replace: "true" + }, + { + // THIS PATCH IS TEMPORARY + // eslint-disable-next-line no-useless-escape + match: /\.keybindGroup,\i.card\),children:\[/g, + replace: "$&`ID: ${this.props.keybind.id}`," } ] }, @@ -37,7 +43,7 @@ addPatch({ }, { // eslint-disable-next-line no-useless-escape - match: /inputEventUnregister\((parseInt\(\i,10\))\);else\{/, + match: /inputEventUnregister\((parseInt\(\i,10\))\);else if\(\i\[\i\]\)\{/, replace: "$&$self.unregisterKeybind($1);return;" } ]