| | |
| | | <script lang="ts"> |
| | | import { onDestroy } from 'svelte' |
| | | import { Call } from '@wailsio/runtime' |
| | | import ToggleSwitch from '../shared/ToggleSwitch.svelte' |
| | | import { t } from '../../lib/i18n' |
| | |
| | | let hintText = $state('') |
| | | let devices = $state<InputDevice[]>([]) |
| | | let showDeviceDropdown = $state(false) |
| | | let activeKeyHandler: ((e: KeyboardEvent) => void) | null = null |
| | | |
| | | const unsub1 = autoHide.subscribe(v => { autoHideVal = v }) |
| | | const unsub2 = startAtLogin.subscribe(v => { startAtLoginVal = v }) |
| | |
| | | const unsub7 = soundFeedback.subscribe(v => { soundFeedbackVal = v }) |
| | | const unsub8 = copyToClipboard.subscribe(v => { copyToClipboardVal = v }) |
| | | const unsub9 = hotkeyMode.subscribe(v => { hotkeyModeVal = v }) |
| | | |
| | | onDestroy(() => { |
| | | unsub1(); unsub2(); unsub3(); unsub4(); unsub5(); unsub6(); unsub7(); unsub8(); unsub9() |
| | | clearHotkeyCapture() |
| | | }) |
| | | |
| | | // Load actual device name from backend on mount |
| | | async function loadDeviceName() { |
| | |
| | | } |
| | | |
| | | async function startRecordingHotkey() { |
| | | clearHotkeyCapture() |
| | | isRecording = true |
| | | hintText = t('hotkeys.pressAnyKey') |
| | | |
| | |
| | | } catch {} |
| | | })() |
| | | |
| | | document.removeEventListener('keydown', onKey) |
| | | clearHotkeyCapture() |
| | | } |
| | | } |
| | | |
| | | activeKeyHandler = onKey |
| | | document.addEventListener('keydown', onKey) |
| | | } |
| | | |
| | | function clearHotkeyCapture() { |
| | | if (activeKeyHandler) { |
| | | document.removeEventListener('keydown', activeKeyHandler) |
| | | activeKeyHandler = null |
| | | } |
| | | if (isRecording) { |
| | | isRecording = false |
| | | void Call.ByName('voicesnap/services.HotkeyService.StopRecordingHotkey').catch(() => {}) |
| | | } |
| | | } |
| | | |
| | | function mapKeyToVK(e: KeyboardEvent): number { |
| | | switch (e.key) { |
| | | case 'Control': return e.location === 1 ? 0xA2 : e.location === 2 ? 0xA3 : 0x11 |