aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard
diff options
context:
space:
mode:
authorEric Kuck <eric@bluelinelabs.com>2018-12-21 19:52:51 -0600
committerEric Kuck <eric@bluelinelabs.com>2018-12-21 19:52:51 -0600
commitf7e9f4d6315145fbba9fcf5ed432a6b43806321e (patch)
tree00a6972f79285a70892b2a636383ab06e598d357 /WireGuard
parentCombine double log invocations (diff)
downloadwireguard-apple-f7e9f4d6315145fbba9fcf5ed432a6b43806321e.tar.xz
wireguard-apple-f7e9f4d6315145fbba9fcf5ed432a6b43806321e.zip
Strongly recommended now appears as placeholder for DNS when needed
Signed-off-by: Eric Kuck <eric@bluelinelabs.com>
Diffstat (limited to '')
-rw-r--r--WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift48
1 files changed, 29 insertions, 19 deletions
diff --git a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift
index db7db66..ad3e2eb 100644
--- a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift
@@ -8,15 +8,25 @@ protocol TunnelEditTableViewControllerDelegate: class {
func tunnelEditingCancelled()
}
-// MARK: TunnelEditTableViewController
-
class TunnelEditTableViewController: UITableViewController {
-
private enum Section {
case interface
case peer(_ peer: TunnelViewModel.PeerData)
case addPeer
case onDemand
+
+ static func == (lhs: Section, rhs: Section) -> Bool {
+ switch (lhs, rhs) {
+ case (.interface, .interface),
+ (.addPeer, .addPeer),
+ (.onDemand, .onDemand):
+ return true
+ case let (.peer(peerA), .peer(peerB)):
+ return peerA.index == peerB.index
+ default:
+ return false
+ }
+ }
}
weak var delegate: TunnelEditTableViewControllerDelegate?
@@ -45,8 +55,8 @@ class TunnelEditTableViewController: UITableViewController {
var activateOnDemandSetting: ActivateOnDemandSetting
private var sections = [Section]()
+ // Use this initializer to edit an existing tunnel.
init(tunnelsManager: TunnelsManager, tunnel: TunnelContainer) {
- // Use this initializer to edit an existing tunnel.
self.tunnelsManager = tunnelsManager
self.tunnel = tunnel
tunnelViewModel = TunnelViewModel(tunnelConfiguration: tunnel.tunnelConfiguration)
@@ -55,8 +65,8 @@ class TunnelEditTableViewController: UITableViewController {
loadSections()
}
+ // Use this initializer to create a new tunnel.
init(tunnelsManager: TunnelsManager) {
- // Use this initializer to create a new tunnel.
self.tunnelsManager = tunnelsManager
tunnel = nil
tunnelViewModel = TunnelViewModel(tunnelConfiguration: nil)
@@ -105,9 +115,7 @@ class TunnelEditTableViewController: UITableViewController {
case .saved(let tunnelConfiguration):
if let tunnel = tunnel {
// We're modifying an existing tunnel
- tunnelsManager.modify(tunnel: tunnel,
- tunnelConfiguration: tunnelConfiguration,
- activateOnDemandSetting: activateOnDemandSetting) { [weak self] error in
+ tunnelsManager.modify(tunnel: tunnel, tunnelConfiguration: tunnelConfiguration, activateOnDemandSetting: activateOnDemandSetting) { [weak self] error in
if let error = error {
ErrorPresenter.showErrorAlert(error: error, from: self)
} else {
@@ -117,8 +125,7 @@ class TunnelEditTableViewController: UITableViewController {
}
} else {
// We're adding a new tunnel
- tunnelsManager.add(tunnelConfiguration: tunnelConfiguration,
- activateOnDemandSetting: activateOnDemandSetting) { [weak self] result in
+ tunnelsManager.add(tunnelConfiguration: tunnelConfiguration, activateOnDemandSetting: activateOnDemandSetting) { [weak self] result in
if let error = result.error {
ErrorPresenter.showErrorAlert(error: error, from: self)
} else {
@@ -290,8 +297,7 @@ extension TunnelEditTableViewController {
cell.buttonText = field.localizedUIString
cell.hasDestructiveAction = true
cell.onTapped = { [weak self, weak peerData] in
- guard let peerData = peerData else { return }
- guard let self = self else { return }
+ guard let self = self, let peerData = peerData else { return }
self.showConfirmationAlert(message: tr("deletePeerConfirmationAlertMessage"), buttonTitle: tr("deletePeerConfirmationAlertButtonTitle"), from: cell) { [weak self] in
guard let self = self else { return }
let removedSectionIndices = self.deletePeer(peer: peerData)
@@ -351,20 +357,24 @@ extension TunnelEditTableViewController {
cell.value = peerData[field]
if field == .allowedIPs {
+ let firstInterfaceSection = sections.firstIndex(where: { $0 == .interface })!
+ let interfaceSubSection = interfaceFieldsBySection.firstIndex(where: { $0.contains(.dns) })!
+ let dnsRow = interfaceFieldsBySection[interfaceSubSection].firstIndex(where: { $0 == .dns })!
+
cell.onValueBeingEdited = { [weak self, weak peerData] value in
guard let self = self, let peerData = peerData else { return }
let oldValue = peerData.shouldAllowExcludePrivateIPsControl
peerData[.allowedIPs] = value
- if oldValue != peerData.shouldAllowExcludePrivateIPsControl {
- if let row = self.peerFields.firstIndex(of: .excludePrivateIPs) {
- if peerData.shouldAllowExcludePrivateIPsControl {
- self.tableView.insertRows(at: [IndexPath(row: row, section: indexPath.section)], with: .fade)
- } else {
- self.tableView.deleteRows(at: [IndexPath(row: row, section: indexPath.section)], with: .fade)
- }
+ if oldValue != peerData.shouldAllowExcludePrivateIPsControl, let row = self.peerFields.firstIndex(of: .excludePrivateIPs) {
+ if peerData.shouldAllowExcludePrivateIPsControl {
+ self.tableView.insertRows(at: [IndexPath(row: row, section: indexPath.section)], with: .fade)
+ } else {
+ self.tableView.deleteRows(at: [IndexPath(row: row, section: indexPath.section)], with: .fade)
}
}
+
+ tableView.reloadRows(at: [IndexPath(row: dnsRow, section: firstInterfaceSection + interfaceSubSection)], with: .none)
}
} else {
cell.onValueChanged = { [weak peerData] value in