mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-08-04 13:51:50 +00:00
Energy (field report: ~3x Chrome drain): - polls skip entirely while the window is hidden/minimized, with one catch-up refresh on return when data is stale; visible-but-unfocused keeps polling (second-monitor case) - all looping animations pause under html.page-hidden (the sidebar flame flicker was a perpetual compositor drain) - default cadence 60s; an explicit stored choice is always honored Currency (field report: set USD, still saw EUR): - memo-served payloads re-applied their embedded stale currency; config mutations now purge the renderer memo and force-refresh, and a switching payload can never overwrite the applied currency - USD default verified end to end Measured: hidden window = 0 new CLI spawns over 5 cadences (was: full polling forever). App 340/340, build + package green.
15 lines
711 B
TypeScript
15 lines
711 B
TypeScript
/**
|
|
* Reflect document visibility onto <html> as the `page-hidden` class so CSS can
|
|
* pause looping animations (the sidebar flame flicker, shimmers) while the window
|
|
* is minimized/occluded — see plain.css. Applies the current state immediately and
|
|
* returns a disposer. Safe when `document` is absent (SSR/tests without jsdom).
|
|
*/
|
|
export function installPageHiddenClass(): () => void {
|
|
if (typeof document === 'undefined') return () => {}
|
|
const sync = () => {
|
|
document.documentElement.classList.toggle('page-hidden', document.visibilityState === 'hidden')
|
|
}
|
|
sync()
|
|
document.addEventListener('visibilitychange', sync)
|
|
return () => document.removeEventListener('visibilitychange', sync)
|
|
}
|