2018-10-11 07:13:19 +00:00
|
|
|
//
|
|
|
|
// ServiceViewController.swift
|
2021-01-01 16:53:28 +00:00
|
|
|
// Passepartout
|
2018-10-11 07:13:19 +00:00
|
|
|
//
|
|
|
|
// Created by Davide De Rosa on 6/6/18.
|
2020-12-27 16:30:25 +00:00
|
|
|
// Copyright (c) 2021 Davide De Rosa. All rights reserved.
|
2018-10-11 07:13:19 +00:00
|
|
|
//
|
2018-11-03 21:33:30 +00:00
|
|
|
// https://github.com/passepartoutvpn
|
2018-10-11 07:13:19 +00:00
|
|
|
//
|
|
|
|
// This file is part of Passepartout.
|
|
|
|
//
|
|
|
|
// Passepartout is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Passepartout is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Passepartout. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
import NetworkExtension
|
2019-04-10 13:27:18 +00:00
|
|
|
import MBProgressHUD
|
2019-10-20 22:01:40 +00:00
|
|
|
import CoreLocation
|
2018-10-11 07:13:19 +00:00
|
|
|
import TunnelKit
|
2019-05-26 06:56:39 +00:00
|
|
|
import PassepartoutCore
|
2019-10-11 08:56:23 +00:00
|
|
|
import Convenience
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2020-05-09 15:33:04 +00:00
|
|
|
import SwiftyBeaver
|
|
|
|
|
|
|
|
private let log = SwiftyBeaver.self
|
|
|
|
|
2019-10-11 08:56:23 +00:00
|
|
|
class ServiceViewController: UIViewController, StrongTableHost {
|
2018-10-11 07:13:19 +00:00
|
|
|
@IBOutlet private weak var tableView: UITableView!
|
|
|
|
|
|
|
|
@IBOutlet private weak var viewWelcome: UIView!
|
|
|
|
|
|
|
|
@IBOutlet private weak var labelWelcome: UILabel!
|
|
|
|
|
2018-11-03 21:23:26 +00:00
|
|
|
@IBOutlet private weak var itemEdit: UIBarButtonItem!
|
|
|
|
|
2019-10-20 22:01:40 +00:00
|
|
|
private let locationManager = CLLocationManager()
|
|
|
|
|
2019-10-20 22:30:49 +00:00
|
|
|
private var isPendingTrustedWiFi = false
|
|
|
|
|
2019-10-11 08:56:23 +00:00
|
|
|
private let downloader = FileDownloader(
|
|
|
|
temporaryURL: GroupConstants.App.cachesURL.appendingPathComponent("downloaded.tmp"),
|
2019-12-02 09:46:59 +00:00
|
|
|
timeout: AppConstants.Services.timeout
|
2019-10-11 08:56:23 +00:00
|
|
|
)
|
|
|
|
|
2019-03-08 11:50:34 +00:00
|
|
|
private var profile: ConnectionProfile?
|
2018-10-11 07:13:19 +00:00
|
|
|
|
|
|
|
private let service = TransientStore.shared.service
|
|
|
|
|
|
|
|
private lazy var vpn = GracefulVPN(service: service)
|
|
|
|
|
2018-11-02 10:19:59 +00:00
|
|
|
private weak var pendingRenameAction: UIAlertAction?
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
private var lastInfrastructureUpdate: Date?
|
|
|
|
|
2019-03-21 20:27:24 +00:00
|
|
|
private var shouldDeleteLogOnDisconnection = false
|
|
|
|
|
2019-03-29 10:17:50 +00:00
|
|
|
private var currentDataCount: (Int, Int)?
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
// MARK: Table
|
|
|
|
|
2019-10-11 08:56:23 +00:00
|
|
|
var model: StrongTableModel<SectionType, RowType> = StrongTableModel()
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2019-11-21 08:15:24 +00:00
|
|
|
private let trustedNetworks = TrustedNetworksUI()
|
2018-10-11 07:13:19 +00:00
|
|
|
|
|
|
|
// MARK: UIViewController
|
|
|
|
|
|
|
|
deinit {
|
|
|
|
NotificationCenter.default.removeObserver(self)
|
|
|
|
}
|
|
|
|
|
2019-03-08 11:50:34 +00:00
|
|
|
func setProfile(_ profile: ConnectionProfile?, reloadingViews: Bool = true) {
|
|
|
|
self.profile = profile
|
|
|
|
|
2020-02-28 17:32:04 +00:00
|
|
|
if let profile = profile {
|
|
|
|
title = service.screenTitle(ProfileKey(profile))
|
|
|
|
} else {
|
|
|
|
title = nil
|
|
|
|
}
|
2019-03-08 11:50:34 +00:00
|
|
|
navigationItem.rightBarButtonItem = (profile?.context == .host) ? itemEdit : nil
|
|
|
|
if reloadingViews {
|
|
|
|
reloadModel()
|
|
|
|
updateViewsIfNeeded()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
override func viewDidLoad() {
|
|
|
|
super.viewDidLoad()
|
|
|
|
|
|
|
|
// fall back to active profile
|
|
|
|
if profile == nil {
|
2019-03-08 11:50:34 +00:00
|
|
|
setProfile(service.activeProfile)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
if let providerProfile = profile as? ProviderConnectionProfile {
|
2019-11-23 13:22:34 +00:00
|
|
|
lastInfrastructureUpdate = InfrastructureFactory.shared.modificationDate(forName: providerProfile.name)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
navigationItem.leftBarButtonItem = splitViewController?.displayModeButtonItem
|
|
|
|
navigationItem.leftItemsSupplementBackButton = true
|
|
|
|
|
2019-06-23 08:33:43 +00:00
|
|
|
labelWelcome.text = L10n.Core.Service.Welcome.message
|
2019-10-25 17:30:21 +00:00
|
|
|
labelWelcome.apply(.current)
|
2018-10-11 07:13:19 +00:00
|
|
|
|
|
|
|
let nc = NotificationCenter.default
|
|
|
|
nc.addObserver(self, selector: #selector(applicationDidBecomeActive), name: UIApplication.didBecomeActiveNotification, object: nil)
|
2020-06-12 21:30:57 +00:00
|
|
|
nc.addObserver(self, selector: #selector(vpnDidUpdate), name: VPN.didChangeStatus, object: nil)
|
|
|
|
nc.addObserver(self, selector: #selector(vpnDidUpdate), name: VPN.didReinstall, object: nil)
|
2019-11-02 10:33:55 +00:00
|
|
|
if #available(iOS 13, *) {
|
|
|
|
nc.addObserver(self, selector: #selector(intentDidUpdateService), name: IntentDispatcher.didUpdateService, object: nil)
|
|
|
|
}
|
|
|
|
nc.addObserver(self, selector: #selector(serviceDidUpdateDataCount(_:)), name: ConnectionService.didUpdateDataCount, object: nil)
|
2019-11-02 10:28:35 +00:00
|
|
|
nc.addObserver(self, selector: #selector(productManagerDidReloadReceipt), name: ProductManager.didReloadReceipt, object: nil)
|
2019-11-09 12:06:13 +00:00
|
|
|
nc.addObserver(self, selector: #selector(productManagerDidReviewPurchases), name: ProductManager.didReviewPurchases, object: nil)
|
2018-10-11 07:13:19 +00:00
|
|
|
|
|
|
|
// run this no matter what
|
|
|
|
// XXX: convenient here vs AppDelegate for updating table
|
2019-03-10 13:18:52 +00:00
|
|
|
vpn.prepare() {
|
2018-10-21 08:05:39 +00:00
|
|
|
self.reloadModel()
|
2019-03-10 13:29:31 +00:00
|
|
|
self.updateViewsIfNeeded()
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
updateViewsIfNeeded()
|
|
|
|
}
|
|
|
|
|
|
|
|
override func viewWillAppear(_ animated: Bool) {
|
|
|
|
super.viewWillAppear(animated)
|
|
|
|
|
|
|
|
hideProfileIfDeleted()
|
|
|
|
}
|
|
|
|
|
|
|
|
override func viewDidAppear(_ animated: Bool) {
|
|
|
|
super.viewDidAppear(animated)
|
|
|
|
|
|
|
|
clearSelection()
|
2019-11-09 12:06:13 +00:00
|
|
|
hideProfileIfDeleted()
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override func didReceiveMemoryWarning() {
|
|
|
|
super.didReceiveMemoryWarning()
|
|
|
|
// Dispose of any resources that can be recreated.
|
|
|
|
}
|
|
|
|
|
|
|
|
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
|
|
|
guard let sid = segue.identifier, let segueType = StoryboardSegue.Main(rawValue: sid) else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
let destination = segue.destination
|
|
|
|
|
|
|
|
switch segueType {
|
|
|
|
case .accountSegueIdentifier:
|
|
|
|
let vc = destination as? AccountViewController
|
|
|
|
vc?.currentCredentials = service.credentials(for: uncheckedProfile)
|
|
|
|
vc?.usernamePlaceholder = (profile as? ProviderConnectionProfile)?.infrastructure.defaults.username
|
|
|
|
vc?.infrastructureName = (profile as? ProviderConnectionProfile)?.infrastructure.name
|
|
|
|
vc?.delegate = self
|
|
|
|
|
|
|
|
case .providerPoolSegueIdentifier:
|
|
|
|
let vc = destination as? ProviderPoolViewController
|
2019-04-25 18:40:50 +00:00
|
|
|
vc?.setInfrastructure(uncheckedProviderProfile.infrastructure, currentPoolId: uncheckedProviderProfile.poolId)
|
2019-11-21 13:00:34 +00:00
|
|
|
vc?.favoriteGroupIds = uncheckedProviderProfile.favoriteGroupIds ?? []
|
2018-10-11 07:13:19 +00:00
|
|
|
vc?.delegate = self
|
|
|
|
|
|
|
|
case .endpointSegueIdentifier:
|
|
|
|
let vc = destination as? EndpointViewController
|
|
|
|
vc?.dataSource = profile
|
|
|
|
vc?.delegate = self
|
|
|
|
vc?.modificationDelegate = self
|
|
|
|
|
|
|
|
case .providerPresetSegueIdentifier:
|
2019-05-02 10:51:40 +00:00
|
|
|
let infra = uncheckedProviderProfile.infrastructure
|
|
|
|
let presets: [InfrastructurePreset] = uncheckedProviderProfile.pool?.supportedPresetIds(in: uncheckedProviderProfile.infrastructure).map {
|
|
|
|
return infra.preset(for: $0)!
|
|
|
|
} ?? []
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
let vc = destination as? ProviderPresetViewController
|
2019-05-02 10:51:40 +00:00
|
|
|
vc?.presets = presets
|
2018-10-11 07:13:19 +00:00
|
|
|
vc?.currentPresetId = uncheckedProviderProfile.presetId
|
|
|
|
vc?.delegate = self
|
|
|
|
|
|
|
|
case .hostParametersSegueIdentifier:
|
|
|
|
let vc = destination as? ConfigurationViewController
|
2019-06-21 21:15:43 +00:00
|
|
|
vc?.title = L10n.App.Service.Cells.Host.Parameters.caption
|
2018-10-25 18:08:22 +00:00
|
|
|
vc?.initialConfiguration = uncheckedHostProfile.parameters.sessionConfiguration
|
2018-10-26 22:08:48 +00:00
|
|
|
vc?.originalConfigurationURL = service.configurationURL(for: uncheckedHostProfile)
|
2018-10-11 07:13:19 +00:00
|
|
|
vc?.delegate = self
|
|
|
|
|
2019-04-29 16:13:49 +00:00
|
|
|
case .networkSettingsSegueIdentifier:
|
|
|
|
let vc = destination as? NetworkSettingsViewController
|
2019-06-21 21:15:43 +00:00
|
|
|
vc?.title = L10n.Core.NetworkSettings.title
|
2019-04-29 16:13:49 +00:00
|
|
|
vc?.profile = profile
|
|
|
|
|
2019-10-23 08:52:15 +00:00
|
|
|
case .serverNetworkSegueIdentifier:
|
|
|
|
break
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case .debugLogSegueIdentifier:
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: Actions
|
|
|
|
|
|
|
|
func hideProfileIfDeleted() {
|
|
|
|
guard let profile = profile else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if !service.containsProfile(profile) {
|
2019-03-08 11:50:34 +00:00
|
|
|
setProfile(nil)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX: outlets can be nil here!
|
|
|
|
private func updateViewsIfNeeded() {
|
|
|
|
tableView?.reloadData()
|
|
|
|
viewWelcome?.isHidden = (profile != nil)
|
|
|
|
}
|
|
|
|
|
2018-11-02 10:19:59 +00:00
|
|
|
private func activateProfile() {
|
2019-03-08 11:29:52 +00:00
|
|
|
service.activateProfile(uncheckedProfile)
|
2019-03-03 12:00:42 +00:00
|
|
|
vpn.disconnect { (error) in
|
2019-03-10 13:18:52 +00:00
|
|
|
self.reloadModel()
|
2019-03-10 13:29:31 +00:00
|
|
|
self.updateViewsIfNeeded()
|
2019-03-03 12:00:42 +00:00
|
|
|
}
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
2018-11-02 10:19:59 +00:00
|
|
|
@IBAction private func renameProfile() {
|
2020-02-28 17:32:04 +00:00
|
|
|
let alert = UIAlertController.asAlert(L10n.Core.Service.Alerts.Rename.title, nil)
|
2018-11-02 10:19:59 +00:00
|
|
|
alert.addTextField { (field) in
|
2020-02-28 17:32:04 +00:00
|
|
|
field.text = self.service.screenTitle(ProfileKey(self.uncheckedProfile))
|
2020-05-11 20:53:09 +00:00
|
|
|
field.applyHostTitle(.current)
|
2018-11-02 10:19:59 +00:00
|
|
|
field.delegate = self
|
|
|
|
}
|
2019-10-11 08:56:23 +00:00
|
|
|
pendingRenameAction = alert.addPreferredAction(L10n.Core.Global.ok) {
|
2020-02-28 17:32:04 +00:00
|
|
|
guard let newTitle = alert.textFields?.first?.text else {
|
2018-11-02 10:19:59 +00:00
|
|
|
return
|
|
|
|
}
|
2020-05-11 20:30:58 +00:00
|
|
|
self.confirmRenameCurrentProfile(to: newTitle)
|
2018-11-02 10:19:59 +00:00
|
|
|
}
|
2019-06-21 21:15:43 +00:00
|
|
|
alert.addCancelAction(L10n.Core.Global.cancel)
|
2018-11-02 10:19:59 +00:00
|
|
|
pendingRenameAction?.isEnabled = false
|
|
|
|
present(alert, animated: true, completion: nil)
|
|
|
|
}
|
|
|
|
|
2020-05-11 20:30:58 +00:00
|
|
|
private func confirmRenameCurrentProfile(to newTitle: String) {
|
2020-02-28 17:32:04 +00:00
|
|
|
guard let profile = profile else {
|
2020-02-27 12:06:52 +00:00
|
|
|
return
|
|
|
|
}
|
2020-05-11 20:30:58 +00:00
|
|
|
if let existingProfile = service.hostProfile(withTitle: newTitle) {
|
|
|
|
let alert = UIAlertController.asAlert(L10n.Core.Service.Alerts.Rename.title, L10n.Core.Wizards.Host.Alerts.Existing.message)
|
|
|
|
alert.addPreferredAction(L10n.Core.Global.ok) {
|
|
|
|
self.doReplaceProfile(profile, to: newTitle, existingProfile: existingProfile)
|
|
|
|
}
|
|
|
|
alert.addCancelAction(L10n.Core.Global.cancel)
|
|
|
|
present(alert, animated: true, completion: nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
doRenameProfile(profile, to: newTitle)
|
|
|
|
}
|
|
|
|
|
|
|
|
private func doReplaceProfile(_ profile: ConnectionProfile, to newTitle: String, existingProfile: ConnectionProfile) {
|
|
|
|
let wasActive = service.isActiveProfile(existingProfile)
|
|
|
|
service.removeProfile(ProfileKey(existingProfile))
|
|
|
|
service.renameProfile(profile, to: newTitle)
|
|
|
|
if wasActive {
|
|
|
|
service.activateProfile(profile)
|
|
|
|
}
|
|
|
|
setProfile(profile, reloadingViews: true)
|
|
|
|
}
|
|
|
|
|
|
|
|
private func doRenameProfile(_ profile: ConnectionProfile, to newTitle: String) {
|
2020-02-28 17:32:04 +00:00
|
|
|
service.renameProfile(profile, to: newTitle)
|
|
|
|
setProfile(profile, reloadingViews: false)
|
2018-11-02 10:19:59 +00:00
|
|
|
}
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
private func toggleVpnService(cell: ToggleTableViewCell) {
|
|
|
|
if cell.isOn {
|
2019-03-19 16:12:24 +00:00
|
|
|
if #available(iOS 12, *) {
|
2020-02-28 17:32:04 +00:00
|
|
|
let title = service.screenTitle(ProfileKey(uncheckedProfile))
|
|
|
|
IntentDispatcher.donateConnection(with: uncheckedProfile, title: title)
|
2019-03-19 16:12:24 +00:00
|
|
|
}
|
2018-10-18 20:51:37 +00:00
|
|
|
guard !service.needsCredentials(for: uncheckedProfile) else {
|
2019-10-11 08:56:23 +00:00
|
|
|
let alert = UIAlertController.asAlert(
|
2019-06-21 21:15:43 +00:00
|
|
|
L10n.App.Service.Sections.Vpn.header,
|
|
|
|
L10n.Core.Service.Alerts.CredentialsNeeded.message
|
2018-10-11 07:13:19 +00:00
|
|
|
)
|
2019-06-21 21:15:43 +00:00
|
|
|
alert.addCancelAction(L10n.Core.Global.ok) {
|
2018-10-11 07:13:19 +00:00
|
|
|
cell.setOn(false, animated: true)
|
|
|
|
}
|
|
|
|
present(alert, animated: true, completion: nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
vpn.reconnect { (error) in
|
|
|
|
guard error == nil else {
|
2019-04-09 21:39:03 +00:00
|
|
|
|
|
|
|
// XXX: delay to avoid weird toggle state
|
2019-10-27 21:03:26 +00:00
|
|
|
delay {
|
2019-04-09 21:39:03 +00:00
|
|
|
cell.setOn(false, animated: true)
|
|
|
|
if error as? ApplicationError == .externalResources {
|
|
|
|
self.requireDownload()
|
|
|
|
}
|
|
|
|
}
|
2018-10-11 07:13:19 +00:00
|
|
|
return
|
|
|
|
}
|
2018-10-21 08:05:39 +00:00
|
|
|
self.reloadModel()
|
2019-03-10 13:29:31 +00:00
|
|
|
self.updateViewsIfNeeded()
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
} else {
|
2019-03-19 16:12:24 +00:00
|
|
|
if #available(iOS 12, *) {
|
|
|
|
IntentDispatcher.donateDisableVPN()
|
|
|
|
}
|
2018-10-11 07:13:19 +00:00
|
|
|
vpn.disconnect { (error) in
|
2018-10-21 08:05:39 +00:00
|
|
|
self.reloadModel()
|
2019-03-10 13:29:31 +00:00
|
|
|
self.updateViewsIfNeeded()
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private func confirmVpnReconnection() {
|
|
|
|
guard vpn.status == .disconnected else {
|
2019-10-11 08:56:23 +00:00
|
|
|
let alert = UIAlertController.asAlert(
|
2019-06-21 21:15:43 +00:00
|
|
|
L10n.Core.Service.Cells.ConnectionStatus.caption,
|
|
|
|
L10n.Core.Service.Alerts.ReconnectVpn.message
|
2018-10-11 07:13:19 +00:00
|
|
|
)
|
2019-10-11 08:56:23 +00:00
|
|
|
alert.addPreferredAction(L10n.Core.Global.ok) {
|
2018-10-11 07:13:19 +00:00
|
|
|
self.vpn.reconnect(completionHandler: nil)
|
|
|
|
}
|
2019-06-21 21:15:43 +00:00
|
|
|
alert.addCancelAction(L10n.Core.Global.cancel)
|
2018-10-11 07:13:19 +00:00
|
|
|
present(alert, animated: true, completion: nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
vpn.reconnect(completionHandler: nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
private func refreshProviderInfrastructure() {
|
2019-04-11 21:14:18 +00:00
|
|
|
let name = uncheckedProviderProfile.name
|
|
|
|
|
2019-10-11 08:56:23 +00:00
|
|
|
let hud = HUD(view: view.window!)
|
2019-12-02 09:46:59 +00:00
|
|
|
let isUpdating = InfrastructureFactory.shared.update(name, notBeforeInterval: AppConstants.Services.minimumUpdateInterval) { (response, error) in
|
2018-10-11 07:13:19 +00:00
|
|
|
hud.hide()
|
|
|
|
guard let response = response else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
self.lastInfrastructureUpdate = response.1
|
|
|
|
self.tableView.reloadData()
|
|
|
|
}
|
|
|
|
if !isUpdating {
|
|
|
|
hud.hide()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private func toggleDisconnectsOnSleep(_ isOn: Bool) {
|
|
|
|
service.preferences.disconnectsOnSleep = !isOn
|
|
|
|
if vpn.isEnabled {
|
|
|
|
vpn.reinstall(completionHandler: nil)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private func toggleResolvesHostname(_ isOn: Bool) {
|
|
|
|
service.preferences.resolvesHostname = isOn
|
|
|
|
if vpn.isEnabled {
|
|
|
|
guard vpn.status == .disconnected else {
|
|
|
|
confirmVpnReconnection()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
vpn.reinstall(completionHandler: nil)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-27 20:56:06 +00:00
|
|
|
private func trustMobileNetwork(cell: ToggleTableViewCell) {
|
2021-01-07 22:37:32 +00:00
|
|
|
do {
|
2021-02-02 16:51:09 +00:00
|
|
|
try ProductManager.shared.verifyEligible(forFeature: .trustedNetworks)
|
|
|
|
} catch ProductError.beta {
|
|
|
|
delay {
|
|
|
|
cell.setOn(false, animated: true)
|
2021-01-07 22:37:32 +00:00
|
|
|
}
|
2021-02-02 16:51:09 +00:00
|
|
|
presentBetaFeatureUnavailable("Trusted networks")
|
|
|
|
return
|
2021-01-07 22:37:32 +00:00
|
|
|
} catch {
|
2019-10-28 09:14:03 +00:00
|
|
|
delay {
|
|
|
|
cell.setOn(false, animated: true)
|
|
|
|
}
|
2021-02-02 16:51:09 +00:00
|
|
|
presentPurchaseScreen(forProduct: .trustedNetworks)
|
2019-10-28 09:14:03 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-10-27 20:56:06 +00:00
|
|
|
if #available(iOS 12, *) {
|
|
|
|
IntentDispatcher.donateTrustCellularNetwork()
|
|
|
|
IntentDispatcher.donateUntrustCellularNetwork()
|
|
|
|
}
|
|
|
|
|
|
|
|
trustedNetworks.setMobile(cell.isOn)
|
|
|
|
}
|
|
|
|
|
2019-10-20 22:25:02 +00:00
|
|
|
private func trustCurrentWiFi() {
|
2021-01-07 22:37:32 +00:00
|
|
|
do {
|
2021-02-02 16:51:09 +00:00
|
|
|
try ProductManager.shared.verifyEligible(forFeature: .trustedNetworks)
|
|
|
|
} catch ProductError.beta {
|
2021-01-07 22:37:32 +00:00
|
|
|
presentBetaFeatureUnavailable("Trusted networks")
|
2019-10-28 09:14:03 +00:00
|
|
|
return
|
2021-02-02 16:51:09 +00:00
|
|
|
} catch {
|
|
|
|
presentPurchaseScreen(forProduct: .trustedNetworks)
|
|
|
|
return
|
2019-10-28 09:14:03 +00:00
|
|
|
}
|
|
|
|
|
2019-10-20 22:01:40 +00:00
|
|
|
if #available(iOS 13, *) {
|
2020-11-21 18:03:10 +00:00
|
|
|
switch CLLocationManager.authorizationStatus() {
|
2019-10-20 22:01:40 +00:00
|
|
|
case .authorizedAlways, .authorizedWhenInUse:
|
|
|
|
break
|
|
|
|
|
|
|
|
case .denied:
|
2019-10-20 22:30:49 +00:00
|
|
|
isPendingTrustedWiFi = false
|
2019-10-20 22:17:25 +00:00
|
|
|
let alert = UIAlertController.asAlert(
|
|
|
|
L10n.App.Service.Cells.TrustedAddWifi.caption,
|
2019-10-20 22:20:04 +00:00
|
|
|
L10n.App.Service.Alerts.Location.Message.denied
|
2019-10-20 22:17:25 +00:00
|
|
|
)
|
|
|
|
alert.addCancelAction(L10n.Core.Global.ok)
|
2019-10-20 22:20:04 +00:00
|
|
|
alert.addPreferredAction(L10n.App.Service.Alerts.Location.Button.settings) {
|
2019-10-20 22:17:25 +00:00
|
|
|
UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!, options: [:], completionHandler: nil)
|
|
|
|
}
|
|
|
|
present(alert, animated: true, completion: nil)
|
2019-10-20 22:25:02 +00:00
|
|
|
return
|
2019-10-20 22:01:40 +00:00
|
|
|
|
|
|
|
default:
|
2019-10-20 22:30:49 +00:00
|
|
|
isPendingTrustedWiFi = true
|
2019-10-20 22:17:25 +00:00
|
|
|
locationManager.delegate = self
|
2019-10-20 22:01:40 +00:00
|
|
|
locationManager.requestWhenInUseAuthorization()
|
2019-10-20 22:25:02 +00:00
|
|
|
return
|
2019-10-20 22:01:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-20 21:55:05 +00:00
|
|
|
if #available(iOS 12, *) {
|
|
|
|
IntentDispatcher.donateTrustCurrentNetwork()
|
|
|
|
IntentDispatcher.donateUntrustCurrentNetwork()
|
|
|
|
}
|
|
|
|
|
2020-12-27 21:21:50 +00:00
|
|
|
let alert = UIAlertController.asAlert(L10n.Core.Service.Sections.Trusted.header, nil)
|
|
|
|
alert.addTextField { (field) in
|
|
|
|
field.text = Utils.currentWifiNetworkName() ?? ""
|
2020-12-28 21:06:44 +00:00
|
|
|
field.applyWiFiTitle(.current)
|
2020-12-27 21:21:50 +00:00
|
|
|
field.delegate = self
|
|
|
|
}
|
|
|
|
alert.addCancelAction(L10n.Core.Global.cancel)
|
2020-12-28 21:06:44 +00:00
|
|
|
alert.addPreferredAction(L10n.App.Service.Cells.TrustedAddWifi.caption) {
|
2020-12-27 21:21:50 +00:00
|
|
|
guard let wifi = alert.textFields?.first?.text else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
self.trustedNetworks.addWifi(wifi)
|
2019-10-20 21:55:05 +00:00
|
|
|
}
|
2020-12-27 21:21:50 +00:00
|
|
|
present(alert, animated: true, completion: nil)
|
2019-10-20 21:55:05 +00:00
|
|
|
}
|
|
|
|
|
2019-10-27 20:56:06 +00:00
|
|
|
private func toggleTrustWiFi(cell: ToggleTableViewCell, at row: Int) {
|
2021-01-07 22:37:32 +00:00
|
|
|
do {
|
2021-02-02 16:51:09 +00:00
|
|
|
try ProductManager.shared.verifyEligible(forFeature: .trustedNetworks)
|
|
|
|
} catch ProductError.beta {
|
|
|
|
delay {
|
|
|
|
cell.setOn(false, animated: true)
|
2021-01-07 22:37:32 +00:00
|
|
|
}
|
2021-02-02 16:51:09 +00:00
|
|
|
presentBetaFeatureUnavailable("Trusted networks")
|
|
|
|
return
|
2021-01-07 22:37:32 +00:00
|
|
|
} catch {
|
2019-10-28 09:14:03 +00:00
|
|
|
delay {
|
|
|
|
cell.setOn(false, animated: true)
|
|
|
|
}
|
2021-02-02 16:51:09 +00:00
|
|
|
presentPurchaseScreen(forProduct: .trustedNetworks)
|
2019-10-28 09:14:03 +00:00
|
|
|
return
|
|
|
|
}
|
2021-01-07 22:37:32 +00:00
|
|
|
|
2019-10-27 20:56:06 +00:00
|
|
|
if cell.isOn {
|
|
|
|
trustedNetworks.enableWifi(at: row)
|
|
|
|
} else {
|
|
|
|
trustedNetworks.disableWifi(at: row)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-03 21:39:07 +00:00
|
|
|
private func toggleTrustedConnectionPolicy(_ isOn: Bool, sender: ToggleTableViewCell) {
|
2018-10-11 07:13:19 +00:00
|
|
|
let completionHandler: () -> Void = {
|
2019-11-21 08:28:28 +00:00
|
|
|
self.uncheckedProfile.trustedNetworks.policy = isOn ? .disconnect : .ignore
|
2018-10-11 07:13:19 +00:00
|
|
|
if self.vpn.isEnabled {
|
|
|
|
self.vpn.reinstall(completionHandler: nil)
|
|
|
|
}
|
|
|
|
}
|
2018-11-03 21:39:07 +00:00
|
|
|
guard isOn else {
|
2018-10-11 07:13:19 +00:00
|
|
|
completionHandler()
|
|
|
|
return
|
|
|
|
}
|
2018-10-23 21:56:53 +00:00
|
|
|
guard vpn.isEnabled else {
|
|
|
|
completionHandler()
|
|
|
|
return
|
|
|
|
}
|
2019-10-11 08:56:23 +00:00
|
|
|
let alert = UIAlertController.asAlert(
|
2019-06-21 21:15:43 +00:00
|
|
|
L10n.Core.Service.Sections.Trusted.header,
|
|
|
|
L10n.Core.Service.Alerts.Trusted.WillDisconnectPolicy.message
|
2018-10-11 07:13:19 +00:00
|
|
|
)
|
2019-10-11 08:56:23 +00:00
|
|
|
alert.addPreferredAction(L10n.Core.Global.ok) {
|
2018-10-11 07:13:19 +00:00
|
|
|
completionHandler()
|
|
|
|
}
|
2019-06-21 21:15:43 +00:00
|
|
|
alert.addCancelAction(L10n.Core.Global.cancel) {
|
2018-11-03 21:39:07 +00:00
|
|
|
sender.setOn(false, animated: true)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
present(alert, animated: true, completion: nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
private func confirmPotentialTrustedDisconnection(at rowIndex: Int?, completionHandler: @escaping () -> Void) {
|
2019-10-11 08:56:23 +00:00
|
|
|
let alert = UIAlertController.asAlert(
|
2019-06-21 21:15:43 +00:00
|
|
|
L10n.Core.Service.Sections.Trusted.header,
|
|
|
|
L10n.Core.Service.Alerts.Trusted.WillDisconnectTrusted.message
|
2018-10-11 07:13:19 +00:00
|
|
|
)
|
2019-10-11 08:56:23 +00:00
|
|
|
alert.addPreferredAction(L10n.Core.Global.ok) {
|
2018-10-11 07:13:19 +00:00
|
|
|
completionHandler()
|
|
|
|
}
|
2019-06-21 21:15:43 +00:00
|
|
|
alert.addCancelAction(L10n.Core.Global.cancel) {
|
2018-10-11 07:13:19 +00:00
|
|
|
guard let rowIndex = rowIndex else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
let indexPath = IndexPath(row: rowIndex, section: self.trustedSectionIndex)
|
|
|
|
let cell = self.tableView.cellForRow(at: indexPath) as? ToggleTableViewCell
|
|
|
|
cell?.setOn(false, animated: true)
|
|
|
|
}
|
|
|
|
present(alert, animated: true, completion: nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
private func testInternetConnectivity() {
|
2019-10-11 08:56:23 +00:00
|
|
|
let hud = HUD(view: view.window!)
|
2019-12-02 09:46:59 +00:00
|
|
|
Utils.checkConnectivityURL(AppConstants.Services.connectivityURL, timeout: AppConstants.Services.connectivityTimeout) {
|
2018-10-11 07:13:19 +00:00
|
|
|
hud.hide()
|
|
|
|
|
2019-06-21 21:15:43 +00:00
|
|
|
let V = L10n.Core.Service.Alerts.TestConnectivity.Messages.self
|
2019-10-11 08:56:23 +00:00
|
|
|
let alert = UIAlertController.asAlert(
|
2019-06-21 21:15:43 +00:00
|
|
|
L10n.Core.Service.Alerts.TestConnectivity.title,
|
2018-10-11 07:13:19 +00:00
|
|
|
$0 ? V.success : V.failure
|
|
|
|
)
|
2019-06-21 21:15:43 +00:00
|
|
|
alert.addCancelAction(L10n.Core.Global.ok)
|
2018-10-11 07:13:19 +00:00
|
|
|
self.present(alert, animated: true, completion: nil)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-29 10:17:50 +00:00
|
|
|
// private func displayDataCount() {
|
|
|
|
// guard vpn.isEnabled else {
|
2019-10-11 08:56:23 +00:00
|
|
|
// let alert = UIAlertController.asAlert(
|
2019-06-21 21:15:43 +00:00
|
|
|
// L10n.Core.Service.Cells.DataCount.caption,
|
|
|
|
// L10n.Core.Service.Alerts.DataCount.Messages.notAvailable
|
2019-03-29 10:17:50 +00:00
|
|
|
// )
|
2019-06-21 21:15:43 +00:00
|
|
|
// alert.addCancelAction(L10n.Core.Global.ok)
|
2019-03-29 10:17:50 +00:00
|
|
|
// present(alert, animated: true, completion: nil)
|
|
|
|
// return
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// vpn.requestBytesCount {
|
|
|
|
// let message: String
|
|
|
|
// if let count = $0 {
|
2019-06-21 21:15:43 +00:00
|
|
|
// message = L10n.Core.Service.Alerts.DataCount.Messages.current(Int(count.0), Int(count.1))
|
2019-03-29 10:17:50 +00:00
|
|
|
// } else {
|
2019-06-21 21:15:43 +00:00
|
|
|
// message = L10n.Core.Service.Alerts.DataCount.Messages.notAvailable
|
2019-03-29 10:17:50 +00:00
|
|
|
// }
|
2019-10-11 08:56:23 +00:00
|
|
|
// let alert = UIAlertController.asAlert(
|
2019-06-21 21:15:43 +00:00
|
|
|
// L10n.Core.Service.Cells.DataCount.caption,
|
2019-03-29 10:17:50 +00:00
|
|
|
// message
|
|
|
|
// )
|
2019-06-21 21:15:43 +00:00
|
|
|
// alert.addCancelAction(L10n.Core.Global.ok)
|
2019-03-29 10:17:50 +00:00
|
|
|
// self.present(alert, animated: true, completion: nil)
|
|
|
|
// }
|
|
|
|
// }
|
2019-03-21 20:31:13 +00:00
|
|
|
|
2019-10-23 08:17:56 +00:00
|
|
|
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
|
2019-11-19 23:54:04 +00:00
|
|
|
vc.isServerPushed = true
|
2019-10-23 08:17:56 +00:00
|
|
|
self?.navigationController?.pushViewController(vc, animated: true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private func discloseServerNetwork() {
|
|
|
|
let caption = L10n.Core.Service.Cells.ServerNetwork.caption
|
|
|
|
tryRequestServerConfiguration(withCaption: caption) { [weak self] in
|
2019-10-23 08:52:15 +00:00
|
|
|
let vc = StoryboardScene.Main.serverNetworkViewController.instantiate()
|
2019-10-23 08:17:56 +00:00
|
|
|
vc.title = caption
|
2019-10-23 08:52:15 +00:00
|
|
|
vc.configuration = $0
|
2019-10-23 08:17:56 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-21 20:31:13 +00:00
|
|
|
private func togglePrivateDataMasking(cell: ToggleTableViewCell) {
|
2019-03-22 18:16:39 +00:00
|
|
|
let handler = {
|
|
|
|
TransientStore.masksPrivateData = cell.isOn
|
|
|
|
self.service.baseConfiguration = TransientStore.baseVPNConfiguration.build()
|
|
|
|
}
|
|
|
|
|
|
|
|
guard vpn.status == .disconnected else {
|
2019-10-11 08:56:23 +00:00
|
|
|
let alert = UIAlertController.asAlert(
|
2019-06-21 21:15:43 +00:00
|
|
|
L10n.Core.Service.Cells.MasksPrivateData.caption,
|
|
|
|
L10n.Core.Service.Alerts.MasksPrivateData.Messages.mustReconnect
|
2019-03-22 18:16:39 +00:00
|
|
|
)
|
2019-06-21 21:15:43 +00:00
|
|
|
alert.addDestructiveAction(L10n.Core.Service.Alerts.Buttons.reconnect) {
|
2019-03-22 18:16:39 +00:00
|
|
|
handler()
|
|
|
|
self.shouldDeleteLogOnDisconnection = true
|
2019-03-22 18:25:01 +00:00
|
|
|
self.vpn.reconnect(completionHandler: nil)
|
2019-03-22 18:16:39 +00:00
|
|
|
}
|
2019-06-21 21:15:43 +00:00
|
|
|
alert.addCancelAction(L10n.Core.Global.cancel) {
|
2019-03-22 18:16:39 +00:00
|
|
|
cell.setOn(!cell.isOn, animated: true)
|
|
|
|
}
|
|
|
|
present(alert, animated: true, completion: nil)
|
|
|
|
return
|
2019-03-21 20:27:24 +00:00
|
|
|
}
|
2019-03-22 18:16:39 +00:00
|
|
|
|
|
|
|
handler()
|
|
|
|
service.eraseVpnLog()
|
|
|
|
shouldDeleteLogOnDisconnection = false
|
2019-03-21 20:31:13 +00:00
|
|
|
}
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2018-10-22 20:42:42 +00:00
|
|
|
private func reportConnectivityIssue() {
|
2019-09-05 20:50:56 +00:00
|
|
|
let issue = Issue(debugLog: true, profile: uncheckedProfile)
|
|
|
|
IssueReporter.shared.present(in: self, withIssue: issue)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
2019-04-09 21:39:03 +00:00
|
|
|
private func requireDownload() {
|
|
|
|
guard let providerProfile = profile as? ProviderConnectionProfile else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
guard let downloadURL = AppConstants.URLs.externalResources[providerProfile.name] else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-10-11 08:56:23 +00:00
|
|
|
let alert = UIAlertController.asAlert(
|
2019-06-21 21:15:43 +00:00
|
|
|
L10n.Core.Service.Alerts.Download.title,
|
2019-11-23 13:22:34 +00:00
|
|
|
L10n.Core.Service.Alerts.Download.message(providerProfile.name)
|
2019-04-09 21:39:03 +00:00
|
|
|
)
|
2019-06-21 21:15:43 +00:00
|
|
|
alert.addCancelAction(L10n.Core.Global.cancel)
|
2019-10-11 08:56:23 +00:00
|
|
|
alert.addPreferredAction(L10n.Core.Global.ok) {
|
2019-04-10 13:27:18 +00:00
|
|
|
self.confirmDownload(URL(string: downloadURL)!)
|
2019-04-09 21:39:03 +00:00
|
|
|
}
|
|
|
|
present(alert, animated: true, completion: nil)
|
|
|
|
}
|
|
|
|
|
2019-04-10 13:27:18 +00:00
|
|
|
private func confirmDownload(_ url: URL) {
|
2019-10-11 08:56:23 +00:00
|
|
|
_ = downloader.download(url: url, in: view) { (url, error) in
|
2019-04-11 15:29:52 +00:00
|
|
|
self.handleDownloadedProviderResources(url: url, error: error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private func handleDownloadedProviderResources(url: URL?, error: Error?) {
|
|
|
|
guard let url = url else {
|
2019-10-11 08:56:23 +00:00
|
|
|
let alert = UIAlertController.asAlert(
|
2019-06-21 21:15:43 +00:00
|
|
|
L10n.Core.Service.Alerts.Download.title,
|
|
|
|
L10n.Core.Service.Alerts.Download.failed(error?.localizedDescription ?? "")
|
2019-04-11 15:29:52 +00:00
|
|
|
)
|
2019-06-21 21:15:43 +00:00
|
|
|
alert.addCancelAction(L10n.Core.Global.ok)
|
2019-04-11 15:29:52 +00:00
|
|
|
present(alert, animated: true, completion: nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-10-11 08:56:23 +00:00
|
|
|
let hud = HUD(view: view.window!, label: L10n.Core.Service.Alerts.Download.Hud.extracting)
|
2019-04-11 15:29:52 +00:00
|
|
|
hud.show()
|
|
|
|
uncheckedProviderProfile.name.importExternalResources(from: url) {
|
|
|
|
hud.hide()
|
2019-04-10 13:27:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
// MARK: Notifications
|
|
|
|
|
|
|
|
@objc private func vpnDidUpdate() {
|
|
|
|
reloadVpnStatus()
|
2018-12-10 11:42:50 +00:00
|
|
|
|
2019-03-21 20:27:24 +00:00
|
|
|
guard let status = vpn.status else {
|
|
|
|
return
|
|
|
|
}
|
2020-05-09 15:33:04 +00:00
|
|
|
log.debug("VPN.status: \(status)")
|
2019-03-21 20:27:24 +00:00
|
|
|
switch status {
|
|
|
|
case .connected:
|
2018-12-10 11:42:50 +00:00
|
|
|
Reviewer.shared.reportEvent()
|
2019-03-21 20:27:24 +00:00
|
|
|
|
|
|
|
case .disconnected:
|
|
|
|
if shouldDeleteLogOnDisconnection {
|
|
|
|
service.eraseVpnLog()
|
|
|
|
shouldDeleteLogOnDisconnection = false
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break
|
2018-12-10 11:42:50 +00:00
|
|
|
}
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
2019-03-09 07:58:01 +00:00
|
|
|
@objc private func intentDidUpdateService() {
|
2019-03-09 11:07:34 +00:00
|
|
|
setProfile(service.activeProfile)
|
2019-03-09 07:58:01 +00:00
|
|
|
}
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
@objc private func applicationDidBecomeActive() {
|
2019-03-10 13:32:24 +00:00
|
|
|
reloadModel()
|
|
|
|
updateViewsIfNeeded()
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
2019-03-29 10:17:50 +00:00
|
|
|
|
|
|
|
@objc private func serviceDidUpdateDataCount(_ notification: Notification) {
|
|
|
|
guard let dataCount = notification.userInfo?[ConnectionService.NotificationKeys.dataCount] as? (Int, Int) else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
refreshDataCount(dataCount)
|
|
|
|
}
|
2019-11-02 10:28:35 +00:00
|
|
|
|
|
|
|
@objc private func productManagerDidReloadReceipt() {
|
|
|
|
reloadModel()
|
|
|
|
tableView.reloadData()
|
|
|
|
}
|
2019-11-09 12:06:13 +00:00
|
|
|
|
|
|
|
@objc private func productManagerDidReviewPurchases() {
|
|
|
|
hideProfileIfDeleted()
|
|
|
|
}
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: -
|
|
|
|
|
|
|
|
extension ServiceViewController: UITableViewDataSource, UITableViewDelegate, ToggleTableViewCellDelegate {
|
|
|
|
enum SectionType {
|
|
|
|
case vpn
|
|
|
|
|
|
|
|
case authentication
|
|
|
|
|
|
|
|
case hostProfile
|
|
|
|
|
|
|
|
case configuration
|
|
|
|
|
|
|
|
case providerInfrastructure
|
|
|
|
|
|
|
|
case vpnResolvesHostname
|
|
|
|
|
|
|
|
case vpnSurvivesSleep
|
|
|
|
|
|
|
|
case trusted
|
|
|
|
|
|
|
|
case trustedPolicy
|
|
|
|
|
|
|
|
case diagnostics
|
|
|
|
|
2018-10-18 14:53:37 +00:00
|
|
|
case feedback
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enum RowType: Int {
|
2018-10-21 07:45:59 +00:00
|
|
|
case useProfile
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case vpnService
|
|
|
|
|
|
|
|
case connectionStatus
|
|
|
|
|
2018-10-21 07:45:59 +00:00
|
|
|
case reconnect
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case account
|
|
|
|
|
|
|
|
case endpoint
|
|
|
|
|
|
|
|
case providerPool
|
|
|
|
|
|
|
|
case providerPreset
|
|
|
|
|
|
|
|
case providerRefresh
|
|
|
|
|
|
|
|
case hostParameters
|
|
|
|
|
2019-04-29 16:13:49 +00:00
|
|
|
case networkSettings
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case vpnResolvesHostname
|
|
|
|
|
|
|
|
case vpnSurvivesSleep
|
|
|
|
|
|
|
|
case trustedMobile
|
|
|
|
|
|
|
|
case trustedWiFi
|
|
|
|
|
|
|
|
case trustedAddCurrentWiFi
|
|
|
|
|
|
|
|
case trustedPolicy
|
|
|
|
|
|
|
|
case testConnectivity
|
|
|
|
|
|
|
|
case dataCount
|
|
|
|
|
2019-10-23 08:17:56 +00:00
|
|
|
case serverConfiguration
|
|
|
|
|
|
|
|
case serverNetwork
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case debugLog
|
|
|
|
|
2019-03-21 20:31:13 +00:00
|
|
|
case masksPrivateData
|
|
|
|
|
2019-11-19 22:33:51 +00:00
|
|
|
case faq
|
|
|
|
|
2018-10-22 20:42:42 +00:00
|
|
|
case reportIssue
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private var trustedSectionIndex: Int {
|
|
|
|
return model.index(ofSection: .trusted)
|
|
|
|
}
|
|
|
|
|
2019-03-05 09:14:21 +00:00
|
|
|
private var statusIndexPath: IndexPath? {
|
2019-10-11 08:56:23 +00:00
|
|
|
return model.indexPath(forRow: .connectionStatus, ofSection: .vpn)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
2019-03-29 10:17:50 +00:00
|
|
|
private var dataCountIndexPath: IndexPath? {
|
2019-10-11 08:56:23 +00:00
|
|
|
return model.indexPath(forRow: .dataCount, ofSection: .diagnostics)
|
2019-03-29 10:17:50 +00:00
|
|
|
}
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
private var endpointIndexPath: IndexPath {
|
2019-10-11 08:56:23 +00:00
|
|
|
guard let ip = model.indexPath(forRow: .endpoint, ofSection: .configuration) else {
|
2018-10-11 07:13:19 +00:00
|
|
|
fatalError("Could not locate endpointIndexPath")
|
|
|
|
}
|
|
|
|
return ip
|
|
|
|
}
|
|
|
|
|
2019-05-02 10:51:40 +00:00
|
|
|
private var providerPresetIndexPath: IndexPath {
|
2019-10-11 08:56:23 +00:00
|
|
|
guard let ip = model.indexPath(forRow: .providerPreset, ofSection: .configuration) else {
|
2019-05-02 10:51:40 +00:00
|
|
|
fatalError("Could not locate presetIndexPath")
|
|
|
|
}
|
|
|
|
return ip
|
|
|
|
}
|
|
|
|
|
2019-11-21 08:15:24 +00:00
|
|
|
private func mappedTrustedNetworksRow(_ from: TrustedNetworksUI.RowType) -> RowType {
|
2019-03-18 10:52:19 +00:00
|
|
|
switch from {
|
|
|
|
case .trustsMobile:
|
|
|
|
return .trustedMobile
|
|
|
|
|
|
|
|
case .trustedWiFi:
|
|
|
|
return .trustedWiFi
|
|
|
|
|
|
|
|
case .addCurrentWiFi:
|
|
|
|
return .trustedAddCurrentWiFi
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
func numberOfSections(in tableView: UITableView) -> Int {
|
2019-10-11 08:56:23 +00:00
|
|
|
return model.numberOfSections
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
2019-10-11 08:56:23 +00:00
|
|
|
return model.header(forSection: section)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
|
2019-10-11 08:56:23 +00:00
|
|
|
let rows = model.rows(forSection: section)
|
2018-10-11 07:13:19 +00:00
|
|
|
if rows.contains(.providerRefresh), let date = lastInfrastructureUpdate {
|
2019-06-21 21:15:43 +00:00
|
|
|
return L10n.Core.Service.Sections.ProviderInfrastructure.footer(date.timestamp)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
2019-10-11 08:56:23 +00:00
|
|
|
return model.footer(forSection: section)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
2019-04-04 17:53:08 +00:00
|
|
|
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
|
|
|
|
return model.headerHeight(for: section)
|
|
|
|
}
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
2019-10-11 08:56:23 +00:00
|
|
|
return model.numberOfRows(forSection: section)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
|
|
let row = model.row(at: indexPath)
|
|
|
|
switch row {
|
2018-10-21 07:45:59 +00:00
|
|
|
case .useProfile:
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
2019-10-25 17:30:21 +00:00
|
|
|
cell.applyAction(.current)
|
2020-11-18 14:13:06 +00:00
|
|
|
cell.leftText = L10n.Core.Service.Cells.UseProfile.caption
|
2018-10-21 07:45:59 +00:00
|
|
|
return cell
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case .vpnService:
|
|
|
|
guard service.isActiveProfile(uncheckedProfile) else {
|
|
|
|
fatalError("Do not show vpnService in non-active profile")
|
|
|
|
}
|
|
|
|
|
|
|
|
let cell = Cells.toggle.dequeue(from: tableView, for: indexPath, tag: row.rawValue, delegate: self)
|
2019-06-21 21:15:43 +00:00
|
|
|
cell.caption = L10n.App.Service.Cells.VpnService.caption
|
2018-10-11 07:13:19 +00:00
|
|
|
cell.isOn = vpn.isEnabled
|
|
|
|
return cell
|
|
|
|
|
|
|
|
case .connectionStatus:
|
|
|
|
guard service.isActiveProfile(uncheckedProfile) else {
|
|
|
|
fatalError("Do not show connectionStatus in non-active profile")
|
|
|
|
}
|
|
|
|
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
2019-10-25 17:30:21 +00:00
|
|
|
cell.applyVPN(.current, with: vpn.isEnabled ? vpn.status : nil, error: service.vpnLastError)
|
2019-06-21 21:15:43 +00:00
|
|
|
cell.leftText = L10n.Core.Service.Cells.ConnectionStatus.caption
|
2018-10-11 07:13:19 +00:00
|
|
|
cell.accessoryType = .none
|
2018-10-21 08:05:39 +00:00
|
|
|
cell.isTappable = false
|
2018-10-11 07:13:19 +00:00
|
|
|
return cell
|
|
|
|
|
2018-10-21 07:45:59 +00:00
|
|
|
case .reconnect:
|
2018-10-11 07:13:19 +00:00
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
2019-10-25 17:30:21 +00:00
|
|
|
cell.applyAction(.current)
|
2019-07-04 08:50:14 +00:00
|
|
|
cell.leftText = L10n.Core.Service.Cells.Reconnect.caption
|
2018-10-21 07:45:59 +00:00
|
|
|
cell.accessoryType = .none
|
|
|
|
cell.isTappable = !service.needsCredentials(for: uncheckedProfile) && vpn.isEnabled
|
2018-10-11 07:13:19 +00:00
|
|
|
return cell
|
|
|
|
|
|
|
|
// shared cells
|
|
|
|
|
|
|
|
case .account:
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
2019-06-21 21:15:43 +00:00
|
|
|
cell.leftText = L10n.Core.Account.title
|
2018-10-11 07:13:19 +00:00
|
|
|
cell.rightText = profile?.username
|
|
|
|
return cell
|
|
|
|
|
|
|
|
case .endpoint:
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
2019-06-21 21:15:43 +00:00
|
|
|
cell.leftText = L10n.Core.Endpoint.title
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2019-06-21 21:15:43 +00:00
|
|
|
let V = L10n.Core.Global.Values.self
|
2018-10-11 07:13:19 +00:00
|
|
|
if let provider = profile as? ProviderConnectionProfile {
|
2020-05-23 17:06:44 +00:00
|
|
|
cell.rightText = provider.usesCustomEndpoint ? V.manual : V.automatic
|
2018-10-11 07:13:19 +00:00
|
|
|
} else {
|
|
|
|
cell.rightText = profile?.mainAddress
|
|
|
|
}
|
|
|
|
return cell
|
|
|
|
|
2019-04-29 16:13:49 +00:00
|
|
|
case .networkSettings:
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
2019-06-21 21:15:43 +00:00
|
|
|
cell.leftText = L10n.Core.NetworkSettings.title
|
2019-04-29 16:13:49 +00:00
|
|
|
return cell
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
// provider cells
|
|
|
|
|
|
|
|
case .providerPool:
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
2019-06-21 21:15:43 +00:00
|
|
|
cell.leftText = L10n.Core.Service.Cells.Provider.Pool.caption
|
2019-04-06 12:48:22 +00:00
|
|
|
cell.rightText = uncheckedProviderProfile.pool?.localizedId
|
2018-10-11 07:13:19 +00:00
|
|
|
return cell
|
|
|
|
|
|
|
|
case .providerPreset:
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
2019-06-21 21:15:43 +00:00
|
|
|
cell.leftText = L10n.Core.Service.Cells.Provider.Preset.caption
|
2018-10-11 07:13:19 +00:00
|
|
|
cell.rightText = uncheckedProviderProfile.preset?.name // XXX: localize?
|
|
|
|
return cell
|
|
|
|
|
|
|
|
case .providerRefresh:
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
2019-10-25 17:30:21 +00:00
|
|
|
cell.applyAction(.current)
|
2019-06-21 21:15:43 +00:00
|
|
|
cell.leftText = L10n.App.Service.Cells.Provider.Refresh.caption
|
2018-10-11 07:13:19 +00:00
|
|
|
return cell
|
|
|
|
|
|
|
|
// host cells
|
|
|
|
|
|
|
|
case .hostParameters:
|
|
|
|
let parameters = uncheckedHostProfile.parameters
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
2019-06-21 21:15:43 +00:00
|
|
|
cell.leftText = L10n.App.Service.Cells.Host.Parameters.caption
|
2019-04-04 11:23:20 +00:00
|
|
|
if !parameters.sessionConfiguration.fallbackCipher.embedsDigest {
|
2019-04-23 13:19:53 +00:00
|
|
|
cell.rightText = "\(parameters.sessionConfiguration.fallbackCipher.genericName) / \(parameters.sessionConfiguration.fallbackDigest.genericName)"
|
2018-10-11 07:13:19 +00:00
|
|
|
} else {
|
2019-04-23 13:19:53 +00:00
|
|
|
cell.rightText = parameters.sessionConfiguration.fallbackCipher.genericName
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
return cell
|
|
|
|
|
|
|
|
// VPN preferences
|
|
|
|
|
|
|
|
case .vpnResolvesHostname:
|
|
|
|
let cell = Cells.toggle.dequeue(from: tableView, for: indexPath, tag: row.rawValue, delegate: self)
|
2019-06-21 21:15:43 +00:00
|
|
|
cell.caption = L10n.Core.Service.Cells.VpnResolvesHostname.caption
|
2018-10-11 07:13:19 +00:00
|
|
|
cell.isOn = service.preferences.resolvesHostname
|
|
|
|
return cell
|
|
|
|
|
|
|
|
case .vpnSurvivesSleep:
|
|
|
|
let cell = Cells.toggle.dequeue(from: tableView, for: indexPath, tag: row.rawValue, delegate: self)
|
2019-06-21 21:15:43 +00:00
|
|
|
cell.caption = L10n.Core.Service.Cells.VpnSurvivesSleep.caption
|
2018-10-11 07:13:19 +00:00
|
|
|
cell.isOn = !service.preferences.disconnectsOnSleep
|
|
|
|
return cell
|
|
|
|
|
|
|
|
case .trustedMobile:
|
|
|
|
let cell = Cells.toggle.dequeue(from: tableView, for: indexPath, tag: row.rawValue, delegate: self)
|
2019-06-21 21:15:43 +00:00
|
|
|
cell.caption = L10n.Core.Service.Cells.TrustedMobile.caption
|
2019-11-21 08:28:28 +00:00
|
|
|
cell.isOn = uncheckedProfile.trustedNetworks.includesMobile
|
2018-10-11 07:13:19 +00:00
|
|
|
return cell
|
|
|
|
|
|
|
|
case .trustedWiFi:
|
|
|
|
let wifi = trustedNetworks.wifi(at: indexPath.row)
|
|
|
|
let cell = Cells.toggle.dequeue(from: tableView, for: indexPath, tag: row.rawValue, delegate: self)
|
2019-04-23 13:19:53 +00:00
|
|
|
cell.caption = wifi.0
|
2018-10-11 07:13:19 +00:00
|
|
|
cell.isOn = wifi.1
|
|
|
|
return cell
|
|
|
|
|
|
|
|
case .trustedAddCurrentWiFi:
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
2019-10-25 17:30:21 +00:00
|
|
|
cell.applyAction(.current)
|
2019-06-21 21:15:43 +00:00
|
|
|
cell.leftText = L10n.App.Service.Cells.TrustedAddWifi.caption
|
2018-10-11 07:13:19 +00:00
|
|
|
return cell
|
|
|
|
|
|
|
|
case .trustedPolicy:
|
|
|
|
let cell = Cells.toggle.dequeue(from: tableView, for: indexPath, tag: row.rawValue, delegate: self)
|
2019-06-21 21:15:43 +00:00
|
|
|
cell.caption = L10n.Core.Service.Cells.TrustedPolicy.caption
|
2019-11-21 08:28:28 +00:00
|
|
|
cell.isOn = (uncheckedProfile.trustedNetworks.policy == .disconnect)
|
2018-10-11 07:13:19 +00:00
|
|
|
return cell
|
|
|
|
|
|
|
|
// diagnostics
|
|
|
|
|
|
|
|
case .testConnectivity:
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
2019-06-21 21:15:43 +00:00
|
|
|
cell.leftText = L10n.Core.Service.Cells.TestConnectivity.caption
|
2018-10-11 07:13:19 +00:00
|
|
|
return cell
|
|
|
|
|
|
|
|
case .dataCount:
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
2019-06-21 21:15:43 +00:00
|
|
|
cell.leftText = L10n.Core.Service.Cells.DataCount.caption
|
2019-03-29 10:17:50 +00:00
|
|
|
if let count = currentDataCount, vpn.status == .connected {
|
2019-04-23 13:19:53 +00:00
|
|
|
let down = count.0.dataUnitDescription
|
|
|
|
let up = count.1.dataUnitDescription
|
|
|
|
cell.rightText = "↓\(down) / ↑\(up)"
|
2019-03-29 10:17:50 +00:00
|
|
|
} else {
|
2019-06-21 21:15:43 +00:00
|
|
|
cell.rightText = L10n.Core.Service.Cells.DataCount.none
|
2019-03-29 10:17:50 +00:00
|
|
|
}
|
|
|
|
cell.accessoryType = .none
|
|
|
|
cell.isTappable = false
|
2018-10-11 07:13:19 +00:00
|
|
|
return cell
|
2019-10-23 08:17:56 +00:00
|
|
|
|
|
|
|
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
|
2018-10-11 07:13:19 +00:00
|
|
|
|
|
|
|
case .debugLog:
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
2019-06-21 21:15:43 +00:00
|
|
|
cell.leftText = L10n.Core.Service.Cells.DebugLog.caption
|
2018-10-11 07:13:19 +00:00
|
|
|
return cell
|
|
|
|
|
2019-03-21 20:31:13 +00:00
|
|
|
case .masksPrivateData:
|
|
|
|
let cell = Cells.toggle.dequeue(from: tableView, for: indexPath, tag: row.rawValue, delegate: self)
|
2019-06-21 21:15:43 +00:00
|
|
|
cell.caption = L10n.Core.Service.Cells.MasksPrivateData.caption
|
2019-03-22 18:09:13 +00:00
|
|
|
cell.isOn = TransientStore.masksPrivateData
|
2019-03-21 20:31:13 +00:00
|
|
|
return cell
|
|
|
|
|
2018-10-18 14:53:37 +00:00
|
|
|
// feedback
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2019-11-19 22:33:51 +00:00
|
|
|
case .faq:
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
|
|
|
cell.leftText = L10n.Core.About.Cells.Faq.caption
|
|
|
|
return cell
|
|
|
|
|
2018-10-22 20:42:42 +00:00
|
|
|
case .reportIssue:
|
2018-10-11 07:13:19 +00:00
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
2019-06-21 21:15:43 +00:00
|
|
|
cell.leftText = L10n.Core.Service.Cells.ReportIssue.caption
|
2018-10-11 07:13:19 +00:00
|
|
|
return cell
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
|
|
|
|
// cell.isSelected = (indexPath == lastSelectedIndexPath)
|
|
|
|
// }
|
|
|
|
|
|
|
|
// MARK: Actions
|
|
|
|
|
|
|
|
func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
|
|
|
|
guard let cell = tableView.cellForRow(at: indexPath) else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if let settingCell = cell as? SettingTableViewCell {
|
|
|
|
guard settingCell.isTappable else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
guard handle(row: model.row(at: indexPath), cell: cell) else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return indexPath
|
|
|
|
}
|
|
|
|
|
|
|
|
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
|
|
|
|
return model.row(at: indexPath) == .trustedWiFi
|
|
|
|
}
|
|
|
|
|
|
|
|
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
|
|
|
|
precondition(indexPath.section == model.index(ofSection: .trusted))
|
|
|
|
trustedNetworks.removeWifi(at: indexPath.row)
|
|
|
|
}
|
|
|
|
|
|
|
|
func toggleCell(_ cell: ToggleTableViewCell, didToggleToValue value: Bool) {
|
|
|
|
guard let item = RowType(rawValue: cell.tag) else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
handle(row: item, cell: cell)
|
|
|
|
}
|
|
|
|
|
|
|
|
// true if enters subscreen
|
|
|
|
private func handle(row: RowType, cell: UITableViewCell) -> Bool {
|
|
|
|
switch row {
|
|
|
|
case .useProfile:
|
2018-11-02 10:19:59 +00:00
|
|
|
activateProfile()
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2018-10-21 07:45:59 +00:00
|
|
|
case .reconnect:
|
|
|
|
confirmVpnReconnection()
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case .account:
|
|
|
|
perform(segue: StoryboardSegue.Main.accountSegueIdentifier, sender: cell)
|
|
|
|
return true
|
|
|
|
|
|
|
|
case .endpoint:
|
|
|
|
perform(segue: StoryboardSegue.Main.endpointSegueIdentifier, sender: cell)
|
|
|
|
return true
|
|
|
|
|
|
|
|
case .providerPool:
|
|
|
|
perform(segue: StoryboardSegue.Main.providerPoolSegueIdentifier, sender: cell)
|
|
|
|
return true
|
|
|
|
|
|
|
|
case .providerPreset:
|
|
|
|
perform(segue: StoryboardSegue.Main.providerPresetSegueIdentifier, sender: cell)
|
|
|
|
return true
|
|
|
|
|
|
|
|
case .providerRefresh:
|
|
|
|
refreshProviderInfrastructure()
|
|
|
|
return false
|
|
|
|
|
|
|
|
case .hostParameters:
|
|
|
|
perform(segue: StoryboardSegue.Main.hostParametersSegueIdentifier, sender: cell)
|
|
|
|
return true
|
|
|
|
|
2019-04-29 16:13:49 +00:00
|
|
|
case .networkSettings:
|
|
|
|
perform(segue: StoryboardSegue.Main.networkSettingsSegueIdentifier, sender: cell)
|
|
|
|
return true
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case .trustedAddCurrentWiFi:
|
2019-10-20 22:25:02 +00:00
|
|
|
trustCurrentWiFi()
|
2018-10-11 07:13:19 +00:00
|
|
|
|
|
|
|
case .testConnectivity:
|
|
|
|
testInternetConnectivity()
|
|
|
|
|
2019-03-29 10:17:50 +00:00
|
|
|
// case .dataCount:
|
|
|
|
// displayDataCount()
|
2019-10-23 08:17:56 +00:00
|
|
|
|
|
|
|
case .serverConfiguration:
|
|
|
|
discloseServerConfiguration()
|
|
|
|
|
|
|
|
case .serverNetwork:
|
|
|
|
discloseServerNetwork()
|
2018-10-11 07:13:19 +00:00
|
|
|
|
|
|
|
case .debugLog:
|
|
|
|
perform(segue: StoryboardSegue.Main.debugLogSegueIdentifier, sender: cell)
|
|
|
|
return true
|
|
|
|
|
2019-11-19 22:33:51 +00:00
|
|
|
case .faq:
|
|
|
|
visitURL(AppConstants.URLs.faq)
|
|
|
|
|
2018-10-22 20:42:42 +00:00
|
|
|
case .reportIssue:
|
|
|
|
reportConnectivityIssue()
|
2018-10-11 07:13:19 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
private func handle(row: RowType, cell: ToggleTableViewCell) {
|
|
|
|
switch row {
|
|
|
|
case .vpnService:
|
|
|
|
toggleVpnService(cell: cell)
|
|
|
|
|
|
|
|
case .vpnResolvesHostname:
|
|
|
|
toggleResolvesHostname(cell.isOn)
|
|
|
|
|
|
|
|
case .vpnSurvivesSleep:
|
|
|
|
toggleDisconnectsOnSleep(cell.isOn)
|
|
|
|
|
|
|
|
case .trustedMobile:
|
2019-10-27 20:56:06 +00:00
|
|
|
trustMobileNetwork(cell: cell)
|
2018-10-11 07:13:19 +00:00
|
|
|
|
|
|
|
case .trustedWiFi:
|
|
|
|
guard let indexPath = tableView.indexPath(for: cell) else {
|
|
|
|
return
|
|
|
|
}
|
2019-10-27 20:56:06 +00:00
|
|
|
toggleTrustWiFi(cell: cell, at: indexPath.row)
|
2018-10-11 07:13:19 +00:00
|
|
|
|
|
|
|
case .trustedPolicy:
|
2018-11-03 21:39:07 +00:00
|
|
|
toggleTrustedConnectionPolicy(cell.isOn, sender: cell)
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2019-03-21 20:31:13 +00:00
|
|
|
case .masksPrivateData:
|
|
|
|
togglePrivateDataMasking(cell: cell)
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
default:
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: Updates
|
|
|
|
|
|
|
|
func reloadModel() {
|
|
|
|
model.clear()
|
|
|
|
|
|
|
|
guard let profile = profile else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// assert(profile != nil, "Profile not set")
|
|
|
|
|
|
|
|
let isActiveProfile = service.isActiveProfile(profile)
|
|
|
|
let isProvider = (profile as? ProviderConnectionProfile) != nil
|
|
|
|
|
|
|
|
// sections
|
|
|
|
model.add(.vpn)
|
|
|
|
if isProvider {
|
|
|
|
model.add(.authentication)
|
|
|
|
}
|
|
|
|
model.add(.configuration)
|
|
|
|
if isProvider {
|
|
|
|
model.add(.providerInfrastructure)
|
|
|
|
}
|
|
|
|
if isActiveProfile {
|
|
|
|
if isProvider {
|
|
|
|
model.add(.vpnResolvesHostname)
|
|
|
|
}
|
|
|
|
model.add(.vpnSurvivesSleep)
|
|
|
|
model.add(.trusted)
|
|
|
|
model.add(.trustedPolicy)
|
|
|
|
model.add(.diagnostics)
|
2019-11-19 22:53:10 +00:00
|
|
|
model.add(.feedback)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// headers
|
2019-10-11 08:56:23 +00:00
|
|
|
model.setHeader(L10n.App.Service.Sections.Vpn.header, forSection: .vpn)
|
2018-10-11 07:13:19 +00:00
|
|
|
if isProvider {
|
2019-10-11 08:56:23 +00:00
|
|
|
model.setHeader(L10n.App.Service.Sections.Configuration.header, forSection: .authentication)
|
2018-10-11 07:13:19 +00:00
|
|
|
} else {
|
2019-10-11 08:56:23 +00:00
|
|
|
model.setHeader(L10n.App.Service.Sections.Configuration.header, forSection: .configuration)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
if isActiveProfile {
|
|
|
|
if isProvider {
|
2019-10-11 08:56:23 +00:00
|
|
|
model.setHeader("", forSection: .vpnResolvesHostname)
|
|
|
|
model.setHeader("", forSection: .vpnSurvivesSleep)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
2019-10-11 08:56:23 +00:00
|
|
|
model.setHeader(L10n.Core.Service.Sections.Trusted.header, forSection: .trusted)
|
|
|
|
model.setHeader(L10n.Core.Service.Sections.Diagnostics.header, forSection: .diagnostics)
|
|
|
|
model.setHeader(L10n.Core.Organizer.Sections.Feedback.header, forSection: .feedback)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// footers
|
|
|
|
if isActiveProfile {
|
2019-10-11 08:56:23 +00:00
|
|
|
model.setFooter(L10n.Core.Service.Sections.Vpn.footer, forSection: .vpn)
|
2018-10-11 07:13:19 +00:00
|
|
|
if isProvider {
|
2019-10-11 08:56:23 +00:00
|
|
|
model.setFooter(L10n.Core.Service.Sections.VpnResolvesHostname.footer, forSection: .vpnResolvesHostname)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
2019-10-11 08:56:23 +00:00
|
|
|
model.setFooter(L10n.Core.Service.Sections.VpnSurvivesSleep.footer, forSection: .vpnSurvivesSleep)
|
|
|
|
model.setFooter(L10n.Core.Service.Sections.Trusted.footer, forSection: .trustedPolicy)
|
|
|
|
model.setFooter(L10n.Core.Service.Sections.Diagnostics.footer, forSection: .diagnostics)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// rows
|
|
|
|
if isActiveProfile {
|
2018-10-21 08:05:39 +00:00
|
|
|
var rows: [RowType] = [.vpnService, .connectionStatus]
|
|
|
|
if vpn.isEnabled {
|
|
|
|
rows.append(.reconnect)
|
|
|
|
}
|
2019-10-11 08:56:23 +00:00
|
|
|
model.set(rows, forSection: .vpn)
|
2018-10-11 07:13:19 +00:00
|
|
|
} else {
|
2019-10-11 08:56:23 +00:00
|
|
|
model.set([.useProfile], forSection: .vpn)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
if isProvider {
|
2019-10-11 08:56:23 +00:00
|
|
|
model.set([.account], forSection: .authentication)
|
|
|
|
model.set([.providerPool, .endpoint, .providerPreset, .networkSettings], forSection: .configuration)
|
|
|
|
model.set([.providerRefresh], forSection: .providerInfrastructure)
|
2018-10-11 07:13:19 +00:00
|
|
|
} else {
|
2019-10-11 08:56:23 +00:00
|
|
|
model.set([.account, .endpoint, .hostParameters, .networkSettings], forSection: .configuration)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
if isActiveProfile {
|
|
|
|
if isProvider {
|
2019-10-11 08:56:23 +00:00
|
|
|
model.set([.vpnResolvesHostname], forSection: .vpnResolvesHostname)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
2019-10-11 08:56:23 +00:00
|
|
|
model.set([.vpnSurvivesSleep], forSection: .vpnSurvivesSleep)
|
|
|
|
model.set([.trustedPolicy], forSection: .trustedPolicy)
|
2019-10-23 08:17:56 +00:00
|
|
|
model.set([.dataCount, .serverConfiguration, .serverNetwork, .debugLog, .masksPrivateData], forSection: .diagnostics)
|
2019-11-19 22:53:10 +00:00
|
|
|
|
|
|
|
var feedbackRows: [RowType] = [.faq]
|
|
|
|
if ProductManager.shared.isEligibleForFeedback() {
|
|
|
|
feedbackRows.append(.reportIssue)
|
|
|
|
}
|
|
|
|
model.set(feedbackRows, forSection: .feedback)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
trustedNetworks.delegate = self
|
2019-11-21 10:27:10 +00:00
|
|
|
trustedNetworks.load(from: uncheckedProfile.trustedNetworks)
|
2019-10-11 08:56:23 +00:00
|
|
|
model.set(trustedNetworks.rows.map { mappedTrustedNetworksRow($0) }, forSection: .trusted)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private func reloadVpnStatus() {
|
|
|
|
guard let profile = profile else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
guard service.isActiveProfile(profile) else {
|
|
|
|
return
|
|
|
|
}
|
2019-03-29 10:17:50 +00:00
|
|
|
var ips: [IndexPath] = []
|
2019-03-05 09:14:21 +00:00
|
|
|
guard let statusIndexPath = statusIndexPath else {
|
|
|
|
return
|
|
|
|
}
|
2019-03-29 10:17:50 +00:00
|
|
|
ips.append(statusIndexPath)
|
|
|
|
if let dataCountIndexPath = dataCountIndexPath {
|
2019-03-30 19:03:50 +00:00
|
|
|
currentDataCount = service.vpnDataCount
|
2019-03-29 10:17:50 +00:00
|
|
|
ips.append(dataCountIndexPath)
|
|
|
|
}
|
|
|
|
tableView.reloadRows(at: ips, with: .none)
|
|
|
|
}
|
|
|
|
|
|
|
|
private func refreshDataCount(_ dataCount: (Int, Int)?) {
|
|
|
|
currentDataCount = dataCount
|
|
|
|
guard let dataCountIndexPath = dataCountIndexPath else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
tableView.reloadRows(at: [dataCountIndexPath], with: .none)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
2019-05-02 10:51:40 +00:00
|
|
|
func reloadSelectedRow(andRowsAt indexPaths: [IndexPath]? = nil) {
|
2018-10-11 07:13:19 +00:00
|
|
|
guard let selectedIP = tableView.indexPathForSelectedRow else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var outdatedIPs = [selectedIP]
|
2019-05-02 10:51:40 +00:00
|
|
|
if let otherIPs = indexPaths {
|
|
|
|
outdatedIPs.append(contentsOf: otherIPs)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
tableView.reloadRows(at: outdatedIPs, with: .none)
|
|
|
|
tableView.selectRow(at: selectedIP, animated: false, scrollPosition: .none)
|
|
|
|
}
|
|
|
|
|
|
|
|
func clearSelection() {
|
|
|
|
guard let selected = tableView.indexPathForSelectedRow else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
tableView.deselectRow(at: selected, animated: true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: -
|
|
|
|
|
2018-11-02 10:19:59 +00:00
|
|
|
extension ServiceViewController: UITextFieldDelegate {
|
|
|
|
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
|
2020-05-11 20:53:09 +00:00
|
|
|
// guard string.rangeOfCharacter(from: CharacterSet.filename.inverted) == nil else {
|
|
|
|
// return false
|
|
|
|
// }
|
2018-11-02 10:19:59 +00:00
|
|
|
if let text = textField.text {
|
|
|
|
let replacement = (text as NSString).replacingCharacters(in: range, with: string)
|
|
|
|
pendingRenameAction?.isEnabled = (replacement != uncheckedProfile.id)
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
2018-11-02 15:23:34 +00:00
|
|
|
|
|
|
|
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
|
|
|
|
return true
|
|
|
|
}
|
2018-11-02 10:19:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: -
|
|
|
|
|
2019-11-21 08:15:24 +00:00
|
|
|
extension ServiceViewController: TrustedNetworksUIDelegate {
|
|
|
|
func trustedNetworksCouldDisconnect(_: TrustedNetworksUI) -> Bool {
|
2019-11-21 08:28:28 +00:00
|
|
|
return (uncheckedProfile.trustedNetworks.policy == .disconnect) && (vpn.status != .disconnected)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
2019-11-21 08:15:24 +00:00
|
|
|
func trustedNetworksShouldConfirmDisconnection(_: TrustedNetworksUI, triggeredAt rowIndex: Int, completionHandler: @escaping () -> Void) {
|
2018-10-11 07:13:19 +00:00
|
|
|
confirmPotentialTrustedDisconnection(at: rowIndex, completionHandler: completionHandler)
|
|
|
|
}
|
|
|
|
|
2019-11-21 08:15:24 +00:00
|
|
|
func trustedNetworks(_: TrustedNetworksUI, shouldInsertWifiAt rowIndex: Int) {
|
2019-10-11 08:56:23 +00:00
|
|
|
model.set(trustedNetworks.rows.map { mappedTrustedNetworksRow($0) }, forSection: .trusted)
|
2018-10-11 07:13:19 +00:00
|
|
|
tableView.insertRows(at: [IndexPath(row: rowIndex, section: trustedSectionIndex)], with: .bottom)
|
|
|
|
}
|
|
|
|
|
2019-11-21 08:15:24 +00:00
|
|
|
func trustedNetworks(_: TrustedNetworksUI, shouldReloadWifiAt rowIndex: Int, isTrusted: Bool) {
|
2018-10-11 07:13:19 +00:00
|
|
|
let genericCell = tableView.cellForRow(at: IndexPath(row: rowIndex, section: trustedSectionIndex))
|
|
|
|
guard let cell = genericCell as? ToggleTableViewCell else {
|
|
|
|
fatalError("Not a trusted Wi-Fi cell (\(type(of: genericCell)) != ToggleTableViewCell)")
|
|
|
|
}
|
|
|
|
guard isTrusted != cell.isOn else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
cell.setOn(isTrusted, animated: true)
|
|
|
|
}
|
|
|
|
|
2019-11-21 08:15:24 +00:00
|
|
|
func trustedNetworks(_: TrustedNetworksUI, shouldDeleteWifiAt rowIndex: Int) {
|
2019-10-11 08:56:23 +00:00
|
|
|
model.set(trustedNetworks.rows.map { mappedTrustedNetworksRow($0) }, forSection: .trusted)
|
2018-10-11 07:13:19 +00:00
|
|
|
tableView.deleteRows(at: [IndexPath(row: rowIndex, section: trustedSectionIndex)], with: .top)
|
|
|
|
}
|
|
|
|
|
2019-11-21 08:15:24 +00:00
|
|
|
func trustedNetworksShouldReinstall(_: TrustedNetworksUI) {
|
2019-11-21 08:28:28 +00:00
|
|
|
uncheckedProfile.trustedNetworks.includesMobile = trustedNetworks.trustsMobileNetwork
|
|
|
|
uncheckedProfile.trustedNetworks.includedWiFis = trustedNetworks.trustedWifis
|
2018-10-11 07:13:19 +00:00
|
|
|
if vpn.isEnabled {
|
|
|
|
vpn.reinstall(completionHandler: nil)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: -
|
|
|
|
|
|
|
|
extension ServiceViewController: ConfigurationModificationDelegate {
|
2019-05-23 21:13:45 +00:00
|
|
|
func configuration(didUpdate newConfiguration: OpenVPN.Configuration) {
|
2018-10-11 07:13:19 +00:00
|
|
|
if let hostProfile = profile as? HostConnectionProfile {
|
2018-10-25 18:08:22 +00:00
|
|
|
var builder = hostProfile.parameters.builder()
|
|
|
|
builder.sessionConfiguration = newConfiguration
|
|
|
|
hostProfile.parameters = builder.build()
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
reloadSelectedRow()
|
|
|
|
}
|
|
|
|
|
|
|
|
func configurationShouldReinstall() {
|
|
|
|
vpn.reinstallIfEnabled()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension ServiceViewController: AccountViewControllerDelegate {
|
|
|
|
func accountController(_ vc: AccountViewController, didEnterCredentials credentials: Credentials) {
|
|
|
|
}
|
|
|
|
|
|
|
|
func accountControllerDidComplete(_ accountVC: AccountViewController) {
|
|
|
|
navigationController?.popViewController(animated: true)
|
|
|
|
|
|
|
|
let credentials = accountVC.credentials
|
|
|
|
guard credentials != service.credentials(for: uncheckedProfile) else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
try? service.setCredentials(credentials, for: uncheckedProfile)
|
|
|
|
reloadSelectedRow()
|
|
|
|
vpn.reinstallIfEnabled()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension ServiceViewController: EndpointViewControllerDelegate {
|
2018-11-10 09:29:51 +00:00
|
|
|
func endpointController(_: EndpointViewController, didUpdateWithNewAddress newAddress: String?, newProtocol: EndpointProtocol?) {
|
2020-05-23 17:06:44 +00:00
|
|
|
profile?.customAddress = newAddress
|
|
|
|
profile?.customProtocol = newProtocol
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
reloadSelectedRow()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension ServiceViewController: ProviderPoolViewControllerDelegate {
|
|
|
|
func providerPoolController(_ vc: ProviderPoolViewController, didSelectPool pool: Pool) {
|
2019-04-06 13:12:39 +00:00
|
|
|
navigationController?.popToViewController(self, animated: true)
|
2018-10-11 07:13:19 +00:00
|
|
|
|
|
|
|
guard pool.id != uncheckedProviderProfile.poolId else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
uncheckedProviderProfile.poolId = pool.id
|
2019-05-02 10:51:40 +00:00
|
|
|
|
|
|
|
var extraReloadedRows = [endpointIndexPath]
|
|
|
|
|
|
|
|
// fall back to a supported preset and reload preset row too
|
|
|
|
let supportedPresets = pool.supportedPresetIds(in: uncheckedProviderProfile.infrastructure)
|
|
|
|
if let presetId = uncheckedProviderProfile.preset?.id, !supportedPresets.contains(presetId),
|
|
|
|
let fallback = supportedPresets.first {
|
|
|
|
|
|
|
|
if fallback != uncheckedProviderProfile.presetId {
|
|
|
|
extraReloadedRows.append(providerPresetIndexPath)
|
|
|
|
}
|
|
|
|
uncheckedProviderProfile.presetId = fallback
|
|
|
|
}
|
|
|
|
|
|
|
|
reloadSelectedRow(andRowsAt: extraReloadedRows)
|
2018-10-11 07:13:19 +00:00
|
|
|
vpn.reinstallIfEnabled()
|
2019-03-09 08:53:48 +00:00
|
|
|
|
|
|
|
if #available(iOS 12, *) {
|
2020-02-28 17:32:04 +00:00
|
|
|
let title = service.screenTitle(forProviderName: uncheckedProviderProfile.name)
|
|
|
|
IntentDispatcher.donateConnection(with: uncheckedProviderProfile, title: title)
|
2019-03-09 08:53:48 +00:00
|
|
|
}
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
2019-11-21 13:00:34 +00:00
|
|
|
|
|
|
|
func providerPoolController(_: ProviderPoolViewController, didUpdateFavoriteGroups favoriteGroupIds: [String]) {
|
|
|
|
uncheckedProviderProfile.favoriteGroupIds = favoriteGroupIds
|
|
|
|
}
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extension ServiceViewController: ProviderPresetViewControllerDelegate {
|
|
|
|
func providerPresetController(_: ProviderPresetViewController, didSelectPreset preset: InfrastructurePreset) {
|
|
|
|
navigationController?.popViewController(animated: true)
|
|
|
|
|
|
|
|
guard preset.id != uncheckedProviderProfile.presetId else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
uncheckedProviderProfile.presetId = preset.id
|
2019-05-02 10:51:40 +00:00
|
|
|
reloadSelectedRow(andRowsAt: [endpointIndexPath])
|
2018-10-11 07:13:19 +00:00
|
|
|
vpn.reinstallIfEnabled()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-20 22:17:25 +00:00
|
|
|
extension ServiceViewController: CLLocationManagerDelegate {
|
|
|
|
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
|
2019-10-20 22:30:49 +00:00
|
|
|
guard isPendingTrustedWiFi else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
isPendingTrustedWiFi = false
|
2019-10-20 22:25:02 +00:00
|
|
|
trustCurrentWiFi()
|
2019-10-20 22:17:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
// MARK: -
|
|
|
|
|
|
|
|
private extension ServiceViewController {
|
|
|
|
private var uncheckedProfile: ConnectionProfile {
|
|
|
|
guard let profile = profile else {
|
|
|
|
fatalError("Expected non-nil profile here")
|
|
|
|
}
|
|
|
|
return profile
|
|
|
|
}
|
|
|
|
|
|
|
|
private var uncheckedProviderProfile: ProviderConnectionProfile {
|
|
|
|
guard let profile = profile as? ProviderConnectionProfile else {
|
|
|
|
fatalError("Expected ProviderConnectionProfile (found: \(type(of: self.profile)))")
|
|
|
|
}
|
|
|
|
return profile
|
|
|
|
}
|
|
|
|
|
|
|
|
private var uncheckedHostProfile: HostConnectionProfile {
|
|
|
|
guard let profile = profile as? HostConnectionProfile else {
|
|
|
|
fatalError("Expected HostConnectionProfile (found: \(type(of: self.profile)))")
|
|
|
|
}
|
|
|
|
return profile
|
|
|
|
}
|
|
|
|
}
|