From 6e0471a55b8277ff0b21e4dd3dfcfcc8da5f0355 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Wed, 27 Apr 2022 15:44:40 +0200 Subject: [PATCH] Report vpnIsEnabled = false on install error --- Sources/TunnelKitManager/NetworkExtensionVPN.swift | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Sources/TunnelKitManager/NetworkExtensionVPN.swift b/Sources/TunnelKitManager/NetworkExtensionVPN.swift index 18cf665..919abe7 100644 --- a/Sources/TunnelKitManager/NetworkExtensionVPN.swift +++ b/Sources/TunnelKitManager/NetworkExtensionVPN.swift @@ -86,7 +86,7 @@ public class NetworkExtensionVPN: VPN { } try manager.connection.startVPNTunnel() } catch { - notifyError(error) + notifyInstallError(error) throw error } } @@ -195,12 +195,12 @@ public class NetworkExtensionVPN: VPN { manager.isOnDemandEnabled = false manager.isEnabled = false continuation.resume(throwing: error) - self.notifyError(error) + self.notifyInstallError(error) } else { manager.loadFromPreferences { error in if let error = error { continuation.resume(throwing: error) - self.notifyError(error) + self.notifyInstallError(error) } else { continuation.resume(returning: manager) self.notifyReinstall(manager) @@ -284,11 +284,12 @@ public class NetworkExtensionVPN: VPN { NotificationCenter.default.post(notification) } - private func notifyError(_ error: Error) { - log.error("VPN command failed: \(error))") + private func notifyInstallError(_ error: Error) { + log.error("VPN installation failed: \(error))") var notification = Notification(name: VPNNotification.didFail) notification.vpnError = error + notification.vpnIsEnabled = false NotificationCenter.default.post(notification) } }