Fix: show alert banners while TopManager is foreground
macOS suppresses an app's own notifications while it is the frontmost app unless the UNUserNotificationCenter delegate opts in. Set the delegate in AppDelegate and return [.banner, .sound, .list] from willPresent so High-CPU/health alerts pop as banners even with the window focused. (Also confirmed notifications require a real code signature, not the ad-hoc CODE_SIGNING_ALLOWED=NO test build.) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,20 @@
|
||||
import SwiftUI
|
||||
import UserNotifications
|
||||
|
||||
/// Flushes persisted metrics history when the app is quit, and lets alert banners
|
||||
/// appear even while TopManager is the foreground app (macOS suppresses an app's
|
||||
/// own notifications in the foreground unless the delegate opts in).
|
||||
final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDelegate {
|
||||
func applicationDidFinishLaunching(_ notification: Notification) {
|
||||
UNUserNotificationCenter.current().delegate = self
|
||||
}
|
||||
|
||||
func userNotificationCenter(_ center: UNUserNotificationCenter,
|
||||
willPresent notification: UNNotification,
|
||||
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
|
||||
completionHandler([.banner, .sound, .list])
|
||||
}
|
||||
|
||||
/// Flushes persisted metrics history when the app is quit so history isn't lost
|
||||
/// between the throttled background saves.
|
||||
final class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
func applicationWillTerminate(_ notification: Notification) {
|
||||
MetricsStore.shared.flush()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user