Skip to content

Commit

Permalink
Issue #46: Reworked bridge fetch UI as per spec.
Browse files Browse the repository at this point in the history
  • Loading branch information
tladesignz committed Jan 17, 2023
1 parent abb8378 commit 35cf544
Show file tree
Hide file tree
Showing 8 changed files with 280 additions and 33 deletions.
4 changes: 4 additions & 0 deletions Orbot.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
A06DDCAF29264D0E001F9371 /* DebugMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = A06DDCAC29264D0E001F9371 /* DebugMessage.swift */; };
A06DDCB029264D0E001F9371 /* DebugMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = A06DDCAC29264D0E001F9371 /* DebugMessage.swift */; };
A08688172975A2310032B141 /* ScanViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A08688162975A2310032B141 /* ScanViewController.swift */; };
A086881B2975B4F80032B141 /* CaptchaViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A086881A2975B4F80032B141 /* CaptchaViewController.swift */; };
A08C8FF02805D7220065B98D /* BlockerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A08C8FEF2805D7220065B98D /* BlockerViewController.swift */; };
A08C8FF22805FB130065B98D /* Eureka+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = A08C8FF12805FB130065B98D /* Eureka+Helpers.swift */; };
A0A039B1274E9DF400D80FD1 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = A0A039B3274E9DF400D80FD1 /* InfoPlist.strings */; };
Expand Down Expand Up @@ -332,6 +333,7 @@
A06C96F5273C36AE0019ABE5 /* Settings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Settings.swift; sourceTree = "<group>"; };
A06DDCAC29264D0E001F9371 /* DebugMessage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DebugMessage.swift; sourceTree = "<group>"; };
A08688162975A2310032B141 /* ScanViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScanViewController.swift; sourceTree = "<group>"; };
A086881A2975B4F80032B141 /* CaptchaViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CaptchaViewController.swift; sourceTree = "<group>"; };
A08C8FEF2805D7220065B98D /* BlockerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlockerViewController.swift; sourceTree = "<group>"; };
A08C8FF12805FB130065B98D /* Eureka+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Eureka+Helpers.swift"; sourceTree = "<group>"; };
A08CA2C827DB697500F23100 /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/InfoPlist.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -555,6 +557,7 @@
A05B73B724755CE600930C40 /* MainViewController.swift */,
A0EF119828043A9200A03017 /* BaseFormViewController.swift */,
A04672E9296DC85400BD0F2F /* BridgesViewController.swift */,
A086881A2975B4F80032B141 /* CaptchaViewController.swift */,
A05DCD05297198540017B36A /* CustomBridgesViewController.swift */,
A08688162975A2310032B141 /* ScanViewController.swift */,
A0C1D8A9292F840E00EB9DBB /* ChangeExitViewController.swift */,
Expand Down Expand Up @@ -1372,6 +1375,7 @@
A06470182477F7E900311CBE /* UITextView+Helpers.swift in Sources */,
A01F34DF2652D082008F9912 /* Logger.swift in Sources */,
A05DCD0829719A1B0017B36A /* UIStoryboard.swift in Sources */,
A086881B2975B4F80032B141 /* CaptchaViewController.swift in Sources */,
A0A735E1247566CD00073C81 /* Config.m in Sources */,
A0A735EC24756CA200073C81 /* Message.swift in Sources */,
A0A735F224756D6B00073C81 /* FileManager+Helpers.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion Orbot/BridgesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class BridgesViewController: BaseFormViewController, BridgesConfDelegate {
.onCellSelection({ [weak self] cell, row in
switch self?.section.selectedRow()?.value ?? .direct {
case .request:
let vc = MoatViewController()
let vc = CaptchaViewController.make()
vc.delegate = self
self?.navigationController?.pushViewController(vc, animated: true)

Expand Down
125 changes: 125 additions & 0 deletions Orbot/CaptchaViewController.swift
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)
}
}
}
}
}
4 changes: 2 additions & 2 deletions Orbot/CustomBridgesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import IPtProxyUI

class CustomBridgesViewController: UIViewController, UITextViewDelegate, ScanQrDelegate {

static func make() -> CustomBridgesViewController {
UIStoryboard.main.instantiateViewController(withIdentifier: "custom_bridges_vc") as! CustomBridgesViewController
static func make() -> Self {
UIStoryboard.main.instantiateViewController(withIdentifier: "custom_bridges_vc") as! Self
}


Expand Down
Loading

0 comments on commit 35cf544

Please sign in to comment.