-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #46: Reworked bridge fetch UI as per spec.
- Loading branch information
1 parent
abb8378
commit 35cf544
Showing
8 changed files
with
280 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
// | ||
// CaptchaViewController.swift | ||
// Orbot | ||
// | ||
// Created by Benjamin Erhart on 16.01.23. | ||
// Copyright © 2023 Guardian Project. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import IPtProxyUI | ||
import MBProgressHUD | ||
|
||
class CaptchaViewController: UIViewController { | ||
|
||
open weak var delegate: BridgesConfDelegate? | ||
|
||
@IBOutlet weak var captchaIv: UIImageView! { | ||
didSet { | ||
captchaIv.accessibilityLabel = MoatViewController.captchaImageText | ||
} | ||
} | ||
|
||
@IBOutlet weak var solutionTf: UITextField! { | ||
didSet { | ||
solutionTf.placeholder = NSLocalizedString("Enter text above", comment: "") | ||
} | ||
} | ||
|
||
@IBOutlet weak var saveBt: UIButton! { | ||
didSet { | ||
saveBt.setTitle(NSLocalizedString("Save", bundle: .iPtProxyUI, comment: "#bc-ignore!")) | ||
} | ||
} | ||
|
||
|
||
private var challenge: String? | ||
|
||
|
||
static func make() -> Self { | ||
UIStoryboard.main.instantiateViewController(withIdentifier: "captcha_vc") as! Self | ||
} | ||
|
||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
navigationItem.title = NSLocalizedString("Solve CAPTCHA", comment: "") | ||
} | ||
|
||
override func viewWillAppear(_ animated: Bool) { | ||
super.viewWillAppear(animated) | ||
|
||
delegate?.startMeek() | ||
|
||
fetchCaptcha(nil) | ||
} | ||
|
||
override func viewWillDisappear(_ animated: Bool) { | ||
super.viewWillDisappear(animated) | ||
|
||
delegate?.stopMeek() | ||
} | ||
|
||
|
||
// MARK: Actions | ||
|
||
@IBAction | ||
func save() { | ||
let hud = MBProgressHUD.showAdded(to: view, animated: true) | ||
|
||
MoatViewController.requestBridges(delegate, challenge, solutionTf.text) { [weak self] bridges, error in | ||
DispatchQueue.main.async { | ||
guard let self = self else { | ||
return | ||
} | ||
|
||
hud.hide(animated: true) | ||
|
||
if let error = error { | ||
AlertHelper.present(self, message: error.localizedDescription) | ||
return | ||
} | ||
|
||
guard let bridges = bridges else { | ||
return | ||
} | ||
|
||
self.delegate?.customBridges = bridges | ||
self.delegate?.transport = .custom | ||
|
||
self.delegate?.save() | ||
|
||
self.navigationController?.popViewController(animated: true) | ||
} | ||
} | ||
} | ||
|
||
|
||
// MARK: Private Methods | ||
|
||
@objc private func fetchCaptcha(_ sender: Any?) { | ||
let hud = MBProgressHUD.showAdded(to: view, animated: true) | ||
|
||
MoatViewController.fetchCaptcha(delegate) { [weak self] challenge, captcha, error in | ||
DispatchQueue.main.async { | ||
guard let self = self else { | ||
return | ||
} | ||
|
||
hud.hide(animated: true) | ||
|
||
if let error = error { | ||
AlertHelper.present(self, message: error.localizedDescription) | ||
return | ||
} | ||
|
||
self.challenge = challenge | ||
|
||
if let captcha = captcha { | ||
self.captchaIv.image = UIImage(data: captcha) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.