diff --git a/WireGuard/WireGuard/Tunnel/TunnelsManager.swift b/WireGuard/WireGuard/Tunnel/TunnelsManager.swift index e10ba77..a2fc00b 100644 --- a/WireGuard/WireGuard/Tunnel/TunnelsManager.swift +++ b/WireGuard/WireGuard/Tunnel/TunnelsManager.swift @@ -105,8 +105,7 @@ class TunnelsManager { } let tunnelProviderManager = NETunnelProviderManager() - tunnelProviderManager.protocolConfiguration = NETunnelProviderProtocol(tunnelConfiguration: tunnelConfiguration) - tunnelProviderManager.localizedDescription = tunnelConfiguration.name + tunnelProviderManager.setTunnelConfiguration(tunnelConfiguration) tunnelProviderManager.isEnabled = true activateOnDemandSetting.apply(on: tunnelProviderManager) @@ -163,8 +162,7 @@ class TunnelsManager { tunnel.name = tunnelName } - tunnelProviderManager.protocolConfiguration = NETunnelProviderProtocol(tunnelConfiguration: tunnelConfiguration, previouslyFrom: tunnelProviderManager.protocolConfiguration) - tunnelProviderManager.localizedDescription = tunnelConfiguration.name + tunnelProviderManager.setTunnelConfiguration(tunnelConfiguration) tunnelProviderManager.isEnabled = true let isActivatingOnDemand = !tunnelProviderManager.isOnDemandEnabled && activateOnDemandSetting.isActivateOnDemandEnabled @@ -178,7 +176,6 @@ class TunnelsManager { return } guard let self = self else { return } - if isNameChanged { let oldIndex = self.tunnels.firstIndex(of: tunnel)! self.tunnels.sort { $0.name < $1.name } @@ -549,4 +546,9 @@ extension NETunnelProviderManager { } return config } + func setTunnelConfiguration(_ tunnelConfiguration: TunnelConfiguration) { + protocolConfiguration = NETunnelProviderProtocol(tunnelConfiguration: tunnelConfiguration, previouslyFrom: protocolConfiguration) + localizedDescription = tunnelConfiguration.name + objc_setAssociatedObject(self, &NETunnelProviderManager.cachedConfigKey, tunnelConfiguration, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC) + } }