aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2018-10-29 04:55:50 +0530
committerRoopesh Chander <roop@roopc.net>2018-10-29 06:19:43 +0530
commit0baca8bf586bb0735d80b59306c19aff81c8d4db (patch)
treebe71b36484bba30d51001d935ccf0f5eb37d3be8
parentVPN: Fix deletion of tunnels (diff)
downloadwireguard-apple-0baca8bf586bb0735d80b59306c19aff81c8d4db.tar.xz
wireguard-apple-0baca8bf586bb0735d80b59306c19aff81c8d4db.zip
Tunnel list, detail: Deletion of tunnels
Signed-off-by: Roopesh Chander <roop@roopc.net>
-rw-r--r--WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift29
-rw-r--r--WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift4
2 files changed, 31 insertions, 2 deletions
diff --git a/WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift b/WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift
index e3a4341..c2e929e 100644
--- a/WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift
@@ -60,6 +60,22 @@ class TunnelDetailTableViewController: UITableViewController {
self.present(alert, animated: true, completion: nil)
}
+
+ func showConfirmationAlert(message: String, buttonTitle: String, from sourceView: UIView,
+ onConfirmed: @escaping (() -> Void)) {
+ let destroyAction = UIAlertAction(title: buttonTitle, style: .destructive) { (action) in
+ onConfirmed()
+ }
+ let cancelAction = UIAlertAction(title: "Cancel", style: .cancel)
+ let alert = UIAlertController(title: "", message: message, preferredStyle: .actionSheet)
+ alert.addAction(destroyAction)
+ alert.addAction(cancelAction)
+
+ // popoverPresentationController will be nil on iPhone and non-nil on iPad
+ alert.popoverPresentationController?.sourceView = sourceView
+
+ self.present(alert, animated: true, completion: nil)
+ }
}
// MARK: TunnelEditTableViewControllerDelegate
@@ -213,8 +229,17 @@ extension TunnelDetailTableViewController {
// Delete configuration
let cell = tableView.dequeueReusableCell(withIdentifier: TunnelDetailTableViewButtonCell.id, for: indexPath) as! TunnelDetailTableViewButtonCell
cell.buttonText = "Delete tunnel"
- cell.onTapped = {
- print("Delete peer unimplemented")
+ cell.onTapped = { [weak self] in
+ guard let s = self else { return }
+ s.tunnelsManager.remove(tunnel: s.tunnel) { (error) in
+ if (error != nil) {
+ print("Error removing tunnel: \(String(describing: error))")
+ return
+ }
+ s.showConfirmationAlert(message: "Delete this tunnel?", buttonTitle: "Delete", from: cell) { [weak s] in
+ s?.navigationController?.navigationController?.popToRootViewController(animated: true)
+ }
+ }
}
return cell
}
diff --git a/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift b/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift
index b2b5944..eacd896 100644
--- a/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift
@@ -263,6 +263,10 @@ extension TunnelsListTableViewController: TunnelsManagerDelegate {
func tunnelsChanged() {
tableView.reloadData()
}
+
+ func tunnelRemoved(at index: Int) {
+ tableView.deleteRows(at: [IndexPath(row: index, section: 0)], with: .automatic)
+ }
}
class TunnelsListTableViewCell: UITableViewCell {