Skip to content

fix(desktop): pause background IPC polls when window is hidden (#1079) - #2130

Open
xielixing wants to merge 1 commit into
GCWing:mainfrom
xielixing:fix/issue-1079-cpu-spike
Open

fix(desktop): pause background IPC polls when window is hidden (#1079)#2130
xielixing wants to merge 1 commit into
GCWing:mainfrom
xielixing:fix/issue-1079-cpu-spike

Conversation

@xielixing

Copy link
Copy Markdown

Summary

Gate frontend polling intervals on document.visibilityState so 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:

Poller Interval IPC calls per poll
DispatchJobObserver 1800 ms dispatch_list_jobs + 1× dispatch_status per job
CodeEditor file-sync 1000 ms file modification check
MarkdownEditor file-sync 1000 ms file modification check
BackgroundCommandOutputPanel 1000 ms background command output read

None checked document.visibilityState, so WebView2 kept processing IPC round-trips at full rate while backgrounded.

Fix

  • DispatchJobObserver.ts: Early-return in run() when visibilityState === 'hidden'. The visibilitychange listener now clears the poll interval when hidden and restarts it when visible.
  • CodeEditor.tsx: Early-return in tick() when hidden.
  • MarkdownEditor.tsx: Early-return in tick() when hidden.
  • BackgroundCommandOutputPanel.tsx: Early-return in interval callback when hidden.

Using document.visibilityState === 'hidden' instead of document.hidden for consistency and testability (jsdom does not sync hidden with visibilityState).

Validation

  • tsc --noEmit — clean
  • vitest run DispatchJobObserver.test.ts — 30/30 tests pass (2 new tests added: pause-when-hidden + resume-when-visible)

Fixes #1079

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

【bug】 任务在不执行时, 挂载APP在后台, 会有异常线程导致cpu占用飙升

1 participant