diff --git a/src/main/index.ts b/src/main/index.ts index 9d6a52c..60e536b 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -47,8 +47,12 @@ function init() { // In the Flatpak on SteamOS the theme is detected as light, but SteamOS only has a dark mode, so we just override it if (isDeckGameMode) nativeTheme.themeSource = "dark"; - app.on("second-instance", (_event, _cmdLine, _cwd, data: any) => { - if (data.IS_DEV) app.quit(); + app.on("second-instance", (_event, cmdLine, _cwd, data: any) => { + const keybindIndex = cmdLine.indexOf("--keybind"); + + if (keybindIndex !== -1) { + mainWin.webContents.executeJavaScript(`Vesktop.keybindCallbacks[${cmdLine[keybindIndex + 1]}](false)`); + } else if (data.IS_DEV) app.quit(); else if (mainWin) { if (mainWin.isMinimized()) mainWin.restore(); if (!mainWin.isVisible()) mainWin.show(); @@ -72,15 +76,24 @@ function init() { } if (!app.requestSingleInstanceLock({ IS_DEV })) { - if (IS_DEV) { - console.log("Vesktop is already running. Quitting previous instance..."); - init(); - } else { - console.log("Vesktop is already running. Quitting..."); + if (process.argv.includes("--keybind")) { app.quit(); + } else { + if (IS_DEV) { + console.log("Vesktop is already running. Quitting previous instance..."); + init(); + } else { + console.log("Vesktop is already running. Quitting..."); + app.quit(); + } } } else { - init(); + if (process.argv.includes("--keybind")) { + console.error("No instances running! cannot issue a keybind!"); + app.quit(); + } else { + init(); + } } async function bootstrap() { diff --git a/src/main/ipc.ts b/src/main/ipc.ts index 71dd512..fb6dd44 100644 --- a/src/main/ipc.ts +++ b/src/main/ipc.ts @@ -7,17 +7,7 @@ if (process.platform === "linux") import("./venmic"); import { execFile } from "child_process"; -import { - app, - BrowserWindow, - clipboard, - dialog, - globalShortcut, - nativeImage, - RelaunchOptions, - session, - shell -} from "electron"; +import { app, BrowserWindow, clipboard, dialog, nativeImage, RelaunchOptions, session, shell } from "electron"; import { mkdirSync, readFileSync, watch } from "fs"; import { open, readFile } from "fs/promises"; import { release } from "os"; @@ -143,15 +133,11 @@ handle(IpcEvents.CLIPBOARD_COPY_IMAGE, async (_, buf: ArrayBuffer, src: string) const registered_keybinds = {}; handle(IpcEvents.KEYBIND_REGISTER, (_, id: number, shortcut: string, options: any) => { - globalShortcut.register(shortcut, () => { - // false here implies `keyup` - // electron's global shortcut system doesn't really register keyup or down as far as i can tell - mainWin.webContents.executeJavaScript(`Vesktop.keybindCallbacks[${id}](false)`); - }); registered_keybinds[id] = shortcut; + console.log(registered_keybinds); }); handle(IpcEvents.KEYBIND_UNREGISTER, (_, id: number) => { - globalShortcut.unregister(registered_keybinds[id]); + delete registered_keybinds[id]; }); function readCss() { diff --git a/src/preload/VesktopNative.ts b/src/preload/VesktopNative.ts index 01af5cb..ba69f0d 100644 --- a/src/preload/VesktopNative.ts +++ b/src/preload/VesktopNative.ts @@ -79,6 +79,6 @@ export const VesktopNative = { keybind: { register: (id: number, shortcut: string, options: any) => invoke(IpcEvents.KEYBIND_REGISTER, id, shortcut), - uregister: (id: number) => invoke(IpcEvents.KEYBIND_UNREGISTER, id) + unregister: (id: number) => invoke(IpcEvents.KEYBIND_UNREGISTER, id) } }; diff --git a/src/renderer/patches/keybinds.ts b/src/renderer/patches/keybinds.ts index d159b57..717113b 100644 --- a/src/renderer/patches/keybinds.ts +++ b/src/renderer/patches/keybinds.ts @@ -50,6 +50,6 @@ addPatch({ }, unregisterKeybind: function (id) { delete keybindCallbacks[id]; - VesktopNative.keybind.uregister(id); + VesktopNative.keybind.unregister(id); } });