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,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]);
|
||||||
|
|||||||
Reference in New Issue
Block a user