diff --git a/Brief/Updater.swift b/Brief/Updater.swift index 30cae8e..097d9a1 100644 --- a/Brief/Updater.swift +++ b/Brief/Updater.swift @@ -7,7 +7,7 @@ public protocol UpdaterProtocol: ObservableObject { } -@MainActor public class Updater: ObservableObject, UpdaterProtocol { +public class Updater: ObservableObject, UpdaterProtocol { @Published public var update: Release? @@ -30,10 +30,10 @@ public protocol UpdaterProtocol: ObservableObject { public func checkForUpdates() async { guard let (data, _) = try? await URLSession.shared.data(from: Constants.updateURL) else { return } guard let releases = try? JSONDecoder().decode([Release].self, from: data) else { return } - evaluate(releases: releases) + await evaluate(releases: releases) } - public func ignore(release: Release) { + @MainActor public func ignore(release: Release) { guard !release.critical else { return } defaults.set(true, forKey: release.name) update = release @@ -47,7 +47,7 @@ public protocol UpdaterProtocol: ObservableObject { extension Updater { - func evaluate(releases: [Release]) { + @MainActor func evaluate(releases: [Release]) { guard let release = releases .sorted() .reversed() diff --git a/SecretAgent/AppDelegate.swift b/SecretAgent/AppDelegate.swift index d54210c..0e7e9b0 100644 --- a/SecretAgent/AppDelegate.swift +++ b/SecretAgent/AppDelegate.swift @@ -33,7 +33,11 @@ class AppDelegate: NSObject, NSApplicationDelegate { notifier.prompt() updateSink = updater.$update.sink { update in guard let update = update else { return } - self.notifier.notify(update: update, ignore: self.updater.ignore(release:)) + Task { + await MainActor.run { + self.notifier.notify(update: update, ignore: self.updater.ignore(release:)) + } + } } } diff --git a/SecretAgent/Notifier.swift b/SecretAgent/Notifier.swift index ffa8059..82ccd84 100644 --- a/SecretAgent/Notifier.swift +++ b/SecretAgent/Notifier.swift @@ -79,7 +79,7 @@ class Notifier { notificationCenter.add(request, withCompletionHandler: nil) } - func notify(update: Release, ignore: ((Release) -> Void)?) { + func notify(update: Release, ignore: (@MainActor (Release) -> Void)?) { notificationDelegate.release = update notificationDelegate.ignore = ignore let notificationCenter = UNUserNotificationCenter.current() @@ -136,7 +136,7 @@ extension Notifier { class NotificationDelegate: NSObject, UNUserNotificationCenterDelegate { fileprivate var release: Release? - fileprivate var ignore: ((Release) -> Void)? + fileprivate var ignore: (@MainActor (Release) -> Void)? fileprivate var persistAuthentication: ((AnySecret, AnySecretStore, TimeInterval?) -> Void)? fileprivate var persistOptions: [String: TimeInterval] = [:] fileprivate var pendingPersistableStores: [String: AnySecretStore] = [:] @@ -146,7 +146,7 @@ class NotificationDelegate: NSObject, UNUserNotificationCenterDelegate { } - func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { + @MainActor func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { let category = response.notification.request.content.categoryIdentifier switch category { case Notifier.Constants.updateCategoryIdentitifier: @@ -160,7 +160,7 @@ class NotificationDelegate: NSObject, UNUserNotificationCenterDelegate { completionHandler() } - func handleUpdateResponse(response: UNNotificationResponse) { + @MainActor func handleUpdateResponse(response: UNNotificationResponse) { guard let update = release else { return } switch response.actionIdentifier { case Notifier.Constants.updateActionIdentitifier, UNNotificationDefaultActionIdentifier: diff --git a/Secretive/Controllers/AgentStatusChecker.swift b/Secretive/Controllers/AgentStatusChecker.swift index c8c0465..2b79453 100644 --- a/Secretive/Controllers/AgentStatusChecker.swift +++ b/Secretive/Controllers/AgentStatusChecker.swift @@ -16,7 +16,11 @@ class AgentStatusChecker: ObservableObject, AgentStatusCheckerProtocol { } func check() { - running = instanceSecretAgentProcess != nil + Task { + await MainActor.run { + running = instanceSecretAgentProcess != nil + } + } } // All processes, including ones from older versions, etc