TunnelsManager: Fix comparing tunnels with tunnelProviders in reload()
This commit is contained in:
parent
3a10eb0748
commit
740350bed5
|
@ -78,14 +78,14 @@ class TunnelsManager {
|
||||||
let loadedTunnelProviders = managers ?? []
|
let loadedTunnelProviders = managers ?? []
|
||||||
|
|
||||||
for (index, currentTunnel) in self.tunnels.enumerated().reversed() {
|
for (index, currentTunnel) in self.tunnels.enumerated().reversed() {
|
||||||
if !loadedTunnelProviders.contains(where: { $0.tunnelConfiguration == currentTunnel.tunnelConfiguration }) {
|
if !loadedTunnelProviders.contains(where: { $0.isEquivalentTo(currentTunnel) }) {
|
||||||
// Tunnel was deleted outside the app
|
// Tunnel was deleted outside the app
|
||||||
self.tunnels.remove(at: index)
|
self.tunnels.remove(at: index)
|
||||||
self.tunnelsListDelegate?.tunnelRemoved(at: index, tunnel: currentTunnel)
|
self.tunnelsListDelegate?.tunnelRemoved(at: index, tunnel: currentTunnel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for loadedTunnelProvider in loadedTunnelProviders {
|
for loadedTunnelProvider in loadedTunnelProviders {
|
||||||
if let matchingTunnel = self.tunnels.first(where: { $0.tunnelConfiguration == loadedTunnelProvider.tunnelConfiguration }) {
|
if let matchingTunnel = self.tunnels.first(where: { loadedTunnelProvider.isEquivalentTo($0) }) {
|
||||||
matchingTunnel.tunnelProvider = loadedTunnelProvider
|
matchingTunnel.tunnelProvider = loadedTunnelProvider
|
||||||
matchingTunnel.refreshStatus()
|
matchingTunnel.refreshStatus()
|
||||||
} else {
|
} else {
|
||||||
|
@ -608,4 +608,15 @@ extension NETunnelProviderManager {
|
||||||
localizedDescription = tunnelConfiguration.name
|
localizedDescription = tunnelConfiguration.name
|
||||||
objc_setAssociatedObject(self, &NETunnelProviderManager.cachedConfigKey, tunnelConfiguration, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
|
objc_setAssociatedObject(self, &NETunnelProviderManager.cachedConfigKey, tunnelConfiguration, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isEquivalentTo(_ tunnel: TunnelContainer) -> Bool {
|
||||||
|
switch (isTunnelConfigurationAvailableInKeychain, tunnel.isTunnelConfigurationAvailableInKeychain) {
|
||||||
|
case (true, true):
|
||||||
|
return tunnelConfiguration == tunnel.tunnelConfiguration
|
||||||
|
case (false, false):
|
||||||
|
return localizedDescription == tunnel.name
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue