fix(menubar): opt out of App Nap so refresh loop keeps ticking#126
Merged
fix(menubar): opt out of App Nap so refresh loop keeps ticking#126
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.