Electron tray app - reliably fetch in background after device suspended #10224
-
|
Hi all! I've been working on refactoring two existing tray/menubar Electron applications to use tanstack query. These apps run mostly in the background / hidden state. When configuring useQuery to That said, I've been having edge-case issues when waking devices that have hibernated for an extended period (ie: overnight). The background interval fetching seems to stop, only resuming after the first interaction with the tray/menubar app (note, i also have Any tips would be welcomed. For the time being, i've reverted to using an out-of-band interval polling function that calls refetch |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
This is a well-known gap between how browser-based timer APIs work and how OS-level suspend/resume behaves, and it's especially sharp in Electron tray apps since there's no natural "window focus" event to bail you out. Root Cause
On top of that, Solution 1: Electron
|
Beta Was this translation helpful? Give feedback.
This is a well-known gap between how browser-based timer APIs work and how OS-level suspend/resume behaves, and it's especially sharp in Electron tray apps since there's no natural "window focus" event to bail you out.
Root Cause
refetchIntervalunder the hood usessetInterval(via TanStack Query'stimeoutManager). When the OS suspends (sleep/hibernate), the JS event loop is frozen. On resume,setIntervalcallbacks don't retroactively fire for missed ticks. They just resume on their normal cadence, meaning your first refetch after an 8-hour sleep might not happen for another full interval cycle.On top of that,
refetchOnWindowFocusrelies onvisibilitychangeevents, andrefetchOnReconnect…