Report vpnIsEnabled = false on install error

This commit is contained in:
Davide De Rosa 2022-04-27 15:44:40 +02:00
parent e075ba6a76
commit 6e0471a55b
1 changed files with 6 additions and 5 deletions

View File

@ -86,7 +86,7 @@ public class NetworkExtensionVPN: VPN {
} }
try manager.connection.startVPNTunnel() try manager.connection.startVPNTunnel()
} catch { } catch {
notifyError(error) notifyInstallError(error)
throw error throw error
} }
} }
@ -195,12 +195,12 @@ public class NetworkExtensionVPN: VPN {
manager.isOnDemandEnabled = false manager.isOnDemandEnabled = false
manager.isEnabled = false manager.isEnabled = false
continuation.resume(throwing: error) continuation.resume(throwing: error)
self.notifyError(error) self.notifyInstallError(error)
} else { } else {
manager.loadFromPreferences { error in manager.loadFromPreferences { error in
if let error = error { if let error = error {
continuation.resume(throwing: error) continuation.resume(throwing: error)
self.notifyError(error) self.notifyInstallError(error)
} else { } else {
continuation.resume(returning: manager) continuation.resume(returning: manager)
self.notifyReinstall(manager) self.notifyReinstall(manager)
@ -284,11 +284,12 @@ public class NetworkExtensionVPN: VPN {
NotificationCenter.default.post(notification) NotificationCenter.default.post(notification)
} }
private func notifyError(_ error: Error) { private func notifyInstallError(_ error: Error) {
log.error("VPN command failed: \(error))") log.error("VPN installation failed: \(error))")
var notification = Notification(name: VPNNotification.didFail) var notification = Notification(name: VPNNotification.didFail)
notification.vpnError = error notification.vpnError = error
notification.vpnIsEnabled = false
NotificationCenter.default.post(notification) NotificationCenter.default.post(notification)
} }
} }