From 256f43b65ca4f82b5385a177b30ba8ce0afc7799 Mon Sep 17 00:00:00 2001 From: George Kutsurua Date: Tue, 7 Dec 2021 15:28:46 +0400 Subject: [PATCH] fix: issue of modification on active tunnel Signed-off-by: George Kutsurua --- Sources/WireGuardApp/Tunnel/TunnelsManager.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sources/WireGuardApp/Tunnel/TunnelsManager.swift b/Sources/WireGuardApp/Tunnel/TunnelsManager.swift index 7751e5457..78de0ebca 100644 --- a/Sources/WireGuardApp/Tunnel/TunnelsManager.swift +++ b/Sources/WireGuardApp/Tunnel/TunnelsManager.swift @@ -89,10 +89,12 @@ class TunnelsManager { guard let self = self else { return } let loadedTunnelProviders = managers ?? [] + var removedTunnels: [TunnelContainer] = [] for (index, currentTunnel) in self.tunnels.enumerated().reversed() { if !loadedTunnelProviders.contains(where: { $0.isEquivalentTo(currentTunnel) }) { // Tunnel was deleted outside the app + removedTunnels.append(currentTunnel) self.tunnels.remove(at: index) self.tunnelsListDelegate?.tunnelRemoved(at: index, tunnel: currentTunnel) } @@ -109,6 +111,10 @@ class TunnelsManager { } } let tunnel = TunnelContainer(tunnel: loadedTunnelProvider) + // Removed tunnel contains programmatically changed status, so we copying it to new one + if let removedTunnel = removedTunnels.first(where: { $0.name == tunnel.name }), [TunnelStatus.restarting, TunnelStatus.reasserting, TunnelStatus.waiting].contains(removedTunnel.status) { + tunnel.status = removedTunnel.status + } self.tunnels.append(tunnel) self.tunnels.sort { TunnelsManager.tunnelNameIsLessThan($0.name, $1.name) } self.tunnelsListDelegate?.tunnelAdded(at: self.tunnels.firstIndex(of: tunnel)!)