feat: auto-stop recording on application focus loss (opt-in)#342
Open
hanselstner wants to merge 1 commit intoOpenWhispr:mainfrom
Open
feat: auto-stop recording on application focus loss (opt-in)#342hanselstner wants to merge 1 commit intoOpenWhispr:mainfrom
hanselstner wants to merge 1 commit intoOpenWhispr:mainfrom
Conversation
When dictating into a text field and switching to another application (e.g. clicking into a browser or IDE), the recording is automatically cancelled to prevent stale audio from being transcribed and pasted into the wrong window. This feature is opt-in and disabled by default. Users can enable it in Settings > General > Dictation Behavior > "Stop when switching apps". Implementation details: - Add FocusWatcher (src/helpers/focusWatcher.js) that polls the foreground window handle on Windows via a lightweight PowerShell script (resources/get-foreground-pid.ps1). When the handle changes, a "focus-changed" event is emitted. - On focus loss during recording, the main process sends a "cancel-dictation" IPC event to discard the audio instead of transcribing it (transcribing would paste into the now-focused app). - Add "blur-main-window" IPC handler so clicking the overlay stop button returns focus to the previously active application. - Prevent Chromium renderer throttling on Windows via disable-renderer-backgrounding and disable-background-timer-throttling so the dictation overlay animations keep running while unfocused. - Change setAlwaysOnTop level from pop-up-menu to floating on Windows to prevent the overlay from stealing focus. - Guard show/focus enforceMainWindowOnTop calls behind a platform check to avoid repeated focus grabs on Windows. - Add stopOnFocusLoss setting (default: false) with full i18n support across all 10 languages.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an opt-in setting to automatically stop (cancel) recording when the user switches away from the application that was focused when recording started. This prevents accidental long recordings when multitasking.
Changes
Core feature
src/helpers/focusWatcher.js(new): PowerShell-based window focus monitor that polls the foreground window PID and firesfocus-lost/focus-restoredeventsresources/get-foreground-pid.ps1(new): Minimal PowerShell script usinguser32.dllP/Invoke to get the foreground window's process IDmain.js: Integrate FocusWatcher lifecycle — start on recording, stop on idle, forwardfocus-lostevents to renderersrc/hooks/useAudioRecording.js: Listen forfocus-lostIPC events and cancel recording with an audio cuepreload.js: ExposeonFocusLost/offFocusLostIPC channelsSettings UI
src/hooks/useSettings.ts: AddstopOnFocusLosssetting (default:false)src/components/SettingsPage.tsx: Add toggle under Dictation Behavior sectionstopOnFocusLossandstopOnFocusLossDescriptiontranslationsWindow management
src/helpers/windowConfig.js: Usefloatingwindow level instead ofpop-up-menuon Windows to prevent focus stealingelectron-builder.json: Includeget-foreground-pid.ps1inextraResourcesTest plan
false(off) for new installationsPull Request opened by Augment Code with guidance from the PR author