Merge branch 'explicit-reconnect-action'

This commit is contained in:
Davide De Rosa 2018-10-22 21:49:38 +02:00
commit 70efaed0cf
4 changed files with 36 additions and 16 deletions

View File

@ -5,7 +5,11 @@ 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/), 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). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased] ## Unreleased
### Added
- Explicit "Reconnect" button. [#9](https://github.com/keeshux/passepartout-ios/pull/9)
### Fixed ### Fixed

View File

@ -92,7 +92,7 @@ class ServiceViewController: UIViewController, TableModelHost {
// run this no matter what // run this no matter what
// XXX: convenient here vs AppDelegate for updating table // XXX: convenient here vs AppDelegate for updating table
vpn.prepare(withProfile: profile) { vpn.prepare(withProfile: profile) {
// self.reloadVpnStatus() self.reloadModel()
self.tableView.reloadData() self.tableView.reloadData()
} }
@ -206,11 +206,13 @@ class ServiceViewController: UIViewController, TableModelHost {
cell.setOn(false, animated: true) cell.setOn(false, animated: true)
return return
} }
self.reloadVpnStatus() self.reloadModel()
self.tableView.reloadData()
} }
} else { } else {
vpn.disconnect { (error) in vpn.disconnect { (error) in
self.reloadVpnStatus() self.reloadModel()
self.tableView.reloadData()
} }
} }
} }
@ -397,11 +399,13 @@ extension ServiceViewController: UITableViewDataSource, UITableViewDelegate, Tog
} }
enum RowType: Int { enum RowType: Int {
case useProfile
case vpnService case vpnService
case connectionStatus case connectionStatus
case useProfile case reconnect
case account case account
@ -503,6 +507,12 @@ extension ServiceViewController: UITableViewDataSource, UITableViewDelegate, Tog
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let row = model.row(at: indexPath) let row = model.row(at: indexPath)
switch row { switch row {
case .useProfile:
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
cell.applyAction(Theme.current)
cell.leftText = L10n.Service.Cells.UseProfile.caption
return cell
case .vpnService: case .vpnService:
guard service.isActiveProfile(uncheckedProfile) else { guard service.isActiveProfile(uncheckedProfile) else {
fatalError("Do not show vpnService in non-active profile") fatalError("Do not show vpnService in non-active profile")
@ -522,13 +532,15 @@ extension ServiceViewController: UITableViewDataSource, UITableViewDelegate, Tog
cell.applyVPN(Theme.current, with: vpn.isEnabled ? vpn.status : nil) cell.applyVPN(Theme.current, with: vpn.isEnabled ? vpn.status : nil)
cell.leftText = L10n.Service.Cells.ConnectionStatus.caption cell.leftText = L10n.Service.Cells.ConnectionStatus.caption
cell.accessoryType = .none cell.accessoryType = .none
cell.isTappable = !service.needsCredentials(for: uncheckedProfile) && vpn.isEnabled cell.isTappable = false
return cell return cell
case .useProfile: case .reconnect:
let cell = Cells.setting.dequeue(from: tableView, for: indexPath) let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
cell.applyAction(Theme.current) cell.applyAction(Theme.current)
cell.leftText = L10n.Service.Cells.UseProfile.caption cell.leftText = L10n.Service.Cells.Reconnect.caption
cell.accessoryType = .none
cell.isTappable = !service.needsCredentials(for: uncheckedProfile) && vpn.isEnabled
return cell return cell
// shared cells // shared cells
@ -695,12 +707,12 @@ extension ServiceViewController: UITableViewDataSource, UITableViewDelegate, Tog
// true if enters subscreen // true if enters subscreen
private func handle(row: RowType, cell: UITableViewCell) -> Bool { private func handle(row: RowType, cell: UITableViewCell) -> Bool {
switch row { switch row {
case .connectionStatus:
confirmVpnReconnection()
case .useProfile: case .useProfile:
activate() activate()
case .reconnect:
confirmVpnReconnection()
case .account: case .account:
perform(segue: StoryboardSegue.Main.accountSegueIdentifier, sender: cell) perform(segue: StoryboardSegue.Main.accountSegueIdentifier, sender: cell)
return true return true
@ -852,7 +864,11 @@ extension ServiceViewController: UITableViewDataSource, UITableViewDelegate, Tog
// rows // rows
if isActiveProfile { if isActiveProfile {
model.set([.vpnService, .connectionStatus], in: .vpn) var rows: [RowType] = [.vpnService, .connectionStatus]
if vpn.isEnabled {
rows.append(.reconnect)
}
model.set(rows, in: .vpn)
} else { } else {
model.set([.useProfile], in: .vpn) model.set([.useProfile], in: .vpn)
} }

View File

@ -61,7 +61,7 @@
"service.sections.status.header" = "Connection"; "service.sections.status.header" = "Connection";
"service.sections.diagnostics.header" = "Diagnostics"; "service.sections.diagnostics.header" = "Diagnostics";
"service.sections.vpn.footer" = "The connection will be established whenever necessary. Tap \"Status\" to enforce a reconnection."; "service.sections.vpn.footer" = "The connection will be established whenever necessary.";
"service.sections.configuration.header" = "Configuration"; "service.sections.configuration.header" = "Configuration";
"service.sections.provider_infrastructure.footer" = "Last updated on %@."; "service.sections.provider_infrastructure.footer" = "Last updated on %@.";
"service.sections.vpn_survives_sleep.footer" = "Disable to improve battery usage, at the expense of occasional slowdowns due to wake-up reconnections."; "service.sections.vpn_survives_sleep.footer" = "Disable to improve battery usage, at the expense of occasional slowdowns due to wake-up reconnections.";
@ -72,9 +72,9 @@
"service.sections.diagnostics.header" = "Diagnostics"; "service.sections.diagnostics.header" = "Diagnostics";
//"service.sections.destruction.footer" = "Delete configuration from device settings."; //"service.sections.destruction.footer" = "Delete configuration from device settings.";
"service.cells.use_profile.caption" = "Use this profile";
"service.cells.vpn_service.caption" = "Enabled"; "service.cells.vpn_service.caption" = "Enabled";
"service.cells.connection_status.caption" = "Status"; "service.cells.connection_status.caption" = "Status";
"service.cells.use_profile.caption" = "Use this profile";
"service.cells.reconnect.caption" = "Reconnect"; "service.cells.reconnect.caption" = "Reconnect";
"service.cells.account.caption" = "Account"; "service.cells.account.caption" = "Account";
"service.cells.account.none" = "None configured"; "service.cells.account.none" = "None configured";

View File

@ -639,7 +639,7 @@ internal enum L10n {
} }
internal enum Vpn { internal enum Vpn {
/// The connection will be established whenever necessary. Tap "Status" to enforce a reconnection. /// The connection will be established whenever necessary.
internal static let footer = L10n.tr("Localizable", "service.sections.vpn.footer") internal static let footer = L10n.tr("Localizable", "service.sections.vpn.footer")
/// VPN /// VPN
internal static let header = L10n.tr("Localizable", "service.sections.vpn.header") internal static let header = L10n.tr("Localizable", "service.sections.vpn.header")