aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI/iOS/ViewController/TunnelDetailTableViewController.swift
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-03-05 19:25:17 +0530
committerJason A. Donenfeld <Jason@zx2c4.com>2019-03-18 06:46:55 +0100
commit01604dd8d14de79689a7d3fd454f41c4e0d2452f (patch)
treee56840e4ad3da6fe10cba7c37f84b3a48ec8e22f /WireGuard/WireGuard/UI/iOS/ViewController/TunnelDetailTableViewController.swift
parenton-demand: iOS: Add ability to add current SSID (diff)
downloadwireguard-apple-01604dd8d14de79689a7d3fd454f41c4e0d2452f.tar.xz
wireguard-apple-01604dd8d14de79689a7d3fd454f41c4e0d2452f.zip
on-demand: iOS: Tunnel detail: Show SSID info
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to '')
-rw-r--r--WireGuard/WireGuard/UI/iOS/ViewController/TunnelDetailTableViewController.swift40
1 files changed, 35 insertions, 5 deletions
diff --git a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelDetailTableViewController.swift b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelDetailTableViewController.swift
index 1f1a24f..19d66e7 100644
--- a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelDetailTableViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelDetailTableViewController.swift
@@ -24,21 +24,28 @@ class TunnelDetailTableViewController: UITableViewController {
.rxBytes, .txBytes, .lastHandshakeTime
]
+ static let onDemandFields: [ActivateOnDemandViewModel.OnDemandField] = [
+ .onDemand, .ssid
+ ]
+
let tunnelsManager: TunnelsManager
let tunnel: TunnelContainer
var tunnelViewModel: TunnelViewModel
+ var onDemandViewModel: ActivateOnDemandViewModel
private var sections = [Section]()
private var interfaceFieldIsVisible = [Bool]()
private var peerFieldIsVisible = [[Bool]]()
private var statusObservationToken: AnyObject?
+ private var onDemandObservationToken: AnyObject?
private var reloadRuntimeConfigurationTimer: Timer?
init(tunnelsManager: TunnelsManager, tunnel: TunnelContainer) {
self.tunnelsManager = tunnelsManager
self.tunnel = tunnel
tunnelViewModel = TunnelViewModel(tunnelConfiguration: tunnel.tunnelConfiguration)
+ onDemandViewModel = ActivateOnDemandViewModel(setting: tunnel.activateOnDemandSetting)
super.init(style: .grouped)
loadSections()
loadVisibleFields()
@@ -51,6 +58,11 @@ class TunnelDetailTableViewController: UITableViewController {
self.stopUpdatingRuntimeConfiguration()
}
}
+ onDemandObservationToken = tunnel.observe(\.isActivateOnDemandEnabled) { [weak self] tunnel, _ in
+ // Handle On-Demand getting turned on/off outside of the app
+ self?.onDemandViewModel = ActivateOnDemandViewModel(setting: tunnel.activateOnDemandSetting)
+ self?.updateActivateOnDemandFields()
+ }
}
required init?(coder aDecoder: NSCoder) {
@@ -242,11 +254,27 @@ class TunnelDetailTableViewController: UITableViewController {
self.applyTunnelConfiguration(tunnelConfiguration: tunnelConfiguration)
}
}
+
+ private func updateActivateOnDemandFields() {
+ guard let onDemandSection = sections.firstIndex(where: { if case .onDemand = $0 { return true } else { return false } }) else { return }
+ let numberOfTableViewOnDemandRows = tableView.numberOfRows(inSection: onDemandSection)
+ let ssidRowIndexPath = IndexPath(row: 1, section: onDemandSection)
+ switch (numberOfTableViewOnDemandRows, onDemandViewModel.isWiFiInterfaceEnabled) {
+ case (1, true):
+ tableView.insertRows(at: [ssidRowIndexPath], with: .automatic)
+ case (2, false):
+ tableView.deleteRows(at: [ssidRowIndexPath], with: .automatic)
+ default:
+ break
+ }
+ tableView.reloadSections(IndexSet(integer: onDemandSection), with: .automatic)
+ }
}
extension TunnelDetailTableViewController: TunnelEditTableViewControllerDelegate {
func tunnelSaved(tunnel: TunnelContainer) {
tunnelViewModel = TunnelViewModel(tunnelConfiguration: tunnel.tunnelConfiguration)
+ onDemandViewModel = ActivateOnDemandViewModel(setting: tunnel.activateOnDemandSetting)
loadSections()
loadVisibleFields()
title = tunnel.name
@@ -272,7 +300,7 @@ extension TunnelDetailTableViewController {
case .peer(let peerIndex, _):
return peerFieldIsVisible[peerIndex].filter { $0 }.count
case .onDemand:
- return 1
+ return onDemandViewModel.isWiFiInterfaceEnabled ? 2 : 1
case .delete:
return 1
}
@@ -380,10 +408,12 @@ extension TunnelDetailTableViewController {
private func onDemandCell(for tableView: UITableView, at indexPath: IndexPath) -> UITableViewCell {
let cell: KeyValueCell = tableView.dequeueReusableCell(for: indexPath)
- cell.key = tr("tunnelOnDemandKey")
- cell.value = TunnelViewModel.activateOnDemandDetailText(for: tunnel.activateOnDemandSetting)
- cell.observationToken = tunnel.observe(\.isActivateOnDemandEnabled) { [weak cell] tunnel, _ in
- cell?.value = TunnelViewModel.activateOnDemandDetailText(for: tunnel.activateOnDemandSetting)
+ let field = TunnelDetailTableViewController.onDemandFields[indexPath.row]
+ cell.key = field.localizedUIString
+ if field == .onDemand {
+ cell.value = onDemandViewModel.localizedInterfaceDescription
+ } else if field == .ssid {
+ cell.value = onDemandViewModel.ssidOption.localizedUIString
}
return cell
}