refactor(apple): Annotate update resources callback @MainActor (#8069)

Followup to the discussion on
https://github.com/firezone/firezone/pull/8064. By annotating the
callback that updates our Resources `@MainActor`, the compiler will
correctly warn us when we call it from a non-isolated context.
This commit is contained in:
Jamil
2025-02-09 19:53:22 -08:00
committed by GitHub
parent fdb7631529
commit 0e990d29d3
3 changed files with 3 additions and 4 deletions

View File

@@ -320,7 +320,7 @@ public class VPNConfigurationManager {
updateInternetResourceState()
}
func fetchResources(callback: @escaping (ResourceList) -> Void) {
func fetchResources(callback: @escaping @MainActor (ResourceList) -> Void) {
guard session()?.status == .connected else { return }
do {
@@ -338,7 +338,7 @@ public class VPNConfigurationManager {
self.resourcesListCache = ResourceList.loaded(decoded)
}
callback(self.resourcesListCache)
Task { await MainActor.run { callback(self.resourcesListCache) } }
}
} catch {
Log.error(error)

View File

@@ -160,7 +160,7 @@ public final class Store: ObservableObject {
// Network Extensions don't have a 2-way binding up to the GUI process,
// so we need to periodically ask the tunnel process for them.
func beginUpdatingResources(callback: @escaping (ResourceList) -> Void) {
func beginUpdatingResources(callback: @escaping @MainActor (ResourceList) -> Void) {
Log.log("\(#function)")
if self.resourcesTimer != nil {

View File

@@ -63,7 +63,6 @@ public final class SessionViewModel: ObservableObject {
public func isInternetResourceEnabled() -> Bool {
store.internetResourceEnabled()
}
}
#if os(iOS)