fix(desktop): pause background IPC polls when window is hidden (#1079) - #2130
Open
xielixing wants to merge 1 commit into
Open
fix(desktop): pause background IPC polls when window is hidden (#1079)#2130xielixing wants to merge 1 commit into
xielixing wants to merge 1 commit into
Conversation
…und CPU Gate DispatchJobObserver (1800ms), CodeEditor/MarkdownEditor (1000ms file-sync), and BackgroundCommandOutputPanel (1000ms) polls on document.visibilityState so they stop issuing Tauri IPC round-trips when the app is backgrounded. Fixes GCWing#1079
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
Gate frontend polling intervals on
document.visibilityStateso IPC round-trips stop when the app window is backgrounded, eliminating the WebView2 subprocess CPU spike described in #1079.Root Cause
Several frontend pollers run unconditionally for the entire app lifetime, issuing Tauri IPC calls even when the window is hidden and idle:
DispatchJobObserverdispatch_list_jobs+ 1×dispatch_statusper jobCodeEditorfile-syncMarkdownEditorfile-syncBackgroundCommandOutputPanelNone checked
document.visibilityState, so WebView2 kept processing IPC round-trips at full rate while backgrounded.Fix
run()whenvisibilityState === 'hidden'. Thevisibilitychangelistener now clears the poll interval when hidden and restarts it when visible.tick()when hidden.tick()when hidden.Using
document.visibilityState === 'hidden'instead ofdocument.hiddenfor consistency and testability (jsdom does not synchiddenwithvisibilityState).Validation
tsc --noEmit— cleanvitest run DispatchJobObserver.test.ts— 30/30 tests pass (2 new tests added: pause-when-hidden + resume-when-visible)Fixes #1079