1j01 / tracky-mouse

Mouse control via head tracking, as a cross platform desktop app and JS library. eViacam alternative.
https://trackymouse.js.org/
MIT License
25 stars 4 forks source link

Global shortcut stops working if I reload the electron window with Ctrl+R #2

Closed 1j01 closed 1 year ago

1j01 commented 1 year ago

mainWindow.webContents.send("shortcut-register-result", success); only happens once in the app's lifetime, and in the renderer process, it looks for window.shortcutRegisterSuccess before attempting to listen for the global shortcut:

    if (window.onShortcut && window.shortcutRegisterSuccess) {
        window.onShortcut(handleShortcut);
    } else {
        addEventListener("keydown", (event) => {
            // Same shortcut as the global shortcut in the electron app (is that gonna be a problem?)
            if (!event.ctrlKey && !event.metaKey && !event.altKey && !event.shiftKey && event.key === "F9") {
                handleShortcut("toggle-tracking");
            }
        });
    }

If the page is reloaded, it doesn't get shortcutRegisterSuccess and so the shortcut no longer works — not even within the app, with the keydown listener, because it's intercepted globally.

This is only a problem during development.