From a261d84fc62ba5e0b7a33ba6eaf7d379c1bdd200 Mon Sep 17 00:00:00 2001 From: Roopesh Chander Date: Tue, 27 Jul 2021 11:39:07 +0530 Subject: [PATCH] UI: When deactivating for activating another tunnel, disable on-demand Signed-off-by: Roopesh Chander --- Sources/WireGuardApp/Tunnel/TunnelsManager.swift | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Sources/WireGuardApp/Tunnel/TunnelsManager.swift b/Sources/WireGuardApp/Tunnel/TunnelsManager.swift index 8eda2cb..e1a9a39 100644 --- a/Sources/WireGuardApp/Tunnel/TunnelsManager.swift +++ b/Sources/WireGuardApp/Tunnel/TunnelsManager.swift @@ -419,7 +419,17 @@ class TunnelsManager { tunnel.status = .waiting activateWaitingTunnelOnDeactivation(of: tunnelInOperation) if tunnelInOperation.status != .deactivating { - startDeactivation(of: tunnelInOperation) + if tunnelInOperation.isActivateOnDemandEnabled { + setOnDemandEnabled(false, on: tunnelInOperation) { [weak self] error in + guard error == nil else { + wg_log(.error, message: "Unable to activate tunnel '\(tunnel.name)' because on-demand could not be disabled on active tunnel '\(tunnel.name)'") + return + } + self?.startDeactivation(of: tunnelInOperation) + } + } else { + startDeactivation(of: tunnelInOperation) + } } return }