From b94935998bee38cfa966387babf2e5531f17aafa Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 24 Mar 2024 12:18:50 -0700 Subject: [PATCH] Use async versions of UNUserNotificationCenterDelegate functions. --- Mac/AppDelegate.swift | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/Mac/AppDelegate.swift b/Mac/AppDelegate.swift index 18ed8a697..9e86b58da 100644 --- a/Mac/AppDelegate.swift +++ b/Mac/AppDelegate.swift @@ -481,33 +481,28 @@ import Sparkle // MARK: UNUserNotificationCenterDelegate - nonisolated func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { - completionHandler([.banner, .badge, .sound]) - } - - nonisolated func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { - + nonisolated func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification) async -> UNNotificationPresentationOptions { + + [.banner, .badge, .sound] + } + + nonisolated func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse) async { + let userInfo = response.notification.request.content.userInfo guard let articlePathInfo = ArticlePathInfo(userInfo: userInfo) else { - completionHandler() return } - let actionIdentifier = response.actionIdentifier - - Task { @MainActor in - switch actionIdentifier { - case "MARK_AS_READ": - handleMarkAsRead(articlePathInfo: articlePathInfo) - case "MARK_AS_STARRED": - handleMarkAsStarred(articlePathInfo: articlePathInfo) - default: - mainWindowController?.handle(articlePathInfo: articlePathInfo) - } - completionHandler() + switch response.actionIdentifier { + case "MARK_AS_READ": + await handleMarkAsRead(articlePathInfo: articlePathInfo) + case "MARK_AS_STARRED": + await handleMarkAsStarred(articlePathInfo: articlePathInfo) + default: + await mainWindowController?.handle(articlePathInfo: articlePathInfo) } - } - + } + // MARK: Add Feed func addFeed(_ urlString: String?, name: String? = nil, account: Account? = nil, folder: Folder? = nil) { createAndShowMainWindowIfNecessary()