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) {
self.profile = profile
vpn.profile = profile
title = profile?.id
navigationItem.rightBarButtonItem = (profile?.context == .host) ? itemEdit : nil
@ -102,7 +103,7 @@ class ServiceViewController: UIViewController, TableModelHost {
// run this no matter what
// XXX: convenient here vs AppDelegate for updating table
vpn.prepare(withProfile: profile) {
vpn.prepare() {
self.reloadModel()
self.tableView.reloadData()
}
@ -192,13 +193,13 @@ class ServiceViewController: UIViewController, TableModelHost {
private func activateProfile() {
service.activateProfile(uncheckedProfile)
// for vpn methods to work, must update .profile to currently active profile
vpn.profile = uncheckedProfile
vpn.disconnect { (error) in
self.vpn.prepare(withProfile: self.uncheckedProfile) {
self.reloadModel()
self.tableView.reloadData()
}
}
}
@IBAction private func renameProfile() {
let alert = Macros.alert(L10n.Service.Alerts.Rename.title, L10n.Global.Host.TitleInput.message)

View File

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