Repository navigation
fix(macos): keep badges independent of notifications - #227
Merged
Merged
Conversation
houko
force-pushed
the
fix/macos-badge-permission
branch
from
November 16, 2026 09:30
b504389 to
964dffe
Compare
houko
force-pushed
the
fix/macos-badge-permission
branch
from
November 16, 2026 09:32
964dffe to
7f21f5f
Compare
houko
force-pushed
the
fix/macos-badge-permission
branch
from
November 16, 2026 09:32
7f21f5f to
e894ba2
Compare
Touching UNUserNotificationCenter makes macOS show a bundled app's Dock badge only while the user allows its badges, so NSGo no longer touches the center at launch; the delegate is set when the app asks for the permission or shows a notification.
…presses Making WatchNotifications run from NotificationPermission and ShowNotification registered the delegate's class on every call, so a second call panicked: on iOS, which watches at launch, the first permission request; on macOS, the second notification. The delegate is now made once and setting it again changes nothing. Watching only lazily also lost presses on macOS: a notification pressed after the app ended, or one an earlier run showed, is answered to the delegate before any code of this run asks for notifications. NSGo now records in the app's defaults that it asked for the permission or showed a notification, and macOS sets the delegate at launch for such an app, so only an app that never used notifications keeps the center untouched and its Dock badge free of any permission. Closing notifications no longer touches the center of an app that never used them, as one clearing them each time it comes to the front, as the services doc suggests, would otherwise hide its Dock badge. The docs and doc comments say that a macOS app's Dock badge needs the user to allow badges once it uses notifications.
…ons on macOS NotificationPermission also touches UNUserNotificationCenter and records the use, so once a macOS app checks the permission its Dock badge shows only while the user allows its badges. The doc comments and pages said only asking or showing did.
houko
force-pushed
the
fix/macos-badge-permission
branch
from
November 16, 2026 10:10
e894ba2 to
9b22bd7
Compare
Collaborator
Author
|
Reviewed.
|
houko
marked this pull request as ready for review
November 16, 2026 10:10
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.
Closes #190
A bundled macOS app that touches
UNUserNotificationCentergets its Dock badge shown only while the user allows the app's badges, so NSGo no longer touches the center of an app that never used notifications:SetBadgestays a plainNSApp.dockTileupdate and needs no permission.NSGoNotifications). A press that launches the app, or one on a notification an earlier run showed, still reachesOnNotificationPress; an app using notifications for the first time sets the delegate when it does.notificationDelegate), so setting it again from the permission request, a shown notification and launch no longer registers its class twice, which panicked.CloseNotificationandCloseNotificationsleave the center of a macOS app that never used notifications untouched, so an app that clears them each time it comes to the front keeps its badge.CHANGELOG.mdgets anUnreleasedline, now that 0.1.0 has shipped.SetBadge,NotificationPermissionandRequestNotificationPermissiondoc comments say that once a macOS app uses notifications (checks or asks for the permission, or shows a notification), its Dock badge shows only while the user allows its badges, which the permission request asks for.Verification
go tool nsgo check -target all;go build ./...and builds for windows, linux, android/arm64 and js/wasm;go tool nsgo testoninternal/platform/apple,internal/platform/macos,coreand-run 'Layer|Skills|Doc' ..TestNotificationDelegateRegistersOncepanics on the first version of this change.~/Applications, read through the Dock item'sAXStatusLabel:SetBadge(7)shows 7.OnNotificationPress. With the first version of this change, which set the delegate only lazily, the same press was lost, and asking for the permission then showing a notification panicked withobjc: failed to create class with name 'NsgoNotificationDelegate'.Screenshots
None.