From 439c9c0b0ff71a1165917a9121b5a17585e3af0f Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Sun, 10 Mar 2019 14:18:52 +0100 Subject: [PATCH] Set profile directly in GracefulVPN No need to pass through prepare(). Couple with setProfile() for robustness. --- Passepartout-iOS/Scenes/ServiceViewController.swift | 11 ++++++----- Passepartout/Sources/VPN/GracefulVPN.swift | 7 +++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Passepartout-iOS/Scenes/ServiceViewController.swift b/Passepartout-iOS/Scenes/ServiceViewController.swift index 409a7356..137c112c 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,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,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.tableView.reloadData() } } diff --git a/Passepartout/Sources/VPN/GracefulVPN.swift b/Passepartout/Sources/VPN/GracefulVPN.swift index eaa08e58..4e92b511 100644 --- a/Passepartout/Sources/VPN/GracefulVPN.swift +++ b/Passepartout/Sources/VPN/GracefulVPN.swift @@ -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) }