aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2018-11-12 16:34:17 +0530
committerRoopesh Chander <roop@roopc.net>2018-11-12 19:24:13 +0530
commitbdb2411ebc3aedceb69e44f3a4b81954e9af21fe (patch)
tree4e2e2527cd622ae246ddf122086af770282a9540 /WireGuard/WireGuard
parentTunnels manager: Keep track of NETunnelProviderManager's isOnDemandEnabled property (diff)
downloadwireguard-apple-bdb2411ebc3aedceb69e44f3a4b81954e9af21fe.tar.xz
wireguard-apple-bdb2411ebc3aedceb69e44f3a4b81954e9af21fe.zip
Tunnel detail: Show VPN-on-demand information
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard/WireGuard')
-rw-r--r--WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift69
1 files changed, 67 insertions, 2 deletions
diff --git a/WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift b/WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift
index 92d5c64..ffefa33 100644
--- a/WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift
@@ -42,6 +42,7 @@ class TunnelDetailTableViewController: UITableViewController {
self.tableView.register(TunnelDetailTableViewStatusCell.self, forCellReuseIdentifier: TunnelDetailTableViewStatusCell.id)
self.tableView.register(TunnelDetailTableViewKeyValueCell.self, forCellReuseIdentifier: TunnelDetailTableViewKeyValueCell.id)
self.tableView.register(TunnelDetailTableViewButtonCell.self, forCellReuseIdentifier: TunnelDetailTableViewButtonCell.id)
+ self.tableView.register(TunnelDetailTableViewActivateOnDemandCell.self, forCellReuseIdentifier: TunnelDetailTableViewActivateOnDemandCell.id)
}
@objc func editTapped() {
@@ -95,7 +96,7 @@ extension TunnelDetailTableViewController: TunnelEditTableViewControllerDelegate
extension TunnelDetailTableViewController {
override func numberOfSections(in tableView: UITableView) -> Int {
- return 3 + tunnelViewModel.peersData.count
+ return 4 + tunnelViewModel.peersData.count
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
@@ -112,7 +113,11 @@ extension TunnelDetailTableViewController {
// Peer
let peerData = tunnelViewModel.peersData[section - 2]
return peerData.filterFieldsWithValueOrControl(peerFields: peerFields).count
+ } else if (section < (3 + numberOfPeerSections)) {
+ // Activate on demand
+ return 1
} else {
+ assert(section == (3 + numberOfPeerSections))
// Delete tunnel
return 1
}
@@ -130,6 +135,9 @@ extension TunnelDetailTableViewController {
} else if ((numberOfPeerSections > 0) && (section < (2 + numberOfPeerSections))) {
// Peer
return "Peer"
+ } else if (section < (3 + numberOfPeerSections)) {
+ // On-Demand Activation
+ return "On-Demand Activation"
} else {
// Delete tunnel
return nil
@@ -181,8 +189,13 @@ extension TunnelDetailTableViewController {
cell.key = field.rawValue
cell.value = peerData[field]
return cell
+ } else if (section < (3 + numberOfPeerSections)) {
+ // On-Demand Activation
+ let cell = tableView.dequeueReusableCell(withIdentifier: TunnelDetailTableViewActivateOnDemandCell.id, for: indexPath) as! TunnelDetailTableViewActivateOnDemandCell
+ cell.tunnel = self.tunnel
+ return cell
} else {
- assert(section == (2 + numberOfPeerSections))
+ assert(section == (3 + numberOfPeerSections))
// Delete configuration
let cell = tableView.dequeueReusableCell(withIdentifier: TunnelDetailTableViewButtonCell.id, for: indexPath) as! TunnelDetailTableViewButtonCell
cell.buttonText = "Delete tunnel"
@@ -392,3 +405,55 @@ class TunnelDetailTableViewButtonCell: UITableViewCell {
hasDestructiveAction = false
}
}
+
+class TunnelDetailTableViewActivateOnDemandCell: UITableViewCell {
+ static let id: String = "TunnelDetailTableViewActivateOnDemandCell"
+
+ var tunnel: TunnelContainer? {
+ didSet(value) {
+ update(from: tunnel?.activateOnDemandSetting())
+ onDemandStatusObservervationToken = tunnel?.observe(\.isActivateOnDemandEnabled) { [weak self] (tunnel, _) in
+ self?.update(from: tunnel.activateOnDemandSetting())
+ }
+ }
+ }
+
+ var onDemandStatusObservervationToken: AnyObject?
+
+ override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
+ super.init(style: .value1, reuseIdentifier: reuseIdentifier)
+ textLabel?.text = "Activate on demand"
+ }
+
+ required init?(coder aDecoder: NSCoder) {
+ fatalError("init(coder:) has not been implemented")
+ }
+
+ func update(from activateOnDemandSetting: ActivateOnDemandSetting?) {
+ let detailText: String
+ if let activateOnDemandSetting = activateOnDemandSetting {
+ if (activateOnDemandSetting.isActivateOnDemandEnabled) {
+ switch (activateOnDemandSetting.activateOnDemandOption) {
+ case .none:
+ detailText = "Off"
+ case .useOnDemandOverWifiOrCellular:
+ detailText = "Wifi or cellular"
+ case .useOnDemandOverWifiOnly:
+ detailText = "Wifi only"
+ case .useOnDemandOverCellularOnly:
+ detailText = "Cellular only"
+ }
+ } else {
+ detailText = "Off"
+ }
+ } else {
+ detailText = "Off"
+ }
+ detailTextLabel?.text = detailText
+ }
+
+ override func prepareForReuse() {
+ super.prepareForReuse()
+ detailTextLabel?.text = ""
+ }
+}