diff options
Diffstat (limited to '')
4 files changed, 36 insertions, 43 deletions
diff --git a/WireGuard/WireGuard/UI/iOS/ErrorPresenter.swift b/WireGuard/WireGuard/UI/iOS/ErrorPresenter.swift index 7c28495..2889694 100644 --- a/WireGuard/WireGuard/UI/iOS/ErrorPresenter.swift +++ b/WireGuard/WireGuard/UI/iOS/ErrorPresenter.swift @@ -5,10 +5,10 @@ import UIKit import os.log class ErrorPresenter { - static func showErrorAlert(error: WireGuardAppError, from sourceVC: UIViewController?, - onPresented: (() -> Void)? = nil, onDismissal: (() -> Void)? = nil) { + static func showErrorAlert(error: WireGuardAppError, from sourceVC: UIViewController?, onPresented: (() -> Void)? = nil, onDismissal: (() -> Void)? = nil) { guard let sourceVC = sourceVC else { return } - guard let (title, message) = error.alertText() else { return } + + let (title, message) = error.alertText() let okAction = UIAlertAction(title: "OK", style: .default) { _ in onDismissal?() } @@ -18,9 +18,9 @@ class ErrorPresenter { sourceVC.present(alert, animated: true, completion: onPresented) } - static func showErrorAlert(title: String, message: String, from sourceVC: UIViewController?, - onPresented: (() -> Void)? = nil, onDismissal: (() -> Void)? = nil) { + static func showErrorAlert(title: String, message: String, from sourceVC: UIViewController?, onPresented: (() -> Void)? = nil, onDismissal: (() -> Void)? = nil) { guard let sourceVC = sourceVC else { return } + let okAction = UIAlertAction(title: "OK", style: .default) { _ in onDismissal?() } diff --git a/WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift b/WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift index e6ad024..c5816e8 100644 --- a/WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift +++ b/WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift @@ -322,9 +322,9 @@ private class KeyValueCell: CopyableLabelTableViewCell { let keyLabel: UILabel let valueLabel: ScrollableLabel - var isStackedHorizontally: Bool = false - var isStackedVertically: Bool = false - var contentSizeBasedConstraints: [NSLayoutConstraint] = [] + var isStackedHorizontally = false + var isStackedVertically = false + var contentSizeBasedConstraints = [NSLayoutConstraint]() override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { keyLabel = UILabel() @@ -364,7 +364,7 @@ private class KeyValueCell: CopyableLabelTableViewCell { } func configureForContentSize() { - var constraints: [NSLayoutConstraint] = [] + var constraints = [NSLayoutConstraint]() if self.traitCollection.preferredContentSizeCategory.isAccessibilityCategory { // Stack vertically if !isStackedVertically { diff --git a/WireGuard/WireGuard/UI/iOS/TunnelEditTableViewController.swift b/WireGuard/WireGuard/UI/iOS/TunnelEditTableViewController.swift index b26992d..7cd96a2 100644 --- a/WireGuard/WireGuard/UI/iOS/TunnelEditTableViewController.swift +++ b/WireGuard/WireGuard/UI/iOS/TunnelEditTableViewController.swift @@ -334,52 +334,45 @@ extension TunnelEditTableViewController { switch field { case .publicKey: cell.placeholderText = "Required" - case .preSharedKey, .endpoint, .allowedIPs: + cell.keyboardType = .default + case .preSharedKey, .endpoint: + cell.placeholderText = "Optional" + cell.keyboardType = .default + case .allowedIPs: cell.placeholderText = "Optional" + cell.keyboardType = .numbersAndPunctuation case .persistentKeepAlive: cell.placeholderText = "Off" - case .excludePrivateIPs, .deletePeer: - break - } - - switch field { - case .persistentKeepAlive: cell.keyboardType = .numberPad - case .allowedIPs: - cell.keyboardType = .numbersAndPunctuation - default: + case .excludePrivateIPs, .deletePeer: cell.keyboardType = .default } - // Show erroring fields - cell.isValueValid = (!peerData.fieldsWithError.contains(field)) - // Bind values to view model + cell.isValueValid = !peerData.fieldsWithError.contains(field) cell.value = peerData[field] - if field != .allowedIPs { - cell.onValueChanged = { [weak peerData] value in - peerData?[field] = value - } - } - // Compute state of exclude private IPs live + if field == .allowedIPs { cell.onValueBeingEdited = { [weak self, weak peerData] value in - if let peerData = peerData, let self = self { - let oldValue = peerData.shouldAllowExcludePrivateIPsControl - peerData[.allowedIPs] = value - if oldValue != peerData.shouldAllowExcludePrivateIPsControl { - if let row = self.peerFields.firstIndex(of: .excludePrivateIPs) { - if peerData.shouldAllowExcludePrivateIPsControl { - self.tableView.insertRows(at: [IndexPath(row: row, section: indexPath.section)], with: .fade) - } else { - self.tableView.deleteRows(at: [IndexPath(row: row, section: indexPath.section)], with: .fade) - } + guard let self = self, let peerData = peerData else { return } + + let oldValue = peerData.shouldAllowExcludePrivateIPsControl + peerData[.allowedIPs] = value + if oldValue != peerData.shouldAllowExcludePrivateIPsControl { + if let row = self.peerFields.firstIndex(of: .excludePrivateIPs) { + if peerData.shouldAllowExcludePrivateIPsControl { + self.tableView.insertRows(at: [IndexPath(row: row, section: indexPath.section)], with: .fade) + } else { + self.tableView.deleteRows(at: [IndexPath(row: row, section: indexPath.section)], with: .fade) } } } } } else { - cell.onValueBeingEdited = nil + cell.onValueChanged = { [weak peerData] value in + peerData?[field] = value + } } + return cell } @@ -410,7 +403,7 @@ extension TunnelEditTableViewController { cell.isOn = activateOnDemandSetting.isActivateOnDemandEnabled cell.onSwitchToggled = { [weak self] isOn in guard let self = self else { return } - let indexPaths: [IndexPath] = (1 ..< 4).map { IndexPath(row: $0, section: indexPath.section) } + let indexPaths = (1 ..< 4).map { IndexPath(row: $0, section: indexPath.section) } if isOn { self.activateOnDemandSetting.isActivateOnDemandEnabled = true if self.activateOnDemandSetting.activateOnDemandOption == .none { @@ -529,7 +522,7 @@ private class KeyValueCell: UITableViewCell { var isStackedHorizontally: Bool = false var isStackedVertically: Bool = false - var contentSizeBasedConstraints: [NSLayoutConstraint] = [] + var contentSizeBasedConstraints = [NSLayoutConstraint]() private var textFieldValueOnBeginEditing: String = "" @@ -573,7 +566,7 @@ private class KeyValueCell: UITableViewCell { } func configureForContentSize() { - var constraints: [NSLayoutConstraint] = [] + var constraints = [NSLayoutConstraint]() if self.traitCollection.preferredContentSizeCategory.isAccessibilityCategory { // Stack vertically if !isStackedVertically { diff --git a/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift b/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift index e5d5af1..f24b452 100644 --- a/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift +++ b/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift @@ -173,7 +173,7 @@ class TunnelsListTableViewController: UIViewController { ErrorPresenter.showErrorAlert(error: error, from: self) return } - let configs: [TunnelConfiguration?] = result.value! + let configs = result.value! tunnelsManager.addMultiple(tunnelConfigurations: configs.compactMap { $0 }) { [weak self] numberSuccessful in if numberSuccessful == configs.count { completionHandler?() |