From 9c834153b0f41ede115174f84b7333422e2a98dd Mon Sep 17 00:00:00 2001 From: Juraj Hilje Date: Wed, 18 Oct 2023 09:41:28 +0200 Subject: [PATCH] fix: update disconnect method in VPNManager --- IVPNClient/Managers/VPNManager.swift | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/IVPNClient/Managers/VPNManager.swift b/IVPNClient/Managers/VPNManager.swift index 59192949e..3d89dddbd 100644 --- a/IVPNClient/Managers/VPNManager.swift +++ b/IVPNClient/Managers/VPNManager.swift @@ -232,7 +232,7 @@ class VPNManager { func installOnDemandRules(settings: ConnectionSettings, accessDetails: AccessDetails) { switch settings { case .ipsec: - self.disable(tunnelType: .openvpn) { _ in + disable(tunnelType: .openvpn) { _ in self.disable(tunnelType: .wireguard) { _ in self.setup(settings: settings, accessDetails: accessDetails, status: .disconnected) { _ in self.disconnect(tunnelType: .ipsec) @@ -240,19 +240,15 @@ class VPNManager { } } case .openvpn: - self.disable(tunnelType: .ipsec) { _ in + disable(tunnelType: .ipsec) { _ in self.disable(tunnelType: .wireguard) { _ in - self.setup(settings: settings, accessDetails: accessDetails, status: .disconnected) { _ in - self.disconnect(tunnelType: .openvpn) - } + self.setup(settings: settings, accessDetails: accessDetails, status: .disconnected) { _ in } } } case .wireguard: - self.disable(tunnelType: .ipsec) { _ in + disable(tunnelType: .ipsec) { _ in self.disable(tunnelType: .openvpn) { _ in - self.setup(settings: settings, accessDetails: accessDetails, status: .disconnected) { _ in - self.disconnect(tunnelType: .wireguard) - } + self.setup(settings: settings, accessDetails: accessDetails, status: .disconnected) { _ in } } } } @@ -272,14 +268,9 @@ class VPNManager { } func disconnect(tunnelType: TunnelType, reconnectAutomatically: Bool = false) { - getManagerFor(tunnelType: tunnelType) { manager in - DispatchQueue.async { - manager.connection.stopVPNTunnel() - } - - if !UserDefaults.shared.networkProtectionEnabled || reconnectAutomatically { - self.removeOnDemandRule(manager: manager) - } + getManagerFor(tunnelType: tunnelType) { [self] manager in + manager.connection.stopVPNTunnel() + removeOnDemandRule(manager: manager) } }