From 20b49518dad08d2f6f49479b62daa4de94cedb71 Mon Sep 17 00:00:00 2001 From: Roopesh Chander Date: Tue, 23 Oct 2018 17:41:37 +0530 Subject: [PATCH] Tunnels list: Update when a tunnel is added Signed-off-by: Roopesh Chander --- .../UI/iOS/TunnelsListTableViewController.swift | 15 +++++++++++++-- WireGuard/WireGuard/VPN/TunnelsManager.swift | 6 ++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift b/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift index f13a900..2a57393 100644 --- a/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift +++ b/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift @@ -30,8 +30,11 @@ class TunnelsListTableViewController: UITableViewController { TunnelsManager.create { [weak self] tunnelsManager in guard let tunnelsManager = tunnelsManager else { return } - self?.tunnelsManager = tunnelsManager - self?.tableView.reloadData() + if let s = self { + tunnelsManager.delegate = s + s.tunnelsManager = tunnelsManager + s.tableView.reloadData() + } } } @@ -78,6 +81,14 @@ extension TunnelsListTableViewController { } } +// MARK: TunnelsManagerDelegate + +extension TunnelsListTableViewController: TunnelsManagerDelegate { + func tunnelsAdded(atIndex index: Int, numberOfTunnels: Int) { + self.tableView.insertRows(at: [IndexPath(row: index, section: 0)], with: .automatic) + } +} + class TunnelsListTableViewCell: UITableViewCell { static let id: String = "TunnelsListTableViewCell" var tunnelName: String { diff --git a/WireGuard/WireGuard/VPN/TunnelsManager.swift b/WireGuard/WireGuard/VPN/TunnelsManager.swift index ecc64d0..2e43b5f 100644 --- a/WireGuard/WireGuard/VPN/TunnelsManager.swift +++ b/WireGuard/WireGuard/VPN/TunnelsManager.swift @@ -28,9 +28,14 @@ class TunnelContainer { } } +protocol TunnelsManagerDelegate: class { + func tunnelsAdded(atIndex: Int, numberOfTunnels: Int) +} + class TunnelsManager { var tunnels: [TunnelContainer] + weak var delegate: TunnelsManagerDelegate? = nil enum TunnelsManagerError: Error { case tunnelsUninitialized @@ -56,6 +61,7 @@ class TunnelsManager { } let tunnel = TunnelContainer(tunnel: tunnelProvider, index: 0) tunnels.insert(tunnel, at: 0) + delegate?.tunnelsAdded(atIndex: 0, numberOfTunnels: 1) completionHandler(nil) }