From 4defd9695d811eaea4e28dc20381cce63da5c69d Mon Sep 17 00:00:00 2001 From: Jamil Date: Mon, 24 Feb 2025 10:46:31 -0800 Subject: [PATCH] fix(apple): Process update notifications on main thread only (#8248) `@Published` properties that views subscribe to for UI updates need to be updated from the main thread only. This PR annotates the relevant variable and function from the original author's implementation with `@MainActor` so that Swift will properly warn us when modifying these in the future. --- .../FirezoneKit/Views/UpdateNotification.swift | 18 +++++++++++------- website/src/components/Changelog/Apple.tsx | 3 +++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/swift/apple/FirezoneKit/Sources/FirezoneKit/Views/UpdateNotification.swift b/swift/apple/FirezoneKit/Sources/FirezoneKit/Views/UpdateNotification.swift index 067d12375..89ce64d28 100644 --- a/swift/apple/FirezoneKit/Sources/FirezoneKit/Views/UpdateNotification.swift +++ b/swift/apple/FirezoneKit/Sources/FirezoneKit/Views/UpdateNotification.swift @@ -27,7 +27,7 @@ class UpdateChecker { private let versionCheckUrl: URL private let marketingVersion: SemanticVersion - @Published public var updateAvailable: Bool = false + @MainActor @Published private(set) var updateAvailable: Bool = false init() { guard let versionCheckUrl = URL(string: "https://www.firezone.dev/api/releases"), @@ -92,13 +92,17 @@ class UpdateChecker { } if latestVersion > marketingVersion { - self.updateAvailable = true + Task { + await MainActor.run { + self.updateAvailable = true - if let lastDismissedVersion = getLastDismissedVersion(), lastDismissedVersion >= latestVersion { - return + if let lastDismissedVersion = getLastDismissedVersion(), lastDismissedVersion >= latestVersion { + return + } + + self.notificationAdapter.showUpdateNotification(version: latestVersion) + } } - - self.notificationAdapter.showUpdateNotification(version: latestVersion) } } @@ -151,7 +155,7 @@ private class NotificationAdapter: NSObject, UNUserNotificationCenterDelegate { } - func showUpdateNotification(version: SemanticVersion) { + @MainActor func showUpdateNotification(version: SemanticVersion) { let content = UNMutableNotificationContent() setLastNotifiedVersion(version: version) content.title = "Update Firezone" diff --git a/website/src/components/Changelog/Apple.tsx b/website/src/components/Changelog/Apple.tsx index de6948b1e..b2cc398bc 100644 --- a/website/src/components/Changelog/Apple.tsx +++ b/website/src/components/Changelog/Apple.tsx @@ -20,6 +20,9 @@ export default function Apple() { {/* When you cut a release, remove any solved issues from the "known issues" lists over in `client-apps`. This must not be done when the issue's PR merges. */} + + Fixes a crash on macOS that could occur when an application update + become available. Fixes a regression that caused a crash if "Open menu" was clicked in the Welcome screen.