Disconnect before switching active profile
Make sure that completionHandler is ALWAYS called, despite vpn object being nil.
This commit is contained in:
parent
b97b6eedeb
commit
3ddfa87b58
|
@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
|
|||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## Unreleased
|
||||
|
||||
- Profile sometimes not connecting right after add.
|
||||
|
||||
## 1.0.2 Beta 1315 (2019-03-03)
|
||||
|
||||
### Fixed
|
||||
|
|
|
@ -185,12 +185,13 @@ class ServiceViewController: UIViewController, TableModelHost {
|
|||
}
|
||||
|
||||
private func activateProfile() {
|
||||
service.activateProfile(uncheckedProfile)
|
||||
|
||||
reloadModel()
|
||||
tableView.reloadData()
|
||||
|
||||
vpn.disconnect(completionHandler: nil)
|
||||
vpn.disconnect { (error) in
|
||||
self.service.activateProfile(self.uncheckedProfile)
|
||||
self.vpn.prepare(withProfile: self.uncheckedProfile) {
|
||||
self.reloadModel()
|
||||
self.tableView.reloadData()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@IBAction private func renameProfile() {
|
||||
|
|
|
@ -59,14 +59,22 @@ class GracefulVPN {
|
|||
self.profile = profile
|
||||
log.info("Preparing...")
|
||||
service.clearVpnLastError()
|
||||
vpn?.prepare(completionHandler: completionHandler)
|
||||
guard let vpn = vpn else {
|
||||
completionHandler?()
|
||||
return
|
||||
}
|
||||
vpn.prepare(completionHandler: completionHandler)
|
||||
}
|
||||
|
||||
func reconnect(completionHandler: ((Error?) -> Void)?) {
|
||||
service.clearVpnLastError()
|
||||
guard let vpn = vpn else {
|
||||
completionHandler?(nil)
|
||||
return
|
||||
}
|
||||
do {
|
||||
log.info("Reconnecting...")
|
||||
try vpn?.reconnect(configuration: service.vpnConfiguration(), completionHandler: completionHandler)
|
||||
try vpn.reconnect(configuration: service.vpnConfiguration(), completionHandler: completionHandler)
|
||||
} catch let e {
|
||||
log.error("Could not reconnect: \(e)")
|
||||
}
|
||||
|
@ -74,9 +82,13 @@ class GracefulVPN {
|
|||
|
||||
func reinstall(completionHandler: ((Error?) -> Void)?) {
|
||||
service.clearVpnLastError()
|
||||
guard let vpn = vpn else {
|
||||
completionHandler?(nil)
|
||||
return
|
||||
}
|
||||
do {
|
||||
log.info("Reinstalling...")
|
||||
try vpn?.install(configuration: service.vpnConfiguration(), completionHandler: completionHandler)
|
||||
try vpn.install(configuration: service.vpnConfiguration(), completionHandler: completionHandler)
|
||||
} catch let e {
|
||||
log.error("Could not reinstall: \(e)")
|
||||
}
|
||||
|
@ -95,14 +107,26 @@ class GracefulVPN {
|
|||
}
|
||||
|
||||
func disconnect(completionHandler: ((Error?) -> Void)?) {
|
||||
vpn?.disconnect(completionHandler: completionHandler)
|
||||
guard let vpn = vpn else {
|
||||
completionHandler?(nil)
|
||||
return
|
||||
}
|
||||
vpn.disconnect(completionHandler: completionHandler)
|
||||
}
|
||||
|
||||
func uninstall(completionHandler: (() -> Void)?) {
|
||||
vpn?.uninstall(completionHandler: completionHandler)
|
||||
guard let vpn = vpn else {
|
||||
completionHandler?()
|
||||
return
|
||||
}
|
||||
vpn.uninstall(completionHandler: completionHandler)
|
||||
}
|
||||
|
||||
func requestBytesCount(completionHandler: @escaping ((UInt, UInt)?) -> Void) {
|
||||
vpn?.requestBytesCount(completionHandler: completionHandler)
|
||||
guard let vpn = vpn else {
|
||||
completionHandler(nil)
|
||||
return
|
||||
}
|
||||
vpn.requestBytesCount(completionHandler: completionHandler)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue