Set profile directly in GracefulVPN

No need to pass through prepare(). Couple with setProfile() for
robustness.
This commit is contained in:
Davide De Rosa 2019-03-10 14:18:52 +01:00
parent e74ed46ed8
commit 439c9c0b0f
2 changed files with 9 additions and 9 deletions

View File

@ -61,6 +61,7 @@ class ServiceViewController: UIViewController, TableModelHost {
func setProfile(_ profile: ConnectionProfile?, reloadingViews: Bool = true) { func setProfile(_ profile: ConnectionProfile?, reloadingViews: Bool = true) {
self.profile = profile self.profile = profile
vpn.profile = profile
title = profile?.id title = profile?.id
navigationItem.rightBarButtonItem = (profile?.context == .host) ? itemEdit : nil navigationItem.rightBarButtonItem = (profile?.context == .host) ? itemEdit : nil
@ -102,7 +103,7 @@ class ServiceViewController: UIViewController, TableModelHost {
// run this no matter what // run this no matter what
// XXX: convenient here vs AppDelegate for updating table // XXX: convenient here vs AppDelegate for updating table
vpn.prepare(withProfile: profile) { vpn.prepare() {
self.reloadModel() self.reloadModel()
self.tableView.reloadData() self.tableView.reloadData()
} }
@ -192,11 +193,11 @@ class ServiceViewController: UIViewController, TableModelHost {
private func activateProfile() { private func activateProfile() {
service.activateProfile(uncheckedProfile) service.activateProfile(uncheckedProfile)
// for vpn methods to work, must update .profile to currently active profile
vpn.profile = uncheckedProfile
vpn.disconnect { (error) in vpn.disconnect { (error) in
self.vpn.prepare(withProfile: self.uncheckedProfile) { self.reloadModel()
self.reloadModel() self.tableView.reloadData()
self.tableView.reloadData()
}
} }
} }

View File

@ -33,7 +33,7 @@ private let log = SwiftyBeaver.self
class GracefulVPN { class GracefulVPN {
private let service: ConnectionService private let service: ConnectionService
private var profile: ConnectionProfile? var profile: ConnectionProfile?
private var vpn: VPNProvider? { private var vpn: VPNProvider? {
guard let profile = profile else { guard let profile = profile else {
@ -57,14 +57,13 @@ class GracefulVPN {
self.service = service self.service = service
} }
func prepare(withProfile profile: ConnectionProfile?, completionHandler: (() -> Void)?) { func prepare(completionHandler: (() -> Void)?) {
self.profile = profile
log.info("Preparing...")
service.clearVpnLastError() service.clearVpnLastError()
guard let vpn = vpn else { guard let vpn = vpn else {
completionHandler?() completionHandler?()
return return
} }
log.info("Preparing...")
vpn.prepare(completionHandler: completionHandler) vpn.prepare(completionHandler: completionHandler)
} }