Skip to content

Commit

Permalink
Disconnect before switching active profile
Browse files Browse the repository at this point in the history
Make sure that completionHandler is ALWAYS called, despite vpn
object being nil.
  • Loading branch information
keeshux committed Mar 3, 2019
1 parent b97b6ee commit 3ddfa87
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

- Profile sometimes not connecting right after add.

## 1.0.2 Beta 1315 (2019-03-03)

### Fixed
Expand Down
13 changes: 7 additions & 6 deletions Passepartout-iOS/Scenes/ServiceViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,13 @@ class ServiceViewController: UIViewController, TableModelHost {
}

private func activateProfile() {
service.activateProfile(uncheckedProfile)

reloadModel()
tableView.reloadData()

vpn.disconnect(completionHandler: nil)
vpn.disconnect { (error) in
self.service.activateProfile(self.uncheckedProfile)
self.vpn.prepare(withProfile: self.uncheckedProfile) {
self.reloadModel()
self.tableView.reloadData()
}
}
}

@IBAction private func renameProfile() {
Expand Down
36 changes: 30 additions & 6 deletions Passepartout/Sources/VPN/GracefulVPN.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,36 @@ class GracefulVPN {
self.profile = profile
log.info("Preparing...")
service.clearVpnLastError()
vpn?.prepare(completionHandler: completionHandler)
guard let vpn = vpn else {
completionHandler?()
return
}
vpn.prepare(completionHandler: completionHandler)
}

func reconnect(completionHandler: ((Error?) -> Void)?) {
service.clearVpnLastError()
guard let vpn = vpn else {
completionHandler?(nil)
return
}
do {
log.info("Reconnecting...")
try vpn?.reconnect(configuration: service.vpnConfiguration(), completionHandler: completionHandler)
try vpn.reconnect(configuration: service.vpnConfiguration(), completionHandler: completionHandler)
} catch let e {
log.error("Could not reconnect: \(e)")
}
}

func reinstall(completionHandler: ((Error?) -> Void)?) {
service.clearVpnLastError()
guard let vpn = vpn else {
completionHandler?(nil)
return
}
do {
log.info("Reinstalling...")
try vpn?.install(configuration: service.vpnConfiguration(), completionHandler: completionHandler)
try vpn.install(configuration: service.vpnConfiguration(), completionHandler: completionHandler)
} catch let e {
log.error("Could not reinstall: \(e)")
}
Expand All @@ -95,14 +107,26 @@ class GracefulVPN {
}

func disconnect(completionHandler: ((Error?) -> Void)?) {
vpn?.disconnect(completionHandler: completionHandler)
guard let vpn = vpn else {
completionHandler?(nil)
return
}
vpn.disconnect(completionHandler: completionHandler)
}

func uninstall(completionHandler: (() -> Void)?) {
vpn?.uninstall(completionHandler: completionHandler)
guard let vpn = vpn else {
completionHandler?()
return
}
vpn.uninstall(completionHandler: completionHandler)
}

func requestBytesCount(completionHandler: @escaping ((UInt, UInt)?) -> Void) {
vpn?.requestBytesCount(completionHandler: completionHandler)
guard let vpn = vpn else {
completionHandler(nil)
return
}
vpn.requestBytesCount(completionHandler: completionHandler)
}
}

0 comments on commit 3ddfa87

Please sign in to comment.