fix(menubar): keep refresh timer alive across sleep

The sleep handler tore down the DispatchSource timer; a missed wake
notification then left it nil forever, stranding the refresh loop.
Cancel only in-flight tasks and let the kernel-paused timer resume.
This commit is contained in:
iamtoruk 2026-05-29 23:46:16 -07:00
parent d7a4048b9f
commit ea64dca52e

View file

@ -161,6 +161,12 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSPopoverDelegate {
}
private func prepareRefreshPipelineForSleep() {
// Cancel only in-flight work so a fetch started before sleep cannot
// apply a stale result after wake. The DispatchSource timer is paused
// by the kernel during sleep and fires normally on wake, so we leave
// it running — tearing it down here was the stranding bug: a missed
// wake notification left refreshTimer nil forever. The 5s rate limiter
// and single-flight forceRefreshTask guard absorb the wake burst.
forceRefreshTask?.cancel()
forceRefreshTask = nil
forceRefreshStartedAt = nil
@ -173,8 +179,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSPopoverDelegate {
statusPayloadRefreshStartedAt = nil
statusPayloadRefreshGeneration &+= 1
store.resetLoadingState()
stopRefreshTimer()
refreshLoopHeartbeatAt = .distantPast
lastRefreshTime = .distantPast
}