aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-03-10 19:43:27 +0530
committerRoopesh Chander <roop@roopc.net>2019-03-10 19:43:27 +0530
commit9bc17034dd37ce0b4b6ec5b1f30b6fa2bb58e09d (patch)
treeaa5949e74f21d47f8554f23d64107a14f6d6bafd /WireGuard
parentmacOS: Generalize NoTunnelsDetailVC into a ButtonedDetailVC (diff)
downloadwireguard-apple-9bc17034dd37ce0b4b6ec5b1f30b6fa2bb58e09d.tar.xz
wireguard-apple-9bc17034dd37ce0b4b6ec5b1f30b6fa2bb58e09d.zip
TunnelsManager: Support for removing multiple tunnels at a time
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard')
-rw-r--r--WireGuard/WireGuard/Tunnel/TunnelsManager.swift24
1 files changed, 22 insertions, 2 deletions
diff --git a/WireGuard/WireGuard/Tunnel/TunnelsManager.swift b/WireGuard/WireGuard/Tunnel/TunnelsManager.swift
index a94d63d7..3f7d9f5f 100644
--- a/WireGuard/WireGuard/Tunnel/TunnelsManager.swift
+++ b/WireGuard/WireGuard/Tunnel/TunnelsManager.swift
@@ -240,8 +240,7 @@ class TunnelsManager {
completionHandler(TunnelsManagerError.systemErrorOnRemoveTunnel(systemError: error!))
return
}
- if let self = self {
- let index = self.tunnels.firstIndex(of: tunnel)!
+ if let self = self, let index = self.tunnels.firstIndex(of: tunnel) {
self.tunnels.remove(at: index)
self.tunnelsListDelegate?.tunnelRemoved(at: index, tunnel: tunnel)
}
@@ -249,6 +248,27 @@ class TunnelsManager {
}
}
+ func removeMultiple(tunnels: [TunnelContainer], completionHandler: @escaping (TunnelsManagerError?) -> Void) {
+ removeMultiple(tunnels: ArraySlice(tunnels), completionHandler: completionHandler)
+ }
+
+ private func removeMultiple(tunnels: ArraySlice<TunnelContainer>, completionHandler: @escaping (TunnelsManagerError?) -> Void) {
+ guard let head = tunnels.first else {
+ completionHandler(nil)
+ return
+ }
+ let tail = tunnels.dropFirst()
+ remove(tunnel: head) { [weak self, tail] error in
+ DispatchQueue.main.async {
+ if let error = error {
+ completionHandler(error)
+ } else {
+ self?.removeMultiple(tunnels: tail, completionHandler: completionHandler)
+ }
+ }
+ }
+ }
+
func numberOfTunnels() -> Int {
return tunnels.count
}