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) }