From 01be43aa7a03e6c3d227f9861002e56f368a9ee0 Mon Sep 17 00:00:00 2001 From: Roopesh Chander Date: Mon, 11 Mar 2019 18:09:48 +0530 Subject: on-demand: View model should account for isActivateOnDemandEnabled This is needed to correctly handle NETunnelProviderManager's isOnDemandEnabled property getting changed outside of the app. Signed-off-by: Roopesh Chander --- .../WireGuard/UI/ActivateOnDemandViewModel.swift | 28 ++++++++++++---------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'WireGuard/WireGuard/UI/ActivateOnDemandViewModel.swift') diff --git a/WireGuard/WireGuard/UI/ActivateOnDemandViewModel.swift b/WireGuard/WireGuard/UI/ActivateOnDemandViewModel.swift index a406393..55b9be2 100644 --- a/WireGuard/WireGuard/UI/ActivateOnDemandViewModel.swift +++ b/WireGuard/WireGuard/UI/ActivateOnDemandViewModel.swift @@ -49,20 +49,22 @@ class ActivateOnDemandViewModel { } extension ActivateOnDemandViewModel { - convenience init(option: ActivateOnDemandOption) { + convenience init(tunnel: TunnelContainer) { self.init() - switch option { - case .off: - break - case .wiFiInterfaceOnly(let onDemandSSIDOption): - isWiFiInterfaceEnabled = true - (ssidOption, selectedSSIDs) = ssidViewModel(from: onDemandSSIDOption) - case .nonWiFiInterfaceOnly: - isNonWiFiInterfaceEnabled = true - case .anyInterface(let onDemandSSIDOption): - isWiFiInterfaceEnabled = true - isNonWiFiInterfaceEnabled = true - (ssidOption, selectedSSIDs) = ssidViewModel(from: onDemandSSIDOption) + if tunnel.isActivateOnDemandEnabled { + switch tunnel.onDemandOption { + case .off: + break + case .wiFiInterfaceOnly(let onDemandSSIDOption): + isWiFiInterfaceEnabled = true + (ssidOption, selectedSSIDs) = ssidViewModel(from: onDemandSSIDOption) + case .nonWiFiInterfaceOnly: + isNonWiFiInterfaceEnabled = true + case .anyInterface(let onDemandSSIDOption): + isWiFiInterfaceEnabled = true + isNonWiFiInterfaceEnabled = true + (ssidOption, selectedSSIDs) = ssidViewModel(from: onDemandSSIDOption) + } } } -- cgit v1.2.3-59-g8ed1b