aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI/iOS/TunnelEditTableViewController.swift
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2018-10-24 14:11:34 +0530
committerRoopesh Chander <roop@roopc.net>2018-10-27 15:13:01 +0530
commit571e9b582647ecca9cb679ed30333c2e74959e54 (patch)
treea6270ef8792278331a1d2627a11481288d792cb1 /WireGuard/WireGuard/UI/iOS/TunnelEditTableViewController.swift
parentTunnel view model: Populate interface's public key (diff)
downloadwireguard-apple-571e9b582647ecca9cb679ed30333c2e74959e54.tar.xz
wireguard-apple-571e9b582647ecca9cb679ed30333c2e74959e54.zip
Tunnel creation: Compute public key from private key as the text is being edited
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard/WireGuard/UI/iOS/TunnelEditTableViewController.swift')
-rw-r--r--WireGuard/WireGuard/UI/iOS/TunnelEditTableViewController.swift19
1 files changed, 19 insertions, 0 deletions
diff --git a/WireGuard/WireGuard/UI/iOS/TunnelEditTableViewController.swift b/WireGuard/WireGuard/UI/iOS/TunnelEditTableViewController.swift
index 89446e9..f203e09 100644
--- a/WireGuard/WireGuard/UI/iOS/TunnelEditTableViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/TunnelEditTableViewController.swift
@@ -160,6 +160,17 @@ extension TunnelEditTableViewController {
cell.onValueChanged = { [weak interfaceData] value in
interfaceData?[field] = value
}
+ // Compute public key live
+ if (field == .privateKey) {
+ cell.onValueBeingEdited = { [weak self, weak interfaceData] value in
+ if let interfaceData = interfaceData, let s = self {
+ interfaceData[.privateKey] = value
+ if let row = s.interfaceFieldsBySection[section].firstIndex(of: .publicKey) {
+ s.tableView.reloadRows(at: [IndexPath(row: row, section: section)], with: .none)
+ }
+ }
+ }
+ }
return cell
}
} else if ((numberOfPeers > 0) && (section < (numberOfInterfaceSections + numberOfPeers * numberOfPeerSections))) {
@@ -289,6 +300,7 @@ class TunnelsEditTableViewKeyValueCell: UITableViewCell {
}
var onValueChanged: ((String) -> Void)? = nil
+ var onValueBeingEdited: ((String) -> Void)? = nil
let keyLabel: UILabel
let valueTextField: UITextField
@@ -352,6 +364,13 @@ extension TunnelsEditTableViewKeyValueCell: UITextFieldDelegate {
onValueChanged(textField.text ?? "")
}
}
+ func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
+ if let onValueBeingEdited = onValueBeingEdited {
+ let modifiedText = ((textField.text ?? "") as NSString).replacingCharacters(in: range, with: string)
+ onValueBeingEdited(modifiedText)
+ }
+ return true
+ }
}
class TunnelsEditTableViewButtonCell: UITableViewCell {