Merge branch 'refactor-service-updates'
This commit is contained in:
commit
446736851f
|
@ -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.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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,4 +31,6 @@ enum ApplicationError: String, Error {
|
|||
case missingCredentials
|
||||
|
||||
case migration
|
||||
|
||||
case inactiveProfile
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue