[codex] Pause ticker while panel is hidden#490
Conversation
|
Stack note for maintainers/agents: This PR is independent from the #487 probe-resource stack. It belongs to #488 and only reduces UI-only ticker work while the panel WebView is hidden. Suggested merge position: merge anytime. It can land before or after #498/#499/#500 because it does not change probe scheduling, backend probe execution, or provider runtime behavior. |
|
@codex review |
There was a problem hiding this comment.
Pull request overview
This PR updates the useNowTicker React hook to be visibility-aware by default, pausing interval updates while document.hidden is true and forcing an immediate refresh when the document becomes visible again. This reduces unnecessary UI timer work when the Tauri panel WebView is hidden, while preserving an opt-out (pauseWhenHidden: false) for callers that need the prior behavior.
Changes:
- Add
pauseWhenHiddenoption (defaulttrue) and avisibilitychangelistener to pause/resume ticking based on document visibility. - Trigger an immediate
nowrefresh on visibility resume (before the next interval tick). - Extend Vitest coverage for initially hidden documents, pause/resume behavior, and opt-out behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/hooks/use-now-ticker.ts | Adds visibility-aware pause/resume logic and a new pauseWhenHidden option to reduce hidden-panel interval work. |
| src/hooks/use-now-ticker.test.ts | Adds tests for hidden/visible transitions and opt-out behavior for the visibility-aware ticker. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2c0614ee81
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
2c0614e to
be7d219
Compare
|
Addressed the review feedback in the latest push:
Verified locally with |
robinebers
left a comment
There was a problem hiding this comment.
LGTM. Display-only ticker change — no impact on app self-update checks (useAppUpdate own setInterval), plugin auto-refresh (useProbeAutoUpdate own setInterval), or tray icon updates (useTrayIcon is probe-result-driven). macOS App Nap is already disabled in app_nap.rs so background timers keep firing while the panel is hidden. Tests are solid, both bot-review nits addressed in commit 2.
Summary
useNowTickerintervals whiledocument.hiddenis true by defaultnowimmediately when the document becomes visible again, before the next interval tickWhy
useNowTickerdrives display-only UI such as countdowns and relative timestamps. When the menu panel WebView is hidden, those React timer updates do not change visible UI but can still wake the app. Pausing the ticker while hidden reduces idle UI work without changing provider probes or background refresh scheduling.This addresses #488 and complements the broader resource-budget discussion in #487.
Notes
The default behavior is visibility-aware, but callers can keep the old hidden ticking behavior with
pauseWhenHidden: falseif a future use case needs it.Validation
node ./node_modules/vitest/vitest.mjs run src/hooks/use-now-ticker.test.tsbun run buildnode ./node_modules/vitest/vitest.mjs runThe full Vitest run passes. Existing tests print Tauri store mock stderr in
App.test.tsx, but the suite exits successfully.Summary by cubic
Pause
useNowTickerticks while the document is hidden to reduce idle updates, and resume with an immediate refresh when it becomes visible. Adds apauseWhenHiddenoption (default true), respectsenabledon visibility changes (no refresh when disabled), and tests for initial hidden state, pause/resume, disabled behavior, and opt‑out.Written for commit be7d219. Summary will update on new commits. Review in cubic