]> git.ipfire.org Git - thirdparty/wireguard-apple.git/commitdiff
UI: When deactivating for activating another tunnel, disable on-demand
authorRoopesh Chander <roop@roopc.net>
Tue, 27 Jul 2021 06:09:07 +0000 (11:39 +0530)
committerRoopesh Chander <roop@roopc.net>
Tue, 27 Jul 2021 22:05:05 +0000 (03:35 +0530)
Signed-off-by: Roopesh Chander <roop@roopc.net>
Sources/WireGuardApp/Tunnel/TunnelsManager.swift

index 8eda2cbb83ac96e80685199465df6353a2cc98b7..e1a9a39933110a4ecab7e34d1fb4d1cc5b145d7f 100644 (file)
@@ -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
         }