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.
This commit is contained in:
Jamil
2025-02-24 10:46:31 -08:00
committed by GitHub
parent cf837a3507
commit 4defd9695d
2 changed files with 14 additions and 7 deletions

View File

@@ -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"

View File

@@ -20,6 +20,9 @@ export default function Apple() {
<Entries downloadLinks={downloadLinks} title="macOS / iOS">
{/* 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. */}
<Unreleased>
<ChangeItem pull="8248">
Fixes a crash on macOS that could occur when an application update
become available.
<ChangeItem pull="8249">
Fixes a regression that caused a crash if "Open menu" was clicked in
the Welcome screen.