Prevent crash on add and deletion of config.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
b8abaa5283
commit
3a8f8ef9e6
|
@ -328,42 +328,49 @@ extension AppCoordinator: TunnelsTableViewControllerDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
func connect(tunnel: Tunnel, tunnelsTableViewController: TunnelsTableViewController) {
|
func connect(tunnel: Tunnel, tunnelsTableViewController: TunnelsTableViewController) {
|
||||||
let manager = self.providerManager(for: tunnel)!
|
_ = refreshProviderManagers().then { () -> Promise<Void> in
|
||||||
let block = {
|
let manager = self.providerManager(for: tunnel)!
|
||||||
switch manager.connection.status {
|
let block = {
|
||||||
case .invalid, .disconnected:
|
switch manager.connection.status {
|
||||||
self.connect(tunnel: tunnel)
|
case .invalid, .disconnected:
|
||||||
default:
|
self.connect(tunnel: tunnel)
|
||||||
break
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if manager.connection.status == .invalid {
|
if manager.connection.status == .invalid {
|
||||||
manager.loadFromPreferences { (_) in
|
manager.loadFromPreferences { (_) in
|
||||||
|
block()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
block()
|
block()
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
block()
|
return Promise.value(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func disconnect(tunnel: Tunnel, tunnelsTableViewController: TunnelsTableViewController) {
|
func disconnect(tunnel: Tunnel, tunnelsTableViewController: TunnelsTableViewController) {
|
||||||
let manager = self.providerManager(for: tunnel)!
|
_ = refreshProviderManagers().then { () -> Promise<Void> in
|
||||||
let block = {
|
let manager = self.providerManager(for: tunnel)!
|
||||||
switch manager.connection.status {
|
let block = {
|
||||||
case .connected, .connecting:
|
switch manager.connection.status {
|
||||||
self.disconnect(tunnel: tunnel)
|
case .connected, .connecting:
|
||||||
default:
|
self.disconnect(tunnel: tunnel)
|
||||||
break
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if manager.connection.status == .invalid {
|
if manager.connection.status == .invalid {
|
||||||
manager.loadFromPreferences { (_) in
|
manager.loadFromPreferences { (_) in
|
||||||
|
block()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
block()
|
block()
|
||||||
}
|
}
|
||||||
} else {
|
return Promise.value(())
|
||||||
block()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue