From ea64dca52e380ad31c01ab95f9ca6545fe87b5d0 Mon Sep 17 00:00:00 2001 From: iamtoruk Date: Fri, 29 May 2026 23:46:16 -0700 Subject: [PATCH] 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. --- mac/Sources/CodeBurnMenubar/CodeBurnApp.swift | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mac/Sources/CodeBurnMenubar/CodeBurnApp.swift b/mac/Sources/CodeBurnMenubar/CodeBurnApp.swift index 280322cf..497a55be 100644 --- a/mac/Sources/CodeBurnMenubar/CodeBurnApp.swift +++ b/mac/Sources/CodeBurnMenubar/CodeBurnApp.swift @@ -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 }