fix(captures): use platform hotkey defaults

This commit is contained in:
Jamie Pine
2026-04-25 10:28:34 -07:00
parent 29f99a8622
commit 2a1bb6f936
8 changed files with 77 additions and 20 deletions
@@ -30,7 +30,7 @@ import { useProfiles } from '@/lib/hooks/useProfiles';
import { usePlatform } from '@/platform/PlatformContext';
import { useServerStore } from '@/stores/serverStore';
import { cn } from '@/lib/utils/cn';
import { displayLabelForKey, modifierSideHint } from '@/lib/utils/keyCodes';
import { defaultChordKeys, displayLabelForKey, modifierSideHint } from '@/lib/utils/keyCodes';
import type { Qwen3ModelSize, VoiceProfileResponse, WhisperModelSize } from '@/lib/api/types';
import { SettingRow, SettingSection } from './SettingRow';
@@ -135,8 +135,8 @@ export function CapturesPage() {
const allowAutoPaste = settings?.allow_auto_paste ?? true;
const defaultVoiceId = settings?.default_playback_voice_id ?? null;
const hotkeyEnabled = settings?.hotkey_enabled ?? false;
const pushToTalkKeys = settings?.chord_push_to_talk_keys ?? ['MetaRight', 'AltGr'];
const toggleToTalkKeys = settings?.chord_toggle_to_talk_keys ?? ['MetaRight', 'AltGr', 'Space'];
const pushToTalkKeys = settings?.chord_push_to_talk_keys ?? defaultChordKeys('push');
const toggleToTalkKeys = settings?.chord_toggle_to_talk_keys ?? defaultChordKeys('toggle');
// Mock-only settings — not yet wired to a backend. Keep local so the UI
// still responds while Phase 7 (hotkey / clipboard / paste) catches up.
+2 -2
View File
@@ -213,9 +213,9 @@ export interface CaptureSettings {
/** Whether the global keyboard hotkey is armed. Off by default — turning
* this on triggers the macOS Input Monitoring TCC prompt. */
hotkey_enabled: boolean;
/** rdev::Key variant names. Defaults: ["MetaRight","AltGr"]. */
/** keytap key names. Defaults are platform-specific right-hand modifiers. */
chord_push_to_talk_keys: string[];
/** rdev::Key variant names. Defaults: ["MetaRight","AltGr","Space"]. */
/** keytap key names. Toggle adds Space to the platform-specific PTT chord. */
chord_toggle_to_talk_keys: string[];
}
+12 -5
View File
@@ -1,13 +1,13 @@
/**
* Stable key-name vocabulary shared with the Rust `key_codes` module.
*
* The chord persistence layer stores rdev `Key` variant names ("MetaRight",
* The chord persistence layer stores keytap `Key` variant names ("MetaRight",
* "AltGr", "KeyA", …) so the same array round-trips losslessly between
* the picker UI, the SQLite settings row, and the global hotkey listener.
*
* This module owns the conversions between three vocabularies:
* - browser `KeyboardEvent` (`event.code` like "MetaRight" / "AltRight")
* - canonical chord key names (matches rdev variants)
* - canonical chord key names (matches keytap variants)
* - human display labels ("⌘", "⌥", "A", …)
*/
@@ -16,8 +16,8 @@
* `null` for keys we don't support in chords (dead keys, IME composition,
* etc.).
*
* Browser quirk: right-Option on macOS is reported as `"AltRight"`; rdev
* calls it `"AltGr"`. Normalize to rdev's name so the Rust side recognizes
* Browser quirk: right-Option on macOS is reported as `"AltRight"`; keytap
* calls it `"AltGr"`. Normalize to keytap's name so the Rust side recognizes
* it without an aliasing layer.
*/
export function canonicalKeyFromEvent(event: KeyboardEvent): string | null {
@@ -53,7 +53,7 @@ export function canonicalKeyFromEvent(event: KeyboardEvent): string | null {
default:
// Browser names like "MetaRight", "MetaLeft", "ControlLeft",
// "ShiftRight", "Space", "KeyA", "Digit1", "F5" all match the
// rdev variant names directly.
// keytap variant names directly.
if (
/^(Meta|Control|Shift)(Left|Right)$/.test(code) ||
/^Key[A-Z]$/.test(code) ||
@@ -72,6 +72,13 @@ export function canonicalKeyFromEvent(event: KeyboardEvent): string | null {
const PLATFORM_IS_MAC =
typeof navigator !== 'undefined' && /mac/i.test(navigator.platform);
export function defaultChordKeys(mode: 'push' | 'toggle'): string[] {
const base = PLATFORM_IS_MAC
? ['MetaRight', 'AltGr']
: ['ControlRight', 'ShiftRight'];
return mode === 'toggle' ? [...base, 'Space'] : base;
}
/**
* Pretty label for a canonical key name. Picks platform-appropriate
* modifier glyphs so macOS users see ⌘ and Windows/Linux users see Win.