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() }