fix: fall back to web keybind listeners when Electron lacks keybind APIs

When running in Electron but the desktop app hasn't been rebuilt with
keybind support (no syncKeybinds/onKeybindAction in preload), the hook
now falls through to the web capture-phase listener instead of silently
doing nothing. This ensures keybinds work immediately on the web-served
UI regardless of the desktop app version.
This commit is contained in:
Jannis Braun
2026-03-22 21:36:05 +01:00
parent 5554b1abc7
commit 39ee894d77
+22 -21
View File
@@ -198,30 +198,31 @@ export function useKeybinds(): void {
} }
}, [keybinds, currentVoiceChannelId]); }, [keybinds, currentVoiceChannelId]);
// --- Electron: IPC bridge --- // --- Keybind listeners (Electron IPC or web capture-phase fallback) ---
useEffect(() => { useEffect(() => {
if (!isElectron()) return;
const api = window.backspace;
if (!api?.syncKeybinds || !api?.onKeybindAction) return;
api.syncKeybinds(keybinds.map((kb) => ({
actionId: kb.actionId,
keys: kb.keys,
mouseButton: kb.mouseButton,
})));
const cleanup = api.onKeybindAction((action) => {
dispatchKeybindAction(action.actionId, action.pressed);
});
return cleanup;
}, [keybinds]);
// --- Web fallback: capture-phase listeners ---
useEffect(() => {
if (isElectron()) return;
if (keybinds.length === 0) return; if (keybinds.length === 0) return;
// Try Electron IPC bridge first (requires rebuilt desktop app with keybind support)
if (isElectron()) {
const api = window.backspace;
if (api?.syncKeybinds && api?.onKeybindAction) {
// Desktop app has keybind support — use OS-level global shortcuts
api.syncKeybinds(keybinds.map((kb) => ({
actionId: kb.actionId,
keys: kb.keys,
mouseButton: kb.mouseButton,
})));
const cleanup = api.onKeybindAction((action) => {
dispatchKeybindAction(action.actionId, action.pressed);
});
return cleanup;
}
// Desktop app lacks keybind APIs (old build) — fall through to web fallback
}
// Web fallback: capture-phase listeners (works when tab/window is focused)
const cleanup = setupWebFallback(keybindsRef); const cleanup = setupWebFallback(keybindsRef);
return cleanup ?? undefined; return cleanup ?? undefined;
}, [keybinds]); }, [keybinds]);