From 976e47af64d130c60e6040cef196913e51be7458 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Mon, 22 Oct 2018 00:14:40 +0200 Subject: [PATCH] Clear VPN error status before restart --- Passepartout/Sources/Model/ConnectionService.swift | 7 +++++++ Passepartout/Sources/VPN/GracefulVPN.swift | 3 +++ 2 files changed, 10 insertions(+) diff --git a/Passepartout/Sources/Model/ConnectionService.swift b/Passepartout/Sources/Model/ConnectionService.swift index bf207491..b0ee8e15 100644 --- a/Passepartout/Sources/Model/ConnectionService.swift +++ b/Passepartout/Sources/Model/ConnectionService.swift @@ -286,6 +286,13 @@ class ConnectionService: Codable { return TunnelKitProvider.ProviderError(rawValue: rawValue) } + func clearVpnLastError() { + guard let key = tunnelConfiguration.lastErrorKey else { + return + } + defaults.removeObject(forKey: key) + } + // func eraseVpnLog() { // defaults.removeObject(forKey: Keys.vpnLog) // } diff --git a/Passepartout/Sources/VPN/GracefulVPN.swift b/Passepartout/Sources/VPN/GracefulVPN.swift index 561d2448..0accb7bc 100644 --- a/Passepartout/Sources/VPN/GracefulVPN.swift +++ b/Passepartout/Sources/VPN/GracefulVPN.swift @@ -58,10 +58,12 @@ class GracefulVPN { func prepare(withProfile profile: ConnectionProfile?, completionHandler: (() -> Void)?) { self.profile = profile log.info("Preparing...") + service.clearVpnLastError() vpn?.prepare(completionHandler: completionHandler) } func reconnect(completionHandler: ((Error?) -> Void)?) { + service.clearVpnLastError() do { log.info("Reconnecting...") try vpn?.reconnect(configuration: service.vpnConfiguration(), completionHandler: completionHandler) @@ -71,6 +73,7 @@ class GracefulVPN { } func reinstall(completionHandler: ((Error?) -> Void)?) { + service.clearVpnLastError() do { log.info("Reinstalling...") try vpn?.install(configuration: service.vpnConfiguration(), completionHandler: completionHandler)