mirror of
https://github.com/passepartoutvpn/wireguard-apple.git
synced 2025-03-03 12:12:24 +00:00
TunnelsManager: addMultiple() should also return the last error
This commit is contained in:
parent
4e476dadb3
commit
415e1e7c0c
WireGuard/WireGuard
@ -148,19 +148,21 @@ class TunnelsManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func addMultiple(tunnelConfigurations: [TunnelConfiguration], completionHandler: @escaping (UInt) -> Void) {
|
func addMultiple(tunnelConfigurations: [TunnelConfiguration], completionHandler: @escaping (UInt, TunnelsManagerError?) -> Void) {
|
||||||
addMultiple(tunnelConfigurations: ArraySlice(tunnelConfigurations), numberSuccessful: 0, completionHandler: completionHandler)
|
addMultiple(tunnelConfigurations: ArraySlice(tunnelConfigurations), numberSuccessful: 0, lastError: nil, completionHandler: completionHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func addMultiple(tunnelConfigurations: ArraySlice<TunnelConfiguration>, numberSuccessful: UInt, completionHandler: @escaping (UInt) -> Void) {
|
private func addMultiple(tunnelConfigurations: ArraySlice<TunnelConfiguration>, numberSuccessful: UInt, lastError: TunnelsManagerError?, completionHandler: @escaping (UInt, TunnelsManagerError?) -> Void) {
|
||||||
guard let head = tunnelConfigurations.first else {
|
guard let head = tunnelConfigurations.first else {
|
||||||
completionHandler(numberSuccessful)
|
completionHandler(numberSuccessful, lastError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let tail = tunnelConfigurations.dropFirst()
|
let tail = tunnelConfigurations.dropFirst()
|
||||||
add(tunnelConfiguration: head) { [weak self, tail] result in
|
add(tunnelConfiguration: head) { [weak self, tail] result in
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self?.addMultiple(tunnelConfigurations: tail, numberSuccessful: numberSuccessful + (result.isSuccess ? 1 : 0), completionHandler: completionHandler)
|
let numberSuccessful = numberSuccessful + (result.isSuccess ? 1 : 0)
|
||||||
|
let lastError = lastError ?? (result.error as? TunnelsManagerError)
|
||||||
|
self?.addMultiple(tunnelConfigurations: tail, numberSuccessful: numberSuccessful, lastError: lastError, completionHandler: completionHandler)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ class TunnelImporter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
dispatchGroup.notify(queue: .main) {
|
dispatchGroup.notify(queue: .main) {
|
||||||
tunnelsManager.addMultiple(tunnelConfigurations: configs.compactMap { $0 }) { numberSuccessful in
|
tunnelsManager.addMultiple(tunnelConfigurations: configs.compactMap { $0 }) { numberSuccessful, _ in
|
||||||
if !configs.isEmpty && numberSuccessful == configs.count {
|
if !configs.isEmpty && numberSuccessful == configs.count {
|
||||||
completionHandler?()
|
completionHandler?()
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user