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
This commit is contained in:
Jamil
2024-12-30 11:08:40 -08:00
committed by GitHub
parent 279512ca98
commit a1337d011c
3 changed files with 15 additions and 8 deletions

View File

@@ -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) {

View File

@@ -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()
}
}
}

View File

@@ -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. */}
<Unreleased>
<ChangeItem pull="7593">
Fixes a bug where the VPN status would not properly update upon the
first launch of the app.
</ChangeItem>
<ChangeItem pull="7334">
Fixes an issue where symmetric NATs would generate unnecessary
candidate for hole-punching.