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:
@@ -198,12 +198,15 @@ export function useKeybinds(): void {
|
||||
}
|
||||
}, [keybinds, currentVoiceChannelId]);
|
||||
|
||||
// --- Electron: IPC bridge ---
|
||||
// --- Keybind listeners (Electron IPC or web capture-phase fallback) ---
|
||||
useEffect(() => {
|
||||
if (!isElectron()) return;
|
||||
const api = window.backspace;
|
||||
if (!api?.syncKeybinds || !api?.onKeybindAction) 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,
|
||||
@@ -215,13 +218,11 @@ export function useKeybinds(): void {
|
||||
});
|
||||
|
||||
return cleanup;
|
||||
}, [keybinds]);
|
||||
|
||||
// --- Web fallback: capture-phase listeners ---
|
||||
useEffect(() => {
|
||||
if (isElectron()) return;
|
||||
if (keybinds.length === 0) return;
|
||||
}
|
||||
// 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);
|
||||
return cleanup ?? undefined;
|
||||
}, [keybinds]);
|
||||
|
||||
Reference in New Issue
Block a user