fix: deduplicate keybind actions when native hook and web fallback both fire

When the app is focused and the native uiohook hook is active, both the
IPC bridge and the web fallback capture the same keypress, dispatching
the toggle action twice (~0-20ms apart). This double-toggles mute/deafen
back to the original state.

Add a 100ms dedup window in dispatchKeybindAction to suppress the second
dispatch. Safe for human input (key repeat starts at ~500ms).
This commit is contained in:
Jannis Braun
2026-03-22 23:55:59 +01:00
parent 4532cc6708
commit 100ac15939
+8
View File
@@ -27,8 +27,16 @@ function getSpaceEnforcementState(): { isSpaceMuted: boolean; isSpaceDeafened: b
};
}
/** Dedup rapid duplicate dispatches (native hook + web fallback both fire when focused) */
const lastDispatch: Record<string, number> = {};
/** Dispatch a keybind action to the appropriate voice handler */
function dispatchKeybindAction(actionId: string, pressed: boolean): void {
const now = Date.now();
const key = `${actionId}:${pressed}`;
if (now - (lastDispatch[key] || 0) < 100) return;
lastDispatch[key] = now;
const voice = useVoiceStore.getState();
if (!voice.currentVoiceChannelId) return;