From 186ae31d0112c89573e7659c1224666a6705a00e Mon Sep 17 00:00:00 2001 From: hariel1985 Date: Thu, 2 Jul 2026 21:00:57 +0200 Subject: [PATCH] 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 --- TopManager/TopManagerApp.swift | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/TopManager/TopManagerApp.swift b/TopManager/TopManagerApp.swift index 69d9bbf..214b72c 100644 --- a/TopManager/TopManagerApp.swift +++ b/TopManager/TopManagerApp.swift @@ -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() }