From 5fbe9789faf05ce99bbff6ec4cd0b905519acbd0 Mon Sep 17 00:00:00 2001
From: Ariver <shanghai3168@gmail.com>
Date: Fri, 03 Jul 2026 05:18:07 +0800
Subject: [PATCH] Freeze R221 2.2.2 source baseline

---
 C1.source/privatevoice.src/frontend/src/components/settings/HotkeysPage.svelte |   22 +++++++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletions(-)

diff --git a/C1.source/privatevoice.src/frontend/src/components/settings/HotkeysPage.svelte b/C1.source/privatevoice.src/frontend/src/components/settings/HotkeysPage.svelte
index acb3aaa..4efaa6a 100755
--- a/C1.source/privatevoice.src/frontend/src/components/settings/HotkeysPage.svelte
+++ b/C1.source/privatevoice.src/frontend/src/components/settings/HotkeysPage.svelte
@@ -1,4 +1,5 @@
 <script lang="ts">
+  import { onDestroy } from 'svelte'
   import { Call } from '@wailsio/runtime'
   import { t } from '../../lib/i18n'
   import { hotkeyVK } from '../../lib/stores/config'
@@ -7,10 +8,17 @@
   let currentKeyName = $state('Ctrl')
   let isRecording = $state(false)
   let hintText = $state('')
+  let activeKeyHandler: ((e: KeyboardEvent) => void) | null = null
 
   const unsub = hotkeyName.subscribe(k => { currentKeyName = k })
 
+  onDestroy(() => {
+    unsub()
+    clearHotkeyCapture()
+  })
+
   async function startRecordingHotkey() {
+    clearHotkeyCapture()
     isRecording = true
     hintText = t('hotkeys.pressAnyKey')
 
@@ -44,13 +52,25 @@
           } 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 {
     // Map browser key codes to Windows VK codes
     switch (e.key) {

--
Gitblit v1.9.3