mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-27 10:18:54 +00:00
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:
@@ -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"
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user