2018-10-11 07:13:19 +00:00
|
|
|
//
|
|
|
|
// ConfigurationViewController.swift
|
|
|
|
// Passepartout-iOS
|
|
|
|
//
|
|
|
|
// Created by Davide De Rosa on 9/2/18.
|
2019-03-09 10:44:44 +00:00
|
|
|
// Copyright (c) 2019 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 TunnelKit
|
2018-10-22 09:16:05 +00:00
|
|
|
import SwiftyBeaver
|
2019-03-18 10:52:19 +00:00
|
|
|
import Passepartout_Core
|
2018-10-22 09:16:05 +00:00
|
|
|
|
|
|
|
private let log = SwiftyBeaver.self
|
2018-10-11 07:13:19 +00:00
|
|
|
|
|
|
|
class ConfigurationViewController: UIViewController, TableModelHost {
|
|
|
|
@IBOutlet private weak var tableView: UITableView!
|
|
|
|
|
|
|
|
private lazy var itemRefresh = UIBarButtonItem(barButtonSystemItem: .refresh, target: self, action: #selector(refresh))
|
|
|
|
|
2018-10-25 18:08:22 +00:00
|
|
|
var initialConfiguration: SessionProxy.Configuration!
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2018-10-25 18:08:22 +00:00
|
|
|
private lazy var configuration: SessionProxy.ConfigurationBuilder = initialConfiguration.builder()
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2018-10-22 09:16:05 +00:00
|
|
|
var originalConfigurationURL: URL?
|
|
|
|
|
2018-10-25 20:51:01 +00:00
|
|
|
private var isEditable: Bool {
|
|
|
|
return originalConfigurationURL != nil
|
|
|
|
}
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
weak var delegate: ConfigurationModificationDelegate?
|
|
|
|
|
|
|
|
// MARK: TableModelHost
|
|
|
|
|
|
|
|
lazy var model: TableModel<SectionType, RowType> = {
|
|
|
|
let model: TableModel<SectionType, RowType> = TableModel()
|
|
|
|
|
|
|
|
// sections
|
|
|
|
model.add(.communication)
|
2018-10-25 20:51:01 +00:00
|
|
|
if isEditable {
|
2018-10-22 09:16:05 +00:00
|
|
|
model.add(.reset)
|
|
|
|
}
|
2018-10-11 07:13:19 +00:00
|
|
|
model.add(.tls)
|
2019-03-19 10:52:17 +00:00
|
|
|
model.add(.compression)
|
2019-04-13 07:30:53 +00:00
|
|
|
model.add(.network)
|
2018-10-11 07:13:19 +00:00
|
|
|
model.add(.other)
|
|
|
|
|
|
|
|
// headers
|
|
|
|
model.setHeader(L10n.Configuration.Sections.Communication.header, for: .communication)
|
|
|
|
model.setHeader(L10n.Configuration.Sections.Tls.header, for: .tls)
|
2019-03-19 10:52:17 +00:00
|
|
|
model.setHeader(L10n.Configuration.Sections.Compression.header, for: .compression)
|
2019-04-13 07:30:53 +00:00
|
|
|
model.setHeader(L10n.Configuration.Sections.Network.header, for: .network)
|
2018-10-11 07:13:19 +00:00
|
|
|
model.setHeader(L10n.Configuration.Sections.Other.header, for: .other)
|
|
|
|
|
|
|
|
// footers
|
2018-10-25 20:51:01 +00:00
|
|
|
if isEditable {
|
2018-10-22 09:16:05 +00:00
|
|
|
model.setFooter(L10n.Configuration.Sections.Reset.footer, for: .reset)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// rows
|
2019-03-19 10:52:17 +00:00
|
|
|
model.set([.cipher, .digest], in: .communication)
|
2018-10-25 20:51:01 +00:00
|
|
|
if isEditable {
|
2018-10-22 09:16:05 +00:00
|
|
|
model.set([.resetOriginal], in: .reset)
|
|
|
|
}
|
2019-03-27 16:06:13 +00:00
|
|
|
model.set([.client, .tlsWrapping, .eku], in: .tls)
|
2019-03-19 10:52:17 +00:00
|
|
|
model.set([.compressionFraming, .compressionAlgorithm], in: .compression)
|
2019-04-13 07:30:53 +00:00
|
|
|
var networkRows: [RowType]
|
2019-03-03 09:40:12 +00:00
|
|
|
if let dnsServers = configuration.dnsServers {
|
2019-04-13 07:30:53 +00:00
|
|
|
networkRows = [RowType](repeating: .dnsServer, count: dnsServers.count)
|
2019-04-03 12:08:22 +00:00
|
|
|
} else {
|
2019-04-13 07:30:53 +00:00
|
|
|
networkRows = []
|
2019-03-03 09:40:12 +00:00
|
|
|
}
|
2019-04-25 12:53:50 +00:00
|
|
|
networkRows.insert(.defaultGateway, at: 0)
|
2019-04-13 07:30:53 +00:00
|
|
|
networkRows.append(.dnsDomain)
|
|
|
|
networkRows.append(.httpProxy)
|
|
|
|
networkRows.append(.httpsProxy)
|
|
|
|
model.set(networkRows, in: .network)
|
2019-03-27 16:06:13 +00:00
|
|
|
model.set([.keepAlive, .renegSeconds, .randomEndpoint], in: .other)
|
2018-10-11 07:13:19 +00:00
|
|
|
|
|
|
|
return model
|
|
|
|
}()
|
|
|
|
|
|
|
|
func reloadModel() {
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: UIViewController
|
|
|
|
|
|
|
|
override func awakeFromNib() {
|
|
|
|
super.awakeFromNib()
|
|
|
|
|
|
|
|
applyDetailTitle(Theme.current)
|
|
|
|
}
|
|
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
|
super.viewDidLoad()
|
2018-10-25 20:51:01 +00:00
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
guard let _ = initialConfiguration else {
|
|
|
|
fatalError("Initial configuration not set")
|
|
|
|
}
|
|
|
|
|
|
|
|
guard isEditable else {
|
|
|
|
tableView.allowsSelection = false
|
|
|
|
return
|
|
|
|
}
|
|
|
|
itemRefresh.isEnabled = false
|
|
|
|
navigationItem.rightBarButtonItem = itemRefresh
|
|
|
|
}
|
|
|
|
|
|
|
|
override func viewWillAppear(_ animated: Bool) {
|
|
|
|
super.viewWillAppear(animated)
|
|
|
|
|
|
|
|
if let ip = tableView.indexPathForSelectedRow {
|
|
|
|
tableView.deselectRow(at: ip, animated: true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: Actions
|
|
|
|
|
2018-10-22 09:16:05 +00:00
|
|
|
private func resetOriginalConfiguration() {
|
2018-10-27 09:36:41 +00:00
|
|
|
guard let originalURL = originalConfigurationURL else {
|
2018-10-22 09:16:05 +00:00
|
|
|
log.warning("Resetting with no original configuration set? Bad table model?")
|
|
|
|
return
|
|
|
|
}
|
2019-04-04 17:26:08 +00:00
|
|
|
let parsingResult: ConfigurationParser.Result
|
2018-10-22 09:31:46 +00:00
|
|
|
do {
|
2018-11-10 09:29:51 +00:00
|
|
|
parsingResult = try ConfigurationParser.parsed(fromURL: originalURL)
|
2018-10-22 09:31:46 +00:00
|
|
|
} catch let e {
|
2018-10-27 08:55:50 +00:00
|
|
|
log.error("Could not parse original configuration: \(e)")
|
2018-10-22 09:31:46 +00:00
|
|
|
return
|
|
|
|
}
|
2018-11-10 09:29:51 +00:00
|
|
|
configuration = parsingResult.configuration.builder()
|
2018-10-27 10:18:47 +00:00
|
|
|
itemRefresh.isEnabled = !configuration.canCommunicate(with: initialConfiguration)
|
2018-11-10 09:29:51 +00:00
|
|
|
initialConfiguration = parsingResult.configuration
|
2018-10-22 09:31:46 +00:00
|
|
|
tableView.reloadData()
|
|
|
|
|
2018-10-25 18:08:22 +00:00
|
|
|
delegate?.configuration(didUpdate: initialConfiguration)
|
2018-10-22 09:16:05 +00:00
|
|
|
}
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
@IBAction private func refresh() {
|
|
|
|
guard isEditable else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
initialConfiguration = configuration.build()
|
|
|
|
itemRefresh.isEnabled = false
|
|
|
|
|
|
|
|
delegate?.configurationShouldReinstall()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: -
|
|
|
|
|
|
|
|
extension ConfigurationViewController: UITableViewDataSource, UITableViewDelegate {
|
|
|
|
enum SectionType: Int {
|
|
|
|
case communication
|
2018-10-22 09:16:05 +00:00
|
|
|
|
|
|
|
case reset
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case tls
|
|
|
|
|
2019-03-19 10:52:17 +00:00
|
|
|
case compression
|
|
|
|
|
2019-04-13 07:30:53 +00:00
|
|
|
case network
|
2019-03-03 09:40:12 +00:00
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case other
|
|
|
|
}
|
|
|
|
|
|
|
|
enum RowType: Int {
|
|
|
|
case cipher
|
|
|
|
|
|
|
|
case digest
|
|
|
|
|
2018-10-22 09:16:05 +00:00
|
|
|
case resetOriginal
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case client
|
|
|
|
|
|
|
|
case tlsWrapping
|
|
|
|
|
2019-03-27 16:06:13 +00:00
|
|
|
case eku
|
|
|
|
|
2019-03-19 10:52:17 +00:00
|
|
|
case compressionFraming
|
2019-03-03 09:40:12 +00:00
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case compressionAlgorithm
|
|
|
|
|
2019-04-25 12:53:50 +00:00
|
|
|
case defaultGateway
|
|
|
|
|
2019-03-19 10:52:17 +00:00
|
|
|
case dnsServer
|
|
|
|
|
2019-04-03 12:08:22 +00:00
|
|
|
case dnsDomain
|
|
|
|
|
2019-04-13 07:30:53 +00:00
|
|
|
case httpProxy
|
|
|
|
|
|
|
|
case httpsProxy
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case keepAlive
|
|
|
|
|
|
|
|
case renegSeconds
|
2019-03-27 16:06:13 +00:00
|
|
|
|
|
|
|
case randomEndpoint
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func numberOfSections(in tableView: UITableView) -> Int {
|
|
|
|
return model.count
|
|
|
|
}
|
|
|
|
|
|
|
|
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
|
|
|
return model.header(for: section)
|
|
|
|
}
|
|
|
|
|
|
|
|
func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
|
|
|
|
return model.footer(for: section)
|
|
|
|
}
|
|
|
|
|
2018-10-22 09:16:05 +00:00
|
|
|
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
|
2019-04-04 17:53:08 +00:00
|
|
|
return model.headerHeight(for: section)
|
2018-10-22 09:16:05 +00:00
|
|
|
}
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
|
|
return model.count(for: section)
|
|
|
|
}
|
|
|
|
|
|
|
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
|
|
let row = model.row(at: indexPath)
|
2019-03-27 16:00:45 +00:00
|
|
|
let V = L10n.Configuration.Cells.self
|
2018-10-11 07:13:19 +00:00
|
|
|
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
|
|
|
if !isEditable {
|
|
|
|
cell.accessoryType = .none
|
|
|
|
}
|
|
|
|
cell.isTappable = isEditable
|
|
|
|
switch row {
|
|
|
|
case .cipher:
|
|
|
|
cell.leftText = L10n.Configuration.Cells.Cipher.caption
|
2019-04-04 11:23:20 +00:00
|
|
|
cell.rightText = configuration.fallbackCipher.description
|
2018-10-11 07:13:19 +00:00
|
|
|
|
|
|
|
case .digest:
|
|
|
|
cell.leftText = L10n.Configuration.Cells.Digest.caption
|
2019-04-27 07:31:12 +00:00
|
|
|
cell.rightText = configuration.fallbackDigest.description
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2018-10-22 09:16:05 +00:00
|
|
|
case .resetOriginal:
|
|
|
|
cell.leftText = L10n.Configuration.Cells.ResetOriginal.caption
|
|
|
|
cell.applyAction(Theme.current)
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case .client:
|
|
|
|
cell.leftText = L10n.Configuration.Cells.Client.caption
|
|
|
|
cell.rightText = (configuration.clientCertificate != nil) ? L10n.Configuration.Cells.Client.Value.enabled : L10n.Configuration.Cells.Client.Value.disabled
|
|
|
|
cell.accessoryType = .none
|
|
|
|
cell.isTappable = false
|
|
|
|
|
|
|
|
case .tlsWrapping:
|
|
|
|
cell.leftText = L10n.Configuration.Cells.TlsWrapping.caption
|
2018-10-18 21:40:38 +00:00
|
|
|
if let strategy = configuration.tlsWrap?.strategy {
|
|
|
|
switch strategy {
|
|
|
|
case .auth:
|
2019-03-27 16:00:45 +00:00
|
|
|
cell.rightText = V.TlsWrapping.Value.auth
|
2018-10-18 21:40:38 +00:00
|
|
|
|
|
|
|
case .crypt:
|
2019-03-27 16:00:45 +00:00
|
|
|
cell.rightText = V.TlsWrapping.Value.crypt
|
2018-10-18 21:40:38 +00:00
|
|
|
}
|
|
|
|
} else {
|
2019-03-27 16:00:45 +00:00
|
|
|
cell.rightText = V.All.Value.disabled
|
2018-10-18 21:40:38 +00:00
|
|
|
}
|
2018-10-11 07:13:19 +00:00
|
|
|
cell.accessoryType = .none
|
|
|
|
cell.isTappable = false
|
2019-03-03 09:40:12 +00:00
|
|
|
|
2019-03-27 16:06:13 +00:00
|
|
|
case .eku:
|
|
|
|
cell.leftText = V.Eku.caption
|
|
|
|
cell.rightText = (configuration.checksEKU ?? false) ? V.All.Value.enabled : V.All.Value.disabled
|
|
|
|
cell.accessoryType = .none
|
|
|
|
cell.isTappable = false
|
|
|
|
|
2019-03-19 10:52:17 +00:00
|
|
|
case .compressionFraming:
|
|
|
|
cell.leftText = L10n.Configuration.Cells.CompressionFraming.caption
|
2019-04-04 11:23:20 +00:00
|
|
|
cell.rightText = configuration.fallbackCompressionFraming.cellDescription
|
2019-03-19 10:52:17 +00:00
|
|
|
cell.accessoryType = .none
|
|
|
|
cell.isTappable = false
|
|
|
|
|
|
|
|
case .compressionAlgorithm:
|
|
|
|
cell.leftText = L10n.Configuration.Cells.CompressionAlgorithm.caption
|
|
|
|
if let compressionAlgorithm = configuration.compressionAlgorithm {
|
|
|
|
cell.rightText = compressionAlgorithm.cellDescription
|
|
|
|
} else {
|
2019-03-27 16:00:45 +00:00
|
|
|
cell.rightText = V.All.Value.disabled
|
2019-03-19 10:52:17 +00:00
|
|
|
}
|
|
|
|
cell.accessoryType = .none
|
|
|
|
cell.isTappable = false
|
|
|
|
|
2019-04-25 12:53:50 +00:00
|
|
|
case .defaultGateway:
|
|
|
|
cell.leftText = L10n.Configuration.Cells.DefaultGateway.caption
|
|
|
|
if let policies = configuration.routingPolicies {
|
|
|
|
cell.rightText = policies.map { $0.rawValue }.joined(separator: " / ")
|
|
|
|
} else {
|
|
|
|
cell.rightText = V.All.Value.none
|
|
|
|
}
|
|
|
|
cell.accessoryType = .none
|
|
|
|
cell.isTappable = false
|
|
|
|
|
2019-03-03 09:40:12 +00:00
|
|
|
case .dnsServer:
|
|
|
|
guard let dnsServers = configuration.dnsServers else {
|
|
|
|
fatalError("Showing DNS section without any custom server")
|
|
|
|
}
|
|
|
|
cell.leftText = L10n.Configuration.Cells.DnsServer.caption
|
2019-04-25 12:53:50 +00:00
|
|
|
cell.rightText = dnsServers[indexPath.row - 1]
|
2019-03-03 09:40:12 +00:00
|
|
|
cell.accessoryType = .none
|
|
|
|
cell.isTappable = false
|
2019-04-03 12:08:22 +00:00
|
|
|
|
|
|
|
case .dnsDomain:
|
|
|
|
cell.leftText = L10n.Configuration.Cells.DnsDomain.caption
|
2019-04-13 07:30:53 +00:00
|
|
|
cell.rightText = configuration.searchDomain ?? L10n.Configuration.Cells.All.Value.none
|
2019-04-03 12:08:22 +00:00
|
|
|
cell.accessoryType = .none
|
|
|
|
cell.isTappable = false
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2019-04-13 07:30:53 +00:00
|
|
|
case .httpProxy:
|
|
|
|
cell.leftText = L10n.Configuration.Cells.ProxyHttp.caption
|
|
|
|
cell.rightText = configuration.httpProxy?.description ?? L10n.Configuration.Cells.All.Value.none
|
|
|
|
cell.accessoryType = .none
|
|
|
|
cell.isTappable = false
|
|
|
|
|
|
|
|
case .httpsProxy:
|
|
|
|
cell.leftText = L10n.Configuration.Cells.ProxyHttps.caption
|
|
|
|
cell.rightText = configuration.httpsProxy?.description ?? L10n.Configuration.Cells.All.Value.none
|
|
|
|
cell.accessoryType = .none
|
|
|
|
cell.isTappable = false
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case .keepAlive:
|
|
|
|
cell.leftText = L10n.Configuration.Cells.KeepAlive.caption
|
2018-10-25 18:08:22 +00:00
|
|
|
if let keepAlive = configuration.keepAliveInterval, keepAlive > 0 {
|
2019-03-27 16:00:45 +00:00
|
|
|
cell.rightText = V.KeepAlive.Value.seconds(Int(keepAlive))
|
2018-10-11 07:13:19 +00:00
|
|
|
} else {
|
2019-03-27 16:00:45 +00:00
|
|
|
cell.rightText = V.All.Value.disabled
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
cell.accessoryType = .none
|
|
|
|
cell.isTappable = false
|
|
|
|
|
|
|
|
case .renegSeconds:
|
|
|
|
cell.leftText = L10n.Configuration.Cells.RenegotiationSeconds.caption
|
2018-10-25 18:08:22 +00:00
|
|
|
if let reneg = configuration.renegotiatesAfter, reneg > 0 {
|
2019-03-27 16:00:45 +00:00
|
|
|
cell.rightText = V.RenegotiationSeconds.Value.after(TimeInterval(reneg).localized)
|
2018-10-11 07:13:19 +00:00
|
|
|
} else {
|
2019-03-27 16:00:45 +00:00
|
|
|
cell.rightText = V.All.Value.disabled
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
cell.accessoryType = .none
|
|
|
|
cell.isTappable = false
|
2019-03-27 16:06:13 +00:00
|
|
|
|
|
|
|
case .randomEndpoint:
|
|
|
|
cell.leftText = V.RandomEndpoint.caption
|
|
|
|
cell.rightText = (configuration.randomizeEndpoint ?? false) ? V.All.Value.enabled : V.All.Value.disabled
|
|
|
|
cell.accessoryType = .none
|
|
|
|
cell.isTappable = false
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
return cell
|
|
|
|
}
|
|
|
|
|
|
|
|
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
|
|
guard isEditable else {
|
|
|
|
fatalError("Table should not allow selection when isEditable is false")
|
|
|
|
}
|
|
|
|
|
2018-10-27 20:21:00 +00:00
|
|
|
let settingCell = tableView.cellForRow(at: indexPath) as? SettingTableViewCell
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
switch model.row(at: indexPath) {
|
|
|
|
case .cipher:
|
|
|
|
let vc = OptionViewController<SessionProxy.Cipher>()
|
2018-10-27 20:21:00 +00:00
|
|
|
vc.title = settingCell?.leftText
|
2018-10-11 07:13:19 +00:00
|
|
|
vc.options = [.aes128cbc, .aes192cbc, .aes256cbc, .aes128gcm, .aes192gcm, .aes256gcm]
|
|
|
|
vc.selectedOption = configuration.cipher
|
|
|
|
vc.descriptionBlock = { $0.description }
|
|
|
|
vc.selectionBlock = { [weak self] in
|
|
|
|
self?.configuration.cipher = $0
|
|
|
|
self?.popAndCheckRefresh()
|
|
|
|
}
|
|
|
|
navigationController?.pushViewController(vc, animated: true)
|
|
|
|
|
|
|
|
case .digest:
|
|
|
|
let vc = OptionViewController<SessionProxy.Digest>()
|
2018-10-27 20:21:00 +00:00
|
|
|
vc.title = settingCell?.leftText
|
2018-10-11 07:13:19 +00:00
|
|
|
vc.options = [.sha1, .sha224, .sha256, .sha384, .sha512]
|
|
|
|
vc.selectedOption = configuration.digest
|
|
|
|
vc.descriptionBlock = { $0.description }
|
|
|
|
vc.selectionBlock = { [weak self] in
|
|
|
|
self?.configuration.digest = $0
|
|
|
|
self?.popAndCheckRefresh()
|
|
|
|
}
|
|
|
|
navigationController?.pushViewController(vc, animated: true)
|
|
|
|
|
2019-03-19 10:52:17 +00:00
|
|
|
// case .compressionFraming:
|
|
|
|
// let vc = OptionViewController<SessionProxy.CompressionFraming>()
|
|
|
|
// vc.title = settingCell?.leftText
|
|
|
|
// vc.options = [.disabled, .compLZO, .compress]
|
|
|
|
// vc.selectedOption = configuration.compressionFraming
|
|
|
|
// vc.descriptionBlock = { $0.cellDescription }
|
|
|
|
// vc.selectionBlock = { [weak self] in
|
|
|
|
// self?.configuration.compressionFraming = $0
|
|
|
|
// self?.popAndCheckRefresh()
|
|
|
|
// }
|
|
|
|
// navigationController?.pushViewController(vc, animated: true)
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2018-10-22 09:16:05 +00:00
|
|
|
case .resetOriginal:
|
|
|
|
tableView.deselectRow(at: indexPath, animated: true)
|
|
|
|
resetOriginalConfiguration()
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
default:
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: Helpers
|
|
|
|
|
|
|
|
private func popAndCheckRefresh() {
|
|
|
|
itemRefresh.isEnabled = !configuration.canCommunicate(with: initialConfiguration)
|
|
|
|
tableView.reloadData()
|
|
|
|
navigationController?.popViewController(animated: true)
|
|
|
|
|
|
|
|
delegate?.configuration(didUpdate: configuration.build())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: -
|
|
|
|
|
|
|
|
private extension SessionProxy.CompressionFraming {
|
|
|
|
var cellDescription: String {
|
2019-03-27 16:00:45 +00:00
|
|
|
let V = L10n.Configuration.Cells.self
|
2018-10-11 07:13:19 +00:00
|
|
|
switch self {
|
|
|
|
case .disabled:
|
2019-03-27 16:00:45 +00:00
|
|
|
return V.All.Value.disabled
|
2018-10-11 07:13:19 +00:00
|
|
|
|
|
|
|
case .compLZO:
|
2019-03-27 16:00:45 +00:00
|
|
|
return V.CompressionFraming.Value.lzo
|
2018-10-11 07:13:19 +00:00
|
|
|
|
|
|
|
case .compress:
|
2019-03-27 16:00:45 +00:00
|
|
|
return V.CompressionFraming.Value.compress
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-03-19 10:52:17 +00:00
|
|
|
|
|
|
|
private extension SessionProxy.CompressionAlgorithm {
|
|
|
|
var cellDescription: String {
|
2019-03-27 16:00:45 +00:00
|
|
|
let V = L10n.Configuration.Cells.self
|
2019-03-19 10:52:17 +00:00
|
|
|
switch self {
|
|
|
|
case .disabled:
|
2019-03-27 16:00:45 +00:00
|
|
|
return V.All.Value.disabled
|
2019-03-19 10:52:17 +00:00
|
|
|
|
|
|
|
case .LZO:
|
2019-03-27 16:00:45 +00:00
|
|
|
return V.CompressionAlgorithm.Value.lzo
|
2019-03-19 10:52:17 +00:00
|
|
|
|
|
|
|
case .other:
|
2019-03-27 16:00:45 +00:00
|
|
|
return V.CompressionAlgorithm.Value.other
|
2019-03-19 10:52:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|