Problem
useNowTicker drives UI-only time labels such as relative timestamps and short cooldown/countdown text. Today those timers can keep React waking up even when the Tauri panel WebView is hidden.
OpenUsage intentionally keeps background refreshes working on macOS, so this is not about re-enabling App Nap or stopping provider probes. The narrow target is to avoid running display-only React intervals while there is no visible panel to update.
This is a small, separable frontend optimization that complements #487.
Proposed change
Add visibility-aware pausing to useNowTicker:
- default to pausing the interval when
document.hidden === true
- resume and refresh
now on visibilitychange when the panel becomes visible again
- keep an escape hatch such as
pauseWhenHidden: false for any caller that truly needs ticking while hidden
- keep the existing
enabled, intervalMs, stopAfterMs, and resetKey behavior intact
Candidate scope:
src/hooks/use-now-ticker.ts
src/hooks/use-now-ticker.test.ts
Why this helps
The app currently has UI timers that are useful while the menu panel is open, but do not add value while the panel is hidden. Pausing them reduces idle wakeups and React state updates without changing provider refresh frequency or user-visible data freshness.
Acceptance criteria
useNowTicker does not start/continue its interval while document.hidden is true by default.
- The hook updates immediately after
visibilitychange makes the document visible again.
- Existing disabled and
stopAfterMs behavior remains covered by tests.
- A caller can opt out with
pauseWhenHidden: false.
- No changes to provider probe scheduling or background refresh behavior.
Test plan
- Add/extend hook tests covering hidden document pause and visible resume.
- Run the focused test file, for example:
vitest run src/hooks/use-now-ticker.test.ts
- Run the regular app build/test command used by the project before opening a PR.
Problem
useNowTickerdrives UI-only time labels such as relative timestamps and short cooldown/countdown text. Today those timers can keep React waking up even when the Tauri panel WebView is hidden.OpenUsage intentionally keeps background refreshes working on macOS, so this is not about re-enabling App Nap or stopping provider probes. The narrow target is to avoid running display-only React intervals while there is no visible panel to update.
This is a small, separable frontend optimization that complements #487.
Proposed change
Add visibility-aware pausing to
useNowTicker:document.hidden === truenowonvisibilitychangewhen the panel becomes visible againpauseWhenHidden: falsefor any caller that truly needs ticking while hiddenenabled,intervalMs,stopAfterMs, andresetKeybehavior intactCandidate scope:
src/hooks/use-now-ticker.tssrc/hooks/use-now-ticker.test.tsWhy this helps
The app currently has UI timers that are useful while the menu panel is open, but do not add value while the panel is hidden. Pausing them reduces idle wakeups and React state updates without changing provider refresh frequency or user-visible data freshness.
Acceptance criteria
useNowTickerdoes not start/continue its interval whiledocument.hiddenis true by default.visibilitychangemakes the document visible again.stopAfterMsbehavior remains covered by tests.pauseWhenHidden: false.Test plan