Remove more comments
This commit is contained in:
parent
b68b3785be
commit
3ca5712ac1
|
@ -71,16 +71,12 @@ class TunnelViewModel {
|
||||||
subscript(field: InterfaceField) -> String {
|
subscript(field: InterfaceField) -> String {
|
||||||
get {
|
get {
|
||||||
if scratchpad.isEmpty {
|
if scratchpad.isEmpty {
|
||||||
// When starting to read a config, setup the scratchpad.
|
|
||||||
// The scratchpad shall serve as a cache of what we want to show in the UI.
|
|
||||||
populateScratchpad()
|
populateScratchpad()
|
||||||
}
|
}
|
||||||
return scratchpad[field] ?? ""
|
return scratchpad[field] ?? ""
|
||||||
}
|
}
|
||||||
set(stringValue) {
|
set(stringValue) {
|
||||||
if scratchpad.isEmpty {
|
if scratchpad.isEmpty {
|
||||||
// When starting to edit a config, setup the scratchpad and remove the configuration.
|
|
||||||
// The scratchpad shall be the sole source of the being-edited configuration.
|
|
||||||
populateScratchpad()
|
populateScratchpad()
|
||||||
}
|
}
|
||||||
validatedConfiguration = nil
|
validatedConfiguration = nil
|
||||||
|
@ -102,7 +98,6 @@ class TunnelViewModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
func populateScratchpad() {
|
func populateScratchpad() {
|
||||||
// Populate the scratchpad from the configuration object
|
|
||||||
guard let config = validatedConfiguration else { return }
|
guard let config = validatedConfiguration else { return }
|
||||||
guard let name = validatedName else { return }
|
guard let name = validatedName else { return }
|
||||||
scratchpad[.name] = name
|
scratchpad[.name] = name
|
||||||
|
@ -125,7 +120,6 @@ class TunnelViewModel {
|
||||||
//swiftlint:disable:next cyclomatic_complexity function_body_length
|
//swiftlint:disable:next cyclomatic_complexity function_body_length
|
||||||
func save() -> SaveResult<(String, InterfaceConfiguration)> {
|
func save() -> SaveResult<(String, InterfaceConfiguration)> {
|
||||||
if let config = validatedConfiguration, let name = validatedName {
|
if let config = validatedConfiguration, let name = validatedName {
|
||||||
// It's already validated and saved
|
|
||||||
return .saved((name, config))
|
return .saved((name, config))
|
||||||
}
|
}
|
||||||
fieldsWithError.removeAll()
|
fieldsWithError.removeAll()
|
||||||
|
@ -198,7 +192,6 @@ class TunnelViewModel {
|
||||||
}
|
}
|
||||||
return !self[field].isEmpty
|
return !self[field].isEmpty
|
||||||
}
|
}
|
||||||
// TODO: Cache this to avoid recomputing
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,7 +201,6 @@ class TunnelViewModel {
|
||||||
var fieldsWithError = Set<PeerField>()
|
var fieldsWithError = Set<PeerField>()
|
||||||
var validatedConfiguration: PeerConfiguration?
|
var validatedConfiguration: PeerConfiguration?
|
||||||
|
|
||||||
// For exclude private IPs
|
|
||||||
private(set) var shouldAllowExcludePrivateIPsControl = false
|
private(set) var shouldAllowExcludePrivateIPsControl = false
|
||||||
private(set) var shouldStronglyRecommendDNS = false
|
private(set) var shouldStronglyRecommendDNS = false
|
||||||
private(set) var excludePrivateIPsValue = false
|
private(set) var excludePrivateIPsValue = false
|
||||||
|
@ -221,16 +213,12 @@ class TunnelViewModel {
|
||||||
subscript(field: PeerField) -> String {
|
subscript(field: PeerField) -> String {
|
||||||
get {
|
get {
|
||||||
if scratchpad.isEmpty {
|
if scratchpad.isEmpty {
|
||||||
// When starting to read a config, setup the scratchpad.
|
|
||||||
// The scratchpad shall serve as a cache of what we want to show in the UI.
|
|
||||||
populateScratchpad()
|
populateScratchpad()
|
||||||
}
|
}
|
||||||
return scratchpad[field] ?? ""
|
return scratchpad[field] ?? ""
|
||||||
}
|
}
|
||||||
set(stringValue) {
|
set(stringValue) {
|
||||||
if scratchpad.isEmpty {
|
if scratchpad.isEmpty {
|
||||||
// When starting to edit a config, setup the scratchpad and remove the configuration.
|
|
||||||
// The scratchpad shall be the sole source of the being-edited configuration.
|
|
||||||
populateScratchpad()
|
populateScratchpad()
|
||||||
}
|
}
|
||||||
validatedConfiguration = nil
|
validatedConfiguration = nil
|
||||||
|
@ -246,7 +234,6 @@ class TunnelViewModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
func populateScratchpad() {
|
func populateScratchpad() {
|
||||||
// Populate the scratchpad from the configuration object
|
|
||||||
guard let config = validatedConfiguration else { return }
|
guard let config = validatedConfiguration else { return }
|
||||||
scratchpad[.publicKey] = config.publicKey.base64EncodedString()
|
scratchpad[.publicKey] = config.publicKey.base64EncodedString()
|
||||||
if let preSharedKey = config.preSharedKey {
|
if let preSharedKey = config.preSharedKey {
|
||||||
|
@ -267,7 +254,6 @@ class TunnelViewModel {
|
||||||
//swiftlint:disable:next cyclomatic_complexity
|
//swiftlint:disable:next cyclomatic_complexity
|
||||||
func save() -> SaveResult<PeerConfiguration> {
|
func save() -> SaveResult<PeerConfiguration> {
|
||||||
if let validatedConfiguration = validatedConfiguration {
|
if let validatedConfiguration = validatedConfiguration {
|
||||||
// It's already validated and saved
|
|
||||||
return .saved(validatedConfiguration)
|
return .saved(validatedConfiguration)
|
||||||
}
|
}
|
||||||
fieldsWithError.removeAll()
|
fieldsWithError.removeAll()
|
||||||
|
@ -331,7 +317,6 @@ class TunnelViewModel {
|
||||||
}
|
}
|
||||||
return (!self[field].isEmpty)
|
return (!self[field].isEmpty)
|
||||||
}
|
}
|
||||||
// TODO: Cache this to avoid recomputing
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static let ipv4DefaultRouteString = "0.0.0.0/0"
|
static let ipv4DefaultRouteString = "0.0.0.0/0"
|
||||||
|
@ -378,7 +363,7 @@ class TunnelViewModel {
|
||||||
modifiedAllowedIPStrings = ipv6Addresses + [TunnelViewModel.PeerData.ipv4DefaultRouteString]
|
modifiedAllowedIPStrings = ipv6Addresses + [TunnelViewModel.PeerData.ipv4DefaultRouteString]
|
||||||
}
|
}
|
||||||
scratchpad[.allowedIPs] = modifiedAllowedIPStrings.joined(separator: ", ")
|
scratchpad[.allowedIPs] = modifiedAllowedIPStrings.joined(separator: ", ")
|
||||||
validatedConfiguration = nil // The configuration has been modified, and needs to be saved
|
validatedConfiguration = nil
|
||||||
excludePrivateIPsValue = isOn
|
excludePrivateIPsValue = isOn
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -435,10 +420,8 @@ class TunnelViewModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
func save() -> SaveResult<TunnelConfiguration> {
|
func save() -> SaveResult<TunnelConfiguration> {
|
||||||
// Attempt to save the interface and all peers, so that all erroring fields are collected
|
|
||||||
let interfaceSaveResult = interfaceData.save()
|
let interfaceSaveResult = interfaceData.save()
|
||||||
let peerSaveResults = peersData.map { $0.save() }
|
let peerSaveResults = peersData.map { $0.save() } // Save all, to help mark erroring fields in red
|
||||||
// Collate the results
|
|
||||||
switch interfaceSaveResult {
|
switch interfaceSaveResult {
|
||||||
case .error(let errorMessage):
|
case .error(let errorMessage):
|
||||||
return .error(errorMessage)
|
return .error(errorMessage)
|
||||||
|
@ -466,8 +449,6 @@ class TunnelViewModel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Activate on demand
|
|
||||||
|
|
||||||
extension TunnelViewModel {
|
extension TunnelViewModel {
|
||||||
static func activateOnDemandOptionText(for activateOnDemandOption: ActivateOnDemandOption) -> String {
|
static func activateOnDemandOptionText(for activateOnDemandOption: ActivateOnDemandOption) -> String {
|
||||||
switch activateOnDemandOption {
|
switch activateOnDemandOption {
|
||||||
|
|
|
@ -38,8 +38,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: State restoration
|
|
||||||
|
|
||||||
extension AppDelegate {
|
extension AppDelegate {
|
||||||
func application(_ application: UIApplication, shouldSaveApplicationState coder: NSCoder) -> Bool {
|
func application(_ application: UIApplication, shouldSaveApplicationState coder: NSCoder) -> Bool {
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -148,8 +148,6 @@ class SettingsTableViewController: UITableViewController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: UITableViewDataSource
|
|
||||||
|
|
||||||
extension SettingsTableViewController {
|
extension SettingsTableViewController {
|
||||||
override func numberOfSections(in tableView: UITableView) -> Int {
|
override func numberOfSections(in tableView: UITableView) -> Int {
|
||||||
return settingsFieldsBySection.count
|
return settingsFieldsBySection.count
|
||||||
|
|
|
@ -90,8 +90,6 @@ class TunnelDetailTableViewController: UITableViewController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: TunnelEditTableViewControllerDelegate
|
|
||||||
|
|
||||||
extension TunnelDetailTableViewController: TunnelEditTableViewControllerDelegate {
|
extension TunnelDetailTableViewController: TunnelEditTableViewControllerDelegate {
|
||||||
func tunnelSaved(tunnel: TunnelContainer) {
|
func tunnelSaved(tunnel: TunnelContainer) {
|
||||||
tunnelViewModel = TunnelViewModel(tunnelConfiguration: tunnel.tunnelConfiguration)
|
tunnelViewModel = TunnelViewModel(tunnelConfiguration: tunnel.tunnelConfiguration)
|
||||||
|
@ -105,8 +103,6 @@ extension TunnelDetailTableViewController: TunnelEditTableViewControllerDelegate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: UITableViewDataSource
|
|
||||||
|
|
||||||
extension TunnelDetailTableViewController {
|
extension TunnelDetailTableViewController {
|
||||||
override func numberOfSections(in tableView: UITableView) -> Int {
|
override func numberOfSections(in tableView: UITableView) -> Int {
|
||||||
return sections.count
|
return sections.count
|
||||||
|
|
|
@ -469,8 +469,6 @@ extension TunnelEditTableViewController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: UITableViewDelegate
|
|
||||||
|
|
||||||
extension TunnelEditTableViewController {
|
extension TunnelEditTableViewController {
|
||||||
override func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
|
override func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
|
||||||
if case .onDemand = sections[indexPath.section], indexPath.row > 0 {
|
if case .onDemand = sections[indexPath.section], indexPath.row > 0 {
|
||||||
|
|
|
@ -196,8 +196,6 @@ class TunnelsListTableViewController: UIViewController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: UIDocumentPickerDelegate
|
|
||||||
|
|
||||||
extension TunnelsListTableViewController: UIDocumentPickerDelegate {
|
extension TunnelsListTableViewController: UIDocumentPickerDelegate {
|
||||||
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
|
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
|
||||||
urls.forEach {
|
urls.forEach {
|
||||||
|
@ -206,8 +204,6 @@ extension TunnelsListTableViewController: UIDocumentPickerDelegate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: QRScanViewControllerDelegate
|
|
||||||
|
|
||||||
extension TunnelsListTableViewController: QRScanViewControllerDelegate {
|
extension TunnelsListTableViewController: QRScanViewControllerDelegate {
|
||||||
func addScannedQRCode(tunnelConfiguration: TunnelConfiguration, qrScanViewController: QRScanViewController,
|
func addScannedQRCode(tunnelConfiguration: TunnelConfiguration, qrScanViewController: QRScanViewController,
|
||||||
completionHandler: (() -> Void)?) {
|
completionHandler: (() -> Void)?) {
|
||||||
|
@ -221,8 +217,6 @@ extension TunnelsListTableViewController: QRScanViewControllerDelegate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: UITableViewDataSource
|
|
||||||
|
|
||||||
extension TunnelsListTableViewController: UITableViewDataSource {
|
extension TunnelsListTableViewController: UITableViewDataSource {
|
||||||
func numberOfSections(in tableView: UITableView) -> Int {
|
func numberOfSections(in tableView: UITableView) -> Int {
|
||||||
return 1
|
return 1
|
||||||
|
@ -250,8 +244,6 @@ extension TunnelsListTableViewController: UITableViewDataSource {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: UITableViewDelegate
|
|
||||||
|
|
||||||
extension TunnelsListTableViewController: UITableViewDelegate {
|
extension TunnelsListTableViewController: UITableViewDelegate {
|
||||||
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||||
guard let tunnelsManager = tunnelsManager else { return }
|
guard let tunnelsManager = tunnelsManager else { return }
|
||||||
|
@ -281,8 +273,6 @@ extension TunnelsListTableViewController: UITableViewDelegate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: TunnelsManagerDelegate
|
|
||||||
|
|
||||||
extension TunnelsListTableViewController: TunnelsManagerListDelegate {
|
extension TunnelsListTableViewController: TunnelsManagerListDelegate {
|
||||||
func tunnelAdded(at index: Int) {
|
func tunnelAdded(at index: Int) {
|
||||||
tableView.insertRows(at: [IndexPath(row: index, section: 0)], with: .automatic)
|
tableView.insertRows(at: [IndexPath(row: index, section: 0)], with: .automatic)
|
||||||
|
|
Loading…
Reference in New Issue