Repository navigation
Pause the animated background while the window is unfocused - #153
Merged
Merged
Conversation
WebKitGTK keeps document.hidden false and fires rAF at vblank rate when the desktop window is on another workspace or covered, so the Waves/Particles loop and the Aurora CSS animation never stopped (~33% CPU measured on Linux with the window out of sight). Run the canvas loop only while the document is visible and focused, and pause Aurora's animation under the same rule. Fixes #151 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Fixes #151.
What
AnimatedBackground.sveltestopped animating only whendocument.hiddenwas true. In the Tauri/WebKitGTK shell that never happens for a window on another workspace or behind other windows, and WebKit keeps firingrequestAnimationFrameat vblank rate. So the backdrop kept rendering while nobody could see it. On Linux, with the window out of sight, that measured about 33% CPU across the UI process, the web process and the compositor.Now the background animates only while the document is visible and focused:
!document.hidden && document.hasFocus().focusandblurrestart or stop it, alongsidevisibilitychange. On blur, the current frame is drawn and the loop stops. On focus, it resumes where it left off.pausedclass setsanimation-play-state: pausedon the blobs under the same rule.Trade-off: a window that is visible but unfocused (tiled side by side, for example) shows a still backdrop until it's focused. This matches how reduced motion already freezes it, and fits the "keep the UI calm" convention.
Verification
npm testpasses (252 tests) andnpm run checkreports 0 errors.Ran the dev build in headless Chromium through Playwright, faking
document.hasFocus()and dispatchingblur/focus:animation-play-state)I haven't tested this in the real Linux desktop build, where the focus events come from GTK. To check: switch workspaces, and
top -Hon the WebKitWebProcess should show its main thread andThreadedCompositornear 0%.🤖 Generated with Claude Code