From a1337d011cfe461b365ec9bed78586c1cebd7987 Mon Sep 17 00:00:00 2001 From: Jamil Date: Mon, 30 Dec 2024 11:08:40 -0800 Subject: [PATCH] fix(apple): Load tunnel manager after creating it (#7593) When launching Firezone for the first time, the VPN profile doesn't exist. We prompt the user to create it with "Grant VPN Permission", but then we fail to reload it, which initializes the tunnelManager instance variables properly and binds observers. The result of this was that we failed to react to VPN status changes on the first launch of Firezone. This can (and should be) refactored to be cleaner, but that is out of scope for this PR and will be saved for #6554. Refs #7579 --- .../FirezoneKit/Managers/TunnelManager.swift | 4 +--- .../Sources/FirezoneKit/Stores/Store.swift | 15 ++++++++++----- website/src/components/Changelog/Apple.tsx | 4 ++++ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/swift/apple/FirezoneKit/Sources/FirezoneKit/Managers/TunnelManager.swift b/swift/apple/FirezoneKit/Sources/FirezoneKit/Managers/TunnelManager.swift index 248280310..b9c1bdb20 100644 --- a/swift/apple/FirezoneKit/Sources/FirezoneKit/Managers/TunnelManager.swift +++ b/swift/apple/FirezoneKit/Sources/FirezoneKit/Managers/TunnelManager.swift @@ -124,7 +124,7 @@ public class TunnelManager { private let bundleDescription = "Firezone" // Initialize and save a new VPN profile in system Preferences - func create() async throws -> Settings { + func create() async throws { let protocolConfiguration = NETunnelProviderProtocol() let manager = NETunnelProviderManager() let settings = Settings.defaultValue @@ -144,8 +144,6 @@ public class TunnelManager { await statusChangeHandler?(manager.connection.status) self.manager = manager - - return settings } func load(callback: @escaping (NEVPNStatus, Settings?, String?) -> Void) { diff --git a/swift/apple/FirezoneKit/Sources/FirezoneKit/Stores/Store.swift b/swift/apple/FirezoneKit/Sources/FirezoneKit/Stores/Store.swift index 2d2228ba4..97a812086 100644 --- a/swift/apple/FirezoneKit/Sources/FirezoneKit/Stores/Store.swift +++ b/swift/apple/FirezoneKit/Sources/FirezoneKit/Stores/Store.swift @@ -40,7 +40,7 @@ public final class Store: ObservableObject { self.sessionNotification = SessionNotification() initNotifications() - initTunnelManager() + loadTunnelManager() } public func internetResourceEnabled() -> Bool { @@ -62,7 +62,7 @@ public final class Store: ObservableObject { .store(in: &cancellables) } - private func initTunnelManager() { + private func loadTunnelManager() { // Subscribe to status updates from the tunnel manager TunnelManager.shared.statusChangeHandler = handleVPNStatusChange @@ -94,9 +94,14 @@ public final class Store: ObservableObject { } func createVPNProfile() { - DispatchQueue.main.async { - Task { - self.settings = try await TunnelManager.shared.create() + Task { + try await TunnelManager.shared.create() + + DispatchQueue.main.async { [weak self] in + guard let self else { return } + + // Load the new settings and bind observers + self.loadTunnelManager() } } } diff --git a/website/src/components/Changelog/Apple.tsx b/website/src/components/Changelog/Apple.tsx index caef3da3e..d288d02b3 100644 --- a/website/src/components/Changelog/Apple.tsx +++ b/website/src/components/Changelog/Apple.tsx @@ -12,6 +12,10 @@ 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 bug where the VPN status would not properly update upon the + first launch of the app. + Fixes an issue where symmetric NATs would generate unnecessary candidate for hole-punching.