From d08ee361d8fddc062113ccbc9a4d140c2c3571f0 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..cf4051b2c 100644 --- a/Sources/WireGuardApp/Tunnel/TunnelsManager.swift +++ b/Sources/WireGuardApp/Tunnel/TunnelsManager.swift @@ -89,11 +89,13 @@ 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 self.tunnels.remove(at: index) + removedTunnels.append(currentTunnel) 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)!)