From 7e51998a466eda493716c76da8fa86093f2b4bc5 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Wed, 5 Apr 2023 19:27:51 -0700 Subject: [PATCH] Continue adopting @MainActor. --- iOS/AppDelegate.swift | 24 ++++++++++++------------ iOS/RootSplitViewController.swift | 2 +- iOS/SceneCoordinator.swift | 2 +- iOS/SceneDelegate.swift | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/iOS/AppDelegate.swift b/iOS/AppDelegate.swift index bf145a3b0..7592430f0 100644 --- a/iOS/AppDelegate.swift +++ b/iOS/AppDelegate.swift @@ -57,7 +57,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD var isSyncArticleStatusRunning = false var isWaitingForSyncTasks = false - override init() { + @MainActor override init() { super.init() appDelegate = self @@ -76,7 +76,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil) } - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { + @MainActor func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { AppDefaults.registerDefaults() let isFirstRun = AppDefaults.shared.isFirstRun @@ -124,7 +124,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD } - func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { + @MainActor func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { DispatchQueue.main.async { self.resumeDatabaseProcessingIfNecessary() AccountManager.shared.receiveRemoteNotification(userInfo: userInfo) { @@ -134,17 +134,17 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD } } - func applicationWillTerminate(_ application: UIApplication) { + @MainActor func applicationWillTerminate(_ application: UIApplication) { shuttingDown = true } - func applicationDidEnterBackground(_ application: UIApplication) { + @MainActor func applicationDidEnterBackground(_ application: UIApplication) { IconImageCache.shared.emptyCache() } // MARK: Notifications - @objc func unreadCountDidChange(_ note: Notification) { + @MainActor @objc func unreadCountDidChange(_ note: Notification) { if note.object is AccountManager { unreadCount = AccountManager.shared.unreadCount } @@ -152,21 +152,21 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD // MARK: - API - func manualRefresh(errorHandler: @escaping (Error) -> ()) { + @MainActor func manualRefresh(errorHandler: @escaping (Error) -> ()) { UIApplication.shared.connectedScenes.compactMap( { $0.delegate as? SceneDelegate } ).forEach { $0.cleanUp(conditional: true) } AccountManager.shared.refreshAll(errorHandler: errorHandler) } - func resumeDatabaseProcessingIfNecessary() { + @MainActor func resumeDatabaseProcessingIfNecessary() { if AccountManager.shared.isSuspended { AccountManager.shared.resumeAll() logger.info("Application processing resumed.") } } - func prepareAccountsForBackground() { + @MainActor func prepareAccountsForBackground() { extensionFeedAddRequestFile.suspend() syncTimer?.invalidate() scheduleBackgroundFeedRefresh() @@ -175,7 +175,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD waitForSyncTasksToFinish() } - func prepareAccountsForForeground() { + @MainActor func prepareAccountsForForeground() { extensionFeedAddRequestFile.resume() syncTimer?.update() @@ -215,7 +215,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD } - func presentThemeImportError(_ error: Error) { + @MainActor func presentThemeImportError(_ error: Error) { let windowScene = { let scenes = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene } return scenes.filter { $0.activationState == .foregroundActive }.first ?? scenes.first @@ -228,7 +228,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD // MARK: App Initialization -private extension AppDelegate { +@MainActor private extension AppDelegate { private func initializeDownloaders() { let tempDir = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first! diff --git a/iOS/RootSplitViewController.swift b/iOS/RootSplitViewController.swift index 7b8c9d0c0..2c1075634 100644 --- a/iOS/RootSplitViewController.swift +++ b/iOS/RootSplitViewController.swift @@ -9,7 +9,7 @@ import UIKit import Account -class RootSplitViewController: UISplitViewController { +final class RootSplitViewController: UISplitViewController { var coordinator: SceneCoordinator! diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index 85f4febc5..6aa712981 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -52,7 +52,7 @@ struct FeedNode: Hashable { } } -class SceneCoordinator: NSObject, UndoableCommandRunner, Logging { +final class SceneCoordinator: NSObject, UndoableCommandRunner, Logging { var undoableCommands = [UndoableCommand]() var undoManager: UndoManager? { diff --git a/iOS/SceneDelegate.swift b/iOS/SceneDelegate.swift index 4c2fc6966..3513932b4 100644 --- a/iOS/SceneDelegate.swift +++ b/iOS/SceneDelegate.swift @@ -12,7 +12,7 @@ import Account import Zip import RSCore -class SceneDelegate: UIResponder, UIWindowSceneDelegate, Logging { +@MainActor final class SceneDelegate: UIResponder, UIWindowSceneDelegate, Logging { var window: UIWindow? var coordinator: SceneCoordinator!