From 458041bdc82b70b84f57be728871e8969ba7874f Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Wed, 23 Oct 2019 10:17:56 +0200 Subject: [PATCH] Add cells to disclose server settings TODO: server network. --- .../Global/SwiftGen+Strings.swift | 12 ++++ .../Scenes/ServiceViewController.swift | 57 ++++++++++++++++++- Submodules/Core | 2 +- 3 files changed, 69 insertions(+), 2 deletions(-) diff --git a/Passepartout-iOS/Global/SwiftGen+Strings.swift b/Passepartout-iOS/Global/SwiftGen+Strings.swift index 7d5332ec..5080cfd0 100644 --- a/Passepartout-iOS/Global/SwiftGen+Strings.swift +++ b/Passepartout-iOS/Global/SwiftGen+Strings.swift @@ -712,6 +712,10 @@ internal enum L10n { /// Reconnect internal static let reconnect = L10n.tr("Core", "service.alerts.buttons.reconnect") } + internal enum Configuration { + /// Configuration unavailable, make sure you are connected to the VPN. + internal static let disconnected = L10n.tr("Core", "service.alerts.configuration.disconnected") + } internal enum CredentialsNeeded { /// You need to enter account credentials first. internal static let message = L10n.tr("Core", "service.alerts.credentials_needed.message") @@ -808,6 +812,14 @@ internal enum L10n { /// Report connectivity issue internal static let caption = L10n.tr("Core", "service.cells.report_issue.caption") } + internal enum ServerConfiguration { + /// Server configuration + internal static let caption = L10n.tr("Core", "service.cells.server_configuration.caption") + } + internal enum ServerNetwork { + /// Server network + internal static let caption = L10n.tr("Core", "service.cells.server_network.caption") + } internal enum TestConnectivity { /// Test connectivity internal static let caption = L10n.tr("Core", "service.cells.test_connectivity.caption") diff --git a/Passepartout-iOS/Scenes/ServiceViewController.swift b/Passepartout-iOS/Scenes/ServiceViewController.swift index dc93c9ea..baefc88d 100644 --- a/Passepartout-iOS/Scenes/ServiceViewController.swift +++ b/Passepartout-iOS/Scenes/ServiceViewController.swift @@ -476,6 +476,41 @@ class ServiceViewController: UIViewController, StrongTableHost { // } // } + private func discloseServerConfiguration() { + let caption = L10n.Core.Service.Cells.ServerConfiguration.caption + tryRequestServerConfiguration(withCaption: caption) { [weak self] in + let vc = StoryboardScene.Main.configurationIdentifier.instantiate() + vc.title = caption + vc.initialConfiguration = $0 + self?.navigationController?.pushViewController(vc, animated: true) + } + } + + private func discloseServerNetwork() { + let caption = L10n.Core.Service.Cells.ServerNetwork.caption + tryRequestServerConfiguration(withCaption: caption) { [weak self] in + let vc = StoryboardScene.Main.configurationIdentifier.instantiate() + vc.title = caption + vc.initialConfiguration = $0 + self?.navigationController?.pushViewController(vc, animated: true) + } + } + + private func tryRequestServerConfiguration(withCaption caption: String, completionHandler: @escaping (OpenVPN.Configuration) -> Void) { + vpn.requestServerConfiguration { [weak self] in + guard let cfg = $0 as? OpenVPN.Configuration else { + let alert = UIAlertController.asAlert( + caption, + L10n.Core.Service.Alerts.Configuration.disconnected + ) + alert.addCancelAction(L10n.Core.Global.ok) + self?.present(alert, animated: true, completion: nil) + return + } + completionHandler(cfg) + } + } + private func togglePrivateDataMasking(cell: ToggleTableViewCell) { let handler = { TransientStore.masksPrivateData = cell.isOn @@ -658,6 +693,10 @@ extension ServiceViewController: UITableViewDataSource, UITableViewDelegate, Tog case dataCount + case serverConfiguration + + case serverNetwork + case debugLog case masksPrivateData @@ -884,6 +923,16 @@ extension ServiceViewController: UITableViewDataSource, UITableViewDelegate, Tog cell.accessoryType = .none cell.isTappable = false return cell + + case .serverConfiguration: + let cell = Cells.setting.dequeue(from: tableView, for: indexPath) + cell.leftText = L10n.Core.Service.Cells.ServerConfiguration.caption + return cell + + case .serverNetwork: + let cell = Cells.setting.dequeue(from: tableView, for: indexPath) + cell.leftText = L10n.Core.Service.Cells.ServerNetwork.caption + return cell case .debugLog: let cell = Cells.setting.dequeue(from: tableView, for: indexPath) @@ -987,6 +1036,12 @@ extension ServiceViewController: UITableViewDataSource, UITableViewDelegate, Tog // case .dataCount: // displayDataCount() + + case .serverConfiguration: + discloseServerConfiguration() + + case .serverNetwork: + discloseServerNetwork() case .debugLog: perform(segue: StoryboardSegue.Main.debugLogSegueIdentifier, sender: cell) @@ -1125,7 +1180,7 @@ extension ServiceViewController: UITableViewDataSource, UITableViewDelegate, Tog } model.set([.vpnSurvivesSleep], forSection: .vpnSurvivesSleep) model.set([.trustedPolicy], forSection: .trustedPolicy) - model.set([.dataCount, .debugLog, .masksPrivateData], forSection: .diagnostics) + model.set([.dataCount, .serverConfiguration, .serverNetwork, .debugLog, .masksPrivateData], forSection: .diagnostics) model.set([.reportIssue], forSection: .feedback) } diff --git a/Submodules/Core b/Submodules/Core index 7fabb48c..8c09f2c3 160000 --- a/Submodules/Core +++ b/Submodules/Core @@ -1 +1 @@ -Subproject commit 7fabb48cee5189bd3c0d65c3af30cf458f69a1e3 +Subproject commit 8c09f2c3c70da0478cc1b6e94837b1aeb3a0ddde