aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-03-11 18:09:48 +0530
committerJason A. Donenfeld <Jason@zx2c4.com>2019-03-18 06:46:56 +0100
commit01be43aa7a03e6c3d227f9861002e56f368a9ee0 (patch)
treef91a58c982d3601c445cdd0ec966b08460e00936
parenton-demand: macOS: Disable SSIDs field when adding a tunnel (diff)
downloadwireguard-apple-01be43aa7a03e6c3d227f9861002e56f368a9ee0.tar.xz
wireguard-apple-01be43aa7a03e6c3d227f9861002e56f368a9ee0.zip
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 <roop@roopc.net>
-rw-r--r--WireGuard/WireGuard/UI/ActivateOnDemandViewModel.swift28
-rw-r--r--WireGuard/WireGuard/UI/iOS/ViewController/TunnelDetailTableViewController.swift6
-rw-r--r--WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift2
-rw-r--r--WireGuard/WireGuard/UI/macOS/ViewController/TunnelDetailTableViewController.swift4
-rw-r--r--WireGuard/WireGuard/UI/macOS/ViewController/TunnelEditViewController.swift2
5 files changed, 22 insertions, 20 deletions
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)
+ }
}
}
diff --git a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelDetailTableViewController.swift b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelDetailTableViewController.swift
index 32393a9..f198e06 100644
--- a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelDetailTableViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelDetailTableViewController.swift
@@ -45,7 +45,7 @@ class TunnelDetailTableViewController: UITableViewController {
self.tunnelsManager = tunnelsManager
self.tunnel = tunnel
tunnelViewModel = TunnelViewModel(tunnelConfiguration: tunnel.tunnelConfiguration)
- onDemandViewModel = ActivateOnDemandViewModel(option: tunnel.onDemandOption)
+ onDemandViewModel = ActivateOnDemandViewModel(tunnel: tunnel)
super.init(style: .grouped)
loadSections()
loadVisibleFields()
@@ -60,7 +60,7 @@ class TunnelDetailTableViewController: UITableViewController {
}
onDemandObservationToken = tunnel.observe(\.isActivateOnDemandEnabled) { [weak self] tunnel, _ in
// Handle On-Demand getting turned on/off outside of the app
- self?.onDemandViewModel = ActivateOnDemandViewModel(option: tunnel.onDemandOption)
+ self?.onDemandViewModel = ActivateOnDemandViewModel(tunnel: tunnel)
self?.updateActivateOnDemandFields()
}
}
@@ -274,7 +274,7 @@ class TunnelDetailTableViewController: UITableViewController {
extension TunnelDetailTableViewController: TunnelEditTableViewControllerDelegate {
func tunnelSaved(tunnel: TunnelContainer) {
tunnelViewModel = TunnelViewModel(tunnelConfiguration: tunnel.tunnelConfiguration)
- onDemandViewModel = ActivateOnDemandViewModel(option: tunnel.onDemandOption)
+ onDemandViewModel = ActivateOnDemandViewModel(tunnel: tunnel)
loadSections()
loadVisibleFields()
title = tunnel.name
diff --git a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift
index 943e7e5..9b9390c 100644
--- a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift
@@ -60,7 +60,7 @@ class TunnelEditTableViewController: UITableViewController {
self.tunnelsManager = tunnelsManager
self.tunnel = tunnel
tunnelViewModel = TunnelViewModel(tunnelConfiguration: tunnel.tunnelConfiguration)
- onDemandViewModel = ActivateOnDemandViewModel(option: tunnel.onDemandOption)
+ onDemandViewModel = ActivateOnDemandViewModel(tunnel: tunnel)
super.init(style: .grouped)
loadSections()
}
diff --git a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelDetailTableViewController.swift b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelDetailTableViewController.swift
index 06b505a..9cd9c76 100644
--- a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelDetailTableViewController.swift
+++ b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelDetailTableViewController.swift
@@ -97,7 +97,7 @@ class TunnelDetailTableViewController: NSViewController {
self.tunnelsManager = tunnelsManager
self.tunnel = tunnel
tunnelViewModel = TunnelViewModel(tunnelConfiguration: tunnel.tunnelConfiguration)
- onDemandViewModel = ActivateOnDemandViewModel(option: tunnel.onDemandOption)
+ onDemandViewModel = ActivateOnDemandViewModel(tunnel: tunnel)
super.init(nibName: nil, bundle: nil)
updateTableViewModelRowsBySection()
updateTableViewModelRows()
@@ -500,7 +500,7 @@ extension TunnelDetailTableViewController: NSTableViewDelegate {
extension TunnelDetailTableViewController: TunnelEditViewControllerDelegate {
func tunnelSaved(tunnel: TunnelContainer) {
tunnelViewModel = TunnelViewModel(tunnelConfiguration: tunnel.tunnelConfiguration)
- onDemandViewModel = ActivateOnDemandViewModel(option: tunnel.onDemandOption)
+ onDemandViewModel = ActivateOnDemandViewModel(tunnel: tunnel)
updateTableViewModelRowsBySection()
updateTableViewModelRows()
updateStatus()
diff --git a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelEditViewController.swift b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelEditViewController.swift
index 2bba189..51420c4 100644
--- a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelEditViewController.swift
+++ b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelEditViewController.swift
@@ -99,7 +99,7 @@ class TunnelEditViewController: NSViewController {
init(tunnelsManager: TunnelsManager, tunnel: TunnelContainer?) {
self.tunnelsManager = tunnelsManager
self.tunnel = tunnel
- self.onDemandViewModel = tunnel != nil ? ActivateOnDemandViewModel(option: tunnel!.onDemandOption) : ActivateOnDemandViewModel()
+ self.onDemandViewModel = tunnel != nil ? ActivateOnDemandViewModel(tunnel: tunnel!) : ActivateOnDemandViewModel()
super.init(nibName: nil, bundle: nil)
}