Skip to content

Commit

Permalink
Fix Proxy functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
martenrebane committed Feb 15, 2024
1 parent e38bbf4 commit 20dd013
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 402 deletions.
4 changes: 0 additions & 4 deletions MoppApp/MoppApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@
DF900C972386768F00887385 /* tslFiles.bundle in Resources */ = {isa = PBXBuildFile; fileRef = DF900C94238567CA00887385 /* tslFiles.bundle */; };
DF9709692B4D79E400361544 /* ProxyCategoryCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF9709682B4D79E400361544 /* ProxyCategoryCell.swift */; };
DF97096B2B4D7A4600361544 /* ProxyViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF97096A2B4D7A4600361544 /* ProxyViewController.swift */; };
DF97096D2B4D7AA900361544 /* SettingsProxyCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF97096C2B4D7AA900361544 /* SettingsProxyCell.swift */; };
DF97096F2B4D92A700361544 /* ProxyChoiceTapGestureRecognizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF97096E2B4D92A700361544 /* ProxyChoiceTapGestureRecognizer.swift */; };
DF97A51129DC8CAB006FB917 /* ContainerAddAllButtonCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF97A51029DC8CAB006FB917 /* ContainerAddAllButtonCell.swift */; };
DFA56CF22AF003F8007D7F7E /* RadioButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFA56CF12AF003F8007D7F7E /* RadioButton.swift */; };
Expand Down Expand Up @@ -557,7 +556,6 @@
DF900C94238567CA00887385 /* tslFiles.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = tslFiles.bundle; sourceTree = "<group>"; };
DF9709682B4D79E400361544 /* ProxyCategoryCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProxyCategoryCell.swift; sourceTree = "<group>"; };
DF97096A2B4D7A4600361544 /* ProxyViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProxyViewController.swift; sourceTree = "<group>"; };
DF97096C2B4D7AA900361544 /* SettingsProxyCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsProxyCell.swift; sourceTree = "<group>"; };
DF97096E2B4D92A700361544 /* ProxyChoiceTapGestureRecognizer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProxyChoiceTapGestureRecognizer.swift; sourceTree = "<group>"; };
DF97A51029DC8CAB006FB917 /* ContainerAddAllButtonCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerAddAllButtonCell.swift; sourceTree = "<group>"; };
DFA56CF12AF003F8007D7F7E /* RadioButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadioButton.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -967,7 +965,6 @@
DF8EFB19287498B900A96DE3 /* SettingsDefaultValueCell.swift */,
DFD54CF429CDDB0600CD92C7 /* SettingsTSACertCell.swift */,
DFBDF1F127D79B8B00A5CF3C /* SettingsStateCell.swift */,
DF97096C2B4D7AA900361544 /* SettingsProxyCell.swift */,
DF3756172AFABEB7006960C5 /* SettingsResetCell.swift */,
);
name = Settings;
Expand Down Expand Up @@ -1765,7 +1762,6 @@
C5964CE820079AE0001FE732 /* TabButton.swift in Sources */,
3921CA9920B2F5B200BF3178 /* PreviewActions.swift in Sources */,
DFBA32A629A5A64000788A87 /* CancelUtil.swift in Sources */,
DF97096D2B4D7AA900361544 /* SettingsProxyCell.swift in Sources */,
DFBDF1FC27DF6BA800A5CF3C /* MobileIDParameters.swift in Sources */,
C56C620F201A2B6500CCC2A5 /* RecentContainersHeaderCell.swift in Sources */,
C593D9F4208F3526000B3BF6 /* SettingsChoiceView.swift in Sources */,
Expand Down
139 changes: 66 additions & 73 deletions MoppApp/MoppApp/ProxyViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import UIKit
import SkSigningLib

class ProxyViewController: MoppViewController, UITextFieldDelegate {
class ProxyViewController: MoppViewController {

@IBOutlet weak var scrollView: UIScrollView!

Expand Down Expand Up @@ -87,12 +87,8 @@ class ProxyViewController: MoppViewController, UITextFieldDelegate {
view.backgroundColor = .gray.withAlphaComponent(0.5)
}

override func keyboardWillShow(notification: NSNotification) {
// tableView.setContentOffset(CGPoint(x: 0, y: (currentlyEditingField?.frame.origin.y ?? 0)), animated: true)
}

override func keyboardWillHide(notification: NSNotification) {
// tableView.setContentOffset(CGPoint(x: 0, y: 0), animated: true)
hideKeyboard(scrollView: scrollView)
}

override func viewDidLoad() {
Expand Down Expand Up @@ -218,11 +214,6 @@ class ProxyViewController: MoppViewController, UITextFieldDelegate {

func updateUI() {
DispatchQueue.main.async {

// self.proxyChoicesStackView.isAccessibilityElement = false

// self.setAccessibilityElementsInStackView(stackView: self.proxyChoicesStackView, isAccessibilityElement: true)

let savedProxySetting = DefaultsHelper.proxySetting
self.useNoProxyRadioButton.setSelectedState(state: savedProxySetting == .noProxy)
self.useSystemProxyRadioButton.setSelectedState(state: savedProxySetting == .systemProxy)
Expand Down Expand Up @@ -309,70 +300,8 @@ class ProxyViewController: MoppViewController, UITextFieldDelegate {
}
printLog("Deinit SettingsProxyCell")
}




}

//extension ProxyViewController: UITableViewDelegate, UITableViewDataSource {
// func numberOfSections(in tableView: UITableView) -> Int {
// return sections.count
// }
//
// func tableView(_ tableView: UITableView, numberOfRowsInSection section_: Int) -> Int {
// switch sections[section_] {
// case .header:
// return 1
// case .fields:
// return fields.count
// }
// }
//
// func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
// return UITableView.automaticDimension
// }
//
// func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
// tableView.estimatedRowHeight = 44
// return UITableView.automaticDimension
// }
//
// func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// switch sections[indexPath.section] {
// case .header:
// let headerCell = tableView.dequeueReusableCell(withType: SettingsHeaderCell.self, for: indexPath)!
// headerCell.delegate = self
// headerCell.populate(with: " ")
// headerCell.titleLabel.isAccessibilityElement = false
// return headerCell
// case .fields:
// let field = fields[indexPath.row]
// switch field {
// case .proxy:
// let proxyCell = tableView.dequeueReusableCell(withType: SettingsProxyCell.self, for: indexPath)!
// proxyCell.topViewController = getTopViewController()
// proxyCell.delegate = self
// proxyCell.populate()
// return proxyCell
// }
// }
// }
//
// @objc func editingChanged(sender: UITextField) {
// let text = sender.text ?? String()
// if (text.count > 11) {
// sender.deleteBackward()
// }
// }
//}

//extension ProxyViewController: SettingsHeaderCellDelegate {
// func didDismissSettings() {
// dismiss(animated: true, completion: nil)
// }
//}

extension ProxyViewController: SettingsCellDelegate {
func didStartEditingField(_ field: SigningCategoryViewController.FieldId, _ textField: UITextField) {
switch field {
Expand Down Expand Up @@ -401,3 +330,67 @@ extension ProxyViewController: SettingsCellDelegate {
UIAccessibility.post(notification: .screenChanged, argument: L(.settingsValueChanged))
}
}

extension ProxyViewController: UITextFieldDelegate {
func textFieldDidBeginEditing(_ textField: UITextField) {

DispatchQueue.main.async {
textField.moveCursorToEnd()
}

switch textField {
case hostTextField:
showKeyboard(textFieldLabel: hostLabel, scrollView: scrollView)
case portTextField:
showKeyboard(textFieldLabel: portLabel, scrollView: scrollView)
case usernameTextField:
showKeyboard(textFieldLabel: usernameLabel, scrollView: scrollView)
case passwordTextField:
showKeyboard(textFieldLabel: passwordLabel, scrollView: scrollView)
default:
break
}
}

func textFieldDidEndEditing(_ textField: UITextField) {
switch textField {
case hostTextField:
DefaultsHelper.proxyHost = textField.text
case portTextField:
DefaultsHelper.proxyPort = Int(textField.text ?? "80") ?? 80
case usernameTextField:
DefaultsHelper.proxyUsername = textField.text
case passwordTextField:
let _ = KeychainUtil.save(key: proxyPasswordKey, info: textField.text ?? "")
default:
break
}
UIAccessibility.post(notification: UIAccessibility.Notification.screenChanged, argument: textField)
}

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {

// Allow only numeric characters
if textField == portTextField {

let allowedCharacterSet = CharacterSet.decimalDigits
let inputCharacterSet = CharacterSet(charactersIn: string)

guard allowedCharacterSet.isSuperset(of: inputCharacterSet) else {
return false
}

guard let text = textField.text as? NSString else { return false }
let portNumber = text.replacingCharacters(in: range, with: string)
guard let number = Int(portNumber) else { if portNumber.isEmpty { return true }; return false }

// Check if port number is within range
let isValidPortNumber = isPortNumberValid(portNumber: Int(number))
portErrorLabel.isHidden = isValidPortNumber

return true
}
return true
}
}

Loading

0 comments on commit 20dd013

Please sign in to comment.