Fix similar completionHandler bugs

See previous commit
This commit is contained in:
Davide De Rosa 2019-03-19 17:27:42 +01:00
parent 9a67918dc0
commit 877dd4d990
1 changed files with 19 additions and 11 deletions

View File

@ -91,19 +91,23 @@ public class StandardVPNProvider: VPNProvider {
fatalError("Not a NetworkExtensionVPNConfiguration") fatalError("Not a NetworkExtensionVPNConfiguration")
} }
find(with: bundleIdentifier) { find(with: bundleIdentifier) {
self.manager = $0 guard let manager = $0 else {
self.manager?.protocolConfiguration = configuration.protocolConfiguration completionHandler?(nil)
self.manager?.onDemandRules = configuration.onDemandRules return
self.manager?.isOnDemandEnabled = true }
self.manager?.isEnabled = true self.manager = manager
self.manager?.saveToPreferences { (error) in manager.protocolConfiguration = configuration.protocolConfiguration
manager.onDemandRules = configuration.onDemandRules
manager.isOnDemandEnabled = true
manager.isEnabled = true
manager.saveToPreferences { (error) in
guard error == nil else { guard error == nil else {
self.manager?.isOnDemandEnabled = false manager.isOnDemandEnabled = false
self.manager?.isEnabled = false manager.isEnabled = false
completionHandler?(error) completionHandler?(error)
return return
} }
self.manager?.loadFromPreferences { (error) in manager.loadFromPreferences { (error) in
completionHandler?(error) completionHandler?(error)
} }
} }
@ -153,8 +157,12 @@ public class StandardVPNProvider: VPNProvider {
public func uninstall(completionHandler: (() -> Void)?) { public func uninstall(completionHandler: (() -> Void)?) {
find(with: bundleIdentifier) { (manager) in find(with: bundleIdentifier) { (manager) in
manager?.connection.stopVPNTunnel() guard let manager = manager else {
manager?.removeFromPreferences { (error) in completionHandler?()
return
}
manager.connection.stopVPNTunnel()
manager.removeFromPreferences { (error) in
self.manager = nil self.manager = nil
completionHandler?() completionHandler?()
} }