Skip to content

Pause useNowTicker while the panel WebView is hidden #488

@zergzorg

Description

@zergzorg

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions