You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
macOS: SetBadge is invisible in a bundled app without notification permission #190
cx.SetBadge on macOS sets NSApp.dockTile.badgeLabel, and internal/platform/macos/services.go:89-90 says "the badge is the Dock tile's, which needs no permission"; docs/public/en/notifications.md:41 documents the same: only iOS needs the notification permission for the badge.
At launch, apple.WatchNotifications (internal/platform/apple/notifications.go:51-72) gets UNUserNotificationCenter currentNotificationCenter and sets its delegate. Once a bundled app has touched UNUserNotificationCenter, macOS gates the Dock tile's badge on the app's notification badge authorization.
Why it matters
On a packaged (bundled) NSGo app that has not been granted notification permission, SetBadge does nothing visible: NSApp.dockTile.badgeLabel reads back the count, but the Dock shows no badge and the Dock item's AXStatusLabel stays missing. An unbundled binary (go run), where the notification center is skipped, shows the badge, so the bug only appears in shipped apps. The docs promise the opposite.
Reproduction
Observed on macOS 27.2 (Apple Silicon):
Build an app calling cx.SetBadge(7) with nsgo build -target macos_arm64 and launch the bundle without granting notifications.
The Dock tile shows no badge; reading AXStatusLabel of the app's Dock item through System Events gives missing value.
The same code run unbundled shows the badge.
A minimal Swift bundle reproduces it without NSGo: setting NSApp.dockTile.badgeLabel = "5" shows the badge, and adding only _ = UNUserNotificationCenter.current() at launch hides it while badgeLabel still reads 5.
Proposal
Either request authorization with the badge option (UNAuthorizationOptionBadge) when an app first sets a badge on macOS, which may prompt, or defer touching UNUserNotificationCenter until the app uses notifications, so apps that only set a badge keep the permission-free Dock badge. In both cases correct the comment in services.go and the notifications page (en and zh) to say when the Dock badge needs the notification permission.
Acceptance
A bundled app that never uses notifications shows its SetBadge count on the Dock tile.
A bundled app that uses notifications either shows the badge after the user grants badges, or the docs state that it needs that grant.
Activity