fix: voice-mode pref toggle-off now stops the recognizer (#1491)

When a user disables 'Hands-free voice mode' in Settings while voice
mode is active, the button hides but the SpeechRecognition keeps
running — the user can't stop it because the button is invisible.

Fix: _applyVoiceModePref() now checks if voice mode is active and
calls _deactivate() when the pref is toggled off. Move
_voiceModeActive declaration above the function to avoid TDZ.

Also removes a duplicate window._applyVoiceModePref assignment.
This commit is contained in:
Frank Song
2026-05-03 15:03:17 +08:00
parent 7921a47f9d
commit f32989d5bb
+5 -2
View File
@@ -470,14 +470,17 @@ window._micPendingSend=window._micPendingSend||false;
try{ return localStorage.getItem('hermes-voice-mode-button')==='true'; }
catch(_){ return false; }
}
let _voiceModeActive=false;
function _applyVoiceModePref(){
modeBtn.style.display = _voiceModePrefEnabled() ? '' : 'none';
const enabled = _voiceModePrefEnabled();
modeBtn.style.display = enabled ? '' : 'none';
if(!enabled && _voiceModeActive) _deactivate();
}
_applyVoiceModePref();
// Expose so the settings pane can re-apply immediately on toggle.
window._applyVoiceModePref = _applyVoiceModePref;
let _voiceModeActive=false;
let _voiceModeState='idle'; // idle | listening | thinking | speaking
let _recognition=null;
let _silenceTimer=null;