diff --git a/Pulse/AppDelegate.swift b/Pulse/AppDelegate.swift index f4a4c2a..e614948 100644 --- a/Pulse/AppDelegate.swift +++ b/Pulse/AppDelegate.swift @@ -4,6 +4,19 @@ import UserNotifications class AppDelegate: NSObject, NSApplicationDelegate { func applicationDidFinishLaunching(_: Foundation.Notification) { UNUserNotificationCenter.current().delegate = self + + Task { + do { + let userNotificationCenter = UNUserNotificationCenter.current() + + guard try await userNotificationCenter.requestAuthorization(options: [.alert, .sound]) else { + Logger.shared.warning("user notification not authorized") + return + } + } catch { + Logger.shared.error("user notification authorization request error: \(error)") + } + } } } diff --git a/Pulse/Notification.swift b/Pulse/Notification.swift index 660edf3..64592c1 100644 --- a/Pulse/Notification.swift +++ b/Pulse/Notification.swift @@ -1,17 +1,6 @@ import UserNotifications enum Notification { - static func initialize() { - let userNotificationCenter = UNUserNotificationCenter.current() - - userNotificationCenter.requestAuthorization(options: [.alert, .sound]) { authorized, _ in - guard authorized else { - Logger.shared.warning("user notificationCentern not authorized") - return - } - } - } - static func notify(id: String, title: String, body: String, url: String) async { let userNotificationCenter = UNUserNotificationCenter.current() diff --git a/Pulse/PulseApp.swift b/Pulse/PulseApp.swift index 8218c63..f1ea1d7 100644 --- a/Pulse/PulseApp.swift +++ b/Pulse/PulseApp.swift @@ -25,8 +25,6 @@ struct PulseApp: App { }() private func initialize() { - Notification.initialize() - let contentView = ContentView(pullRequest: pullRequest, githubToken: $githubToken) popover.contentViewController = NSHostingController(rootView: contentView)