diff --git a/Account/Sources/Account/Account.swift b/Account/Sources/Account/Account.swift index 03b8d1a39..65ee8c749 100644 --- a/Account/Sources/Account/Account.swift +++ b/Account/Sources/Account/Account.swift @@ -424,8 +424,8 @@ public enum FetchType { grantingType.requestOAuthAccessToken(with: response, transport: transport, completion: completion) } - public func receiveRemoteNotification(userInfo: [AnyHashable : Any], completion: @escaping () -> Void) { - delegate.receiveRemoteNotification(for: self, userInfo: userInfo, completion: completion) + public func receiveRemoteNotification(userInfo: [AnyHashable : Any]) async { + await delegate.receiveRemoteNotification(for: self, userInfo: userInfo) } public func refreshAll(completion: @escaping (Result) -> Void) { diff --git a/Account/Sources/Account/AccountDelegate.swift b/Account/Sources/Account/AccountDelegate.swift index aac87ca5d..1c13e3d5f 100644 --- a/Account/Sources/Account/AccountDelegate.swift +++ b/Account/Sources/Account/AccountDelegate.swift @@ -23,7 +23,7 @@ import Secrets var refreshProgress: DownloadProgress { get } - func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable : Any], completion: @escaping () -> Void) + func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable : Any]) async func refreshAll(for account: Account, completion: @escaping (Result) -> Void) func syncArticleStatus(for account: Account, completion: ((Result) -> Void)?) diff --git a/Account/Sources/Account/AccountDelegates/FeedbinAccountDelegate.swift b/Account/Sources/Account/AccountDelegates/FeedbinAccountDelegate.swift index 72c407ce2..12d89ccba 100644 --- a/Account/Sources/Account/AccountDelegates/FeedbinAccountDelegate.swift +++ b/Account/Sources/Account/AccountDelegates/FeedbinAccountDelegate.swift @@ -71,8 +71,8 @@ public enum FeedbinAccountDelegateError: String, Error { self.caller.delegate = self } - func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable : Any], completion: @escaping () -> Void) { - completion() + func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable : Any]) async { + return } func refreshAll(for account: Account, completion: @escaping (Result) -> Void) { diff --git a/Account/Sources/Account/AccountDelegates/LocalAccountDelegate.swift b/Account/Sources/Account/AccountDelegates/LocalAccountDelegate.swift index f521f0887..d75cbf090 100644 --- a/Account/Sources/Account/AccountDelegates/LocalAccountDelegate.swift +++ b/Account/Sources/Account/AccountDelegates/LocalAccountDelegate.swift @@ -40,10 +40,10 @@ final class LocalAccountDelegate: AccountDelegate, Logging { let refreshProgress = DownloadProgress(numberOfTasks: 0) - func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable : Any], completion: @escaping () -> Void) { - completion() + func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable : Any]) async { + return } - + func refreshAll(for account: Account, completion: @escaping (Result) -> Void) { guard refreshProgress.isComplete else { completion(.success(())) diff --git a/Account/Sources/Account/AccountDelegates/NewsBlurAccountDelegate.swift b/Account/Sources/Account/AccountDelegates/NewsBlurAccountDelegate.swift index 28467cca0..c35b9dfa7 100644 --- a/Account/Sources/Account/AccountDelegates/NewsBlurAccountDelegate.swift +++ b/Account/Sources/Account/AccountDelegates/NewsBlurAccountDelegate.swift @@ -62,10 +62,10 @@ final class NewsBlurAccountDelegate: AccountDelegate, Logging { database = SyncDatabase(databaseFilePath: dataFolder.appending("/DB.sqlite3")) } - func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable : Any], completion: @escaping () -> Void) { - completion() + func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable : Any]) async { + return } - + func refreshAll(for account: Account, completion: @escaping (Result) -> ()) { self.refreshProgress.addToNumberOfTasksAndRemaining(4) diff --git a/Account/Sources/Account/AccountDelegates/ReaderAPIAccountDelegate.swift b/Account/Sources/Account/AccountDelegates/ReaderAPIAccountDelegate.swift index 49011cd99..6d3723def 100644 --- a/Account/Sources/Account/AccountDelegates/ReaderAPIAccountDelegate.swift +++ b/Account/Sources/Account/AccountDelegates/ReaderAPIAccountDelegate.swift @@ -99,10 +99,10 @@ public enum ReaderAPIAccountDelegateError: LocalizedError { self.caller.variant = variant } - func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable : Any], completion: @escaping () -> Void) { - completion() + func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable : Any]) async { + return } - + func refreshAll(for account: Account, completion: @escaping (Result) -> Void) { refreshProgress.addToNumberOfTasksAndRemaining(6) diff --git a/Account/Sources/Account/AccountManager.swift b/Account/Sources/Account/AccountManager.swift index 82ca464bd..ab9750e30 100644 --- a/Account/Sources/Account/AccountManager.swift +++ b/Account/Sources/Account/AccountManager.swift @@ -239,18 +239,9 @@ import RSDatabase } } - public func receiveRemoteNotification(userInfo: [AnyHashable : Any], completion: (() -> Void)? = nil) { - let group = DispatchGroup() - + public func receiveRemoteNotification(userInfo: [AnyHashable : Any]) async { for account in activeAccounts { - group.enter() - account.receiveRemoteNotification(userInfo: userInfo) { - group.leave() - } - } - - group.notify(queue: DispatchQueue.main) { - completion?() + await account.receiveRemoteNotification(userInfo: userInfo) } } diff --git a/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift b/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift index 8d29be67c..6899e2b8f 100644 --- a/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift +++ b/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift @@ -68,14 +68,16 @@ final class CloudKitAccountDelegate: AccountDelegate, Logging { database = SyncDatabase(databaseFilePath: databaseFilePath) } - func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable : Any], completion: @escaping () -> Void) { - let op = CloudKitRemoteNotificationOperation(accountZone: accountZone, articlesZone: articlesZone, userInfo: userInfo) - op.completionBlock = { mainThreadOperaion in - completion() + func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable : Any]) async { + await withCheckedContinuation { continuation in + let op = CloudKitRemoteNotificationOperation(accountZone: accountZone, articlesZone: articlesZone, userInfo: userInfo) + op.completionBlock = { mainThreadOperation in + continuation.resume() + } + mainThreadOperationQueue.add(op) } - mainThreadOperationQueue.add(op) } - + func refreshAll(for account: Account, completion: @escaping (Result) -> Void) { guard refreshProgress.isComplete else { completion(.success(())) diff --git a/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift b/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift index 584cd667d..f35191b0c 100644 --- a/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift +++ b/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift @@ -103,8 +103,8 @@ final class FeedlyAccountDelegate: AccountDelegate, Logging { // MARK: Account API - func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable : Any], completion: @escaping () -> Void) { - completion() + func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable : Any]) async { + return } func refreshAll(for account: Account, completion: @escaping (Result) -> Void) { diff --git a/Mac/AppDelegate.swift b/Mac/AppDelegate.swift index 75eb19c5d..eaa2181e2 100644 --- a/Mac/AppDelegate.swift +++ b/Mac/AppDelegate.swift @@ -318,7 +318,9 @@ var appDelegate: AppDelegate! } func application(_ application: NSApplication, didReceiveRemoteNotification userInfo: [String : Any]) { - AccountManager.shared.receiveRemoteNotification(userInfo: userInfo) + Task { @MainActor in + await AccountManager.shared.receiveRemoteNotification(userInfo: userInfo) + } } func application(_ sender: NSApplication, openFile filename: String) -> Bool { diff --git a/iOS/AppDelegate.swift b/iOS/AppDelegate.swift index b6cc20df7..d305807cd 100644 --- a/iOS/AppDelegate.swift +++ b/iOS/AppDelegate.swift @@ -124,15 +124,14 @@ var appDelegate: AppDelegate! } func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { - DispatchQueue.main.async { + Task { @MainActor in self.resumeDatabaseProcessingIfNecessary() - AccountManager.shared.receiveRemoteNotification(userInfo: userInfo) { - self.suspendApplication() - completionHandler(.newData) - } + await AccountManager.shared.receiveRemoteNotification(userInfo: userInfo) + self.suspendApplication() + completionHandler(.newData) } - } - + } + func applicationWillTerminate(_ application: UIApplication) { shuttingDown = true }