Skip to content

fix(menubar): opt out of App Nap so refresh loop keeps ticking#126

Merged
iamtoruk merged 1 commit intomainfrom
fix/menubar-disable-appnap
Apr 21, 2026
Merged

fix(menubar): opt out of App Nap so refresh loop keeps ticking#126
iamtoruk merged 1 commit intomainfrom
fix/menubar-disable-appnap

Conversation

@iamtoruk
Copy link
Copy Markdown
Member

Root cause of the stuck-menubar-label / only-refreshes-on-click behaviour that survived the prefetchAll removal and the status-bar redraw fix.

Confirmed in the system log: `_kLSApplicationWouldBeTerminatedByTALKey=1` flips on a few seconds after the menubar icon goes idle. That is Automatic Termination / App Nap declaring the app a suspend candidate, which stretches the 15-second `Task.sleep` in the refresh loop indefinitely. Clicking the menubar icon calls `NSApp.activate` which wakes the app, the pending Tasks resume, the cache refreshes, the label updates. Matches the symptom exactly.

Fix: hold a `ProcessInfo.beginActivity` token with `.userInitiated`, `.automaticTerminationDisabled`, `.suddenTerminationDisabled` for the life of the app. Released automatically when the app quits.

Net change 8 lines. Swift build clean.

Confirmed in the system log: while the menubar icon sits idle in the
background, macOS flips _kLSApplicationWouldBeTerminatedByTALKey to 1,
which is the Automatic Termination and App Nap subsystem declaring the
app a suspend candidate. Once that happens the 15s refresh Task's sleep
stretches arbitrarily, so the status bar label freezes until the user
clicks the icon (which triggers NSApp.activate and wakes everything up).

Hold a ProcessInfo.beginActivity handle for the life of the app with
.userInitiated + .automaticTerminationDisabled + .suddenTerminationDisabled
so macOS leaves the app alone. Released implicitly when the app exits.
@iamtoruk iamtoruk merged commit 2ffd5b4 into main Apr 21, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant