diff --git a/Passepartout-iOS/Scenes/ServiceViewController.swift b/Passepartout-iOS/Scenes/ServiceViewController.swift index 409a7356..1ad8b334 100644 --- a/Passepartout-iOS/Scenes/ServiceViewController.swift +++ b/Passepartout-iOS/Scenes/ServiceViewController.swift @@ -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,9 +103,9 @@ 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() + self.updateViewsIfNeeded() } updateViewsIfNeeded() @@ -192,11 +193,11 @@ 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() - } + self.reloadModel() + self.updateViewsIfNeeded() } } @@ -242,12 +243,12 @@ class ServiceViewController: UIViewController, TableModelHost { return } self.reloadModel() - self.tableView.reloadData() + self.updateViewsIfNeeded() } } else { vpn.disconnect { (error) in self.reloadModel() - self.tableView.reloadData() + self.updateViewsIfNeeded() } } @@ -415,11 +416,12 @@ class ServiceViewController: UIViewController, TableModelHost { } @objc private func intentDidUpdateService() { - setProfile(profile) + setProfile(service.activeProfile) } @objc private func applicationDidBecomeActive() { - reloadVpnStatus() + reloadModel() + updateViewsIfNeeded() } } diff --git a/Passepartout/Sources/ApplicationError.swift b/Passepartout/Sources/ApplicationError.swift index 569ad082..37b49833 100644 --- a/Passepartout/Sources/ApplicationError.swift +++ b/Passepartout/Sources/ApplicationError.swift @@ -31,4 +31,6 @@ enum ApplicationError: String, Error { case missingCredentials case migration + + case inactiveProfile } diff --git a/Passepartout/Sources/VPN/GracefulVPN.swift b/Passepartout/Sources/VPN/GracefulVPN.swift index eaa08e58..73d96217 100644 --- a/Passepartout/Sources/VPN/GracefulVPN.swift +++ b/Passepartout/Sources/VPN/GracefulVPN.swift @@ -28,12 +28,10 @@ import SwiftyBeaver private let log = SwiftyBeaver.self -// FIXME: replace completionHandler?(nil) with completionHandler?(some_error) - class GracefulVPN { private let service: ConnectionService - private var profile: ConnectionProfile? + var profile: ConnectionProfile? private var vpn: VPNProvider? { guard let profile = profile else { @@ -57,21 +55,20 @@ 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) } func reconnect(completionHandler: ((Error?) -> Void)?) { service.clearVpnLastError() guard let vpn = vpn else { - completionHandler?(nil) + completionHandler?(ApplicationError.inactiveProfile) return } do { @@ -85,7 +82,7 @@ class GracefulVPN { func reinstall(completionHandler: ((Error?) -> Void)?) { service.clearVpnLastError() guard let vpn = vpn else { - completionHandler?(nil) + completionHandler?(ApplicationError.inactiveProfile) return } do { @@ -110,7 +107,7 @@ class GracefulVPN { func disconnect(completionHandler: ((Error?) -> Void)?) { guard let vpn = vpn else { - completionHandler?(nil) + completionHandler?(ApplicationError.inactiveProfile) return } vpn.disconnect(completionHandler: completionHandler)