fix: Pause and resume PerformanceHudView with lifecycle#1463
Conversation
Integrates the PerformanceHudView with the screen's lifecycle to automatically pause its updates when the screen is in the background (ON_PAUSE) and resume them when it returns to the foreground (ON_RESUME). This change conserves resources and prevents unnecessary activity when the application is not actively displayed.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds pause/resume methods to PerformanceHudView that gate its metric-update loop and wires those methods to XServerScreen lifecycle events so the HUD is paused on ON_PAUSE and resumed on ON_RESUME. ChangesPerformance HUD Pause/Resume Lifecycle Control
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@app/src/main/java/app/gamenative/ui/screen/xserver/XServerScreen.kt`:
- Around line 1471-1494: The LifecycleEventObserver registered inside
DisposableEffect (involving performanceHudView, lifecycleOwner and observer)
only reacts to future ON_PAUSE/ON_RESUME events; to fix, immediately inspect
lifecycleOwner.lifecycle.currentState after creating hud and call hud.pause() if
state.isAtLeast(Lifecycle.State.STARTED) is false (or call hud.resume() if state
is resumed/started) so the HUD is synchronized with the current lifecycle; keep
the existing observer registration and onDispose removal and ensure you only
call pause()/resume() when hud is non-null.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: e811883a-cacc-4323-b17d-ec8e70e5a2cd
📒 Files selected for processing (2)
app/src/main/java/app/gamenative/ui/screen/xserver/XServerScreen.ktapp/src/main/java/app/gamenative/ui/widget/PerformanceHudView.kt
There was a problem hiding this comment.
1 issue found across 2 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Description
Integrates the PerformanceHudView with the screen's lifecycle to automatically pause its updates when the screen is in the background (ON_PAUSE) and resume them when it returns to the foreground (ON_RESUME).
This change conserves resources and prevents unnecessary activity when the application is not actively displayed.
Recording
None
Type of Change
Checklist
#code-changes, I have discussed this change there and it has been green-lighted. If I do not have access, I have still provided clear context in this PR. If I skip both, I accept that this change may face delays in review, may not be reviewed at all, or may be closed.CONTRIBUTING.md.Summary by cubic
Pause
PerformanceHudViewwhen the screen goes to the background and resume it on return to foreground to cut unnecessary updates and save resources.DisposableEffectandLifecycleEventObserver(pause on ON_PAUSE, resume on ON_RESUME) and synced the initial state with the current lifecycle.pause()/resume()with anisPausedflag; guardedstartUpdates()inonAttachedToWindow; removed the observer on dispose.Written for commit a54c8cd. Summary will update on new commits. Review in cubic
Summary by CodeRabbit