Skip to content

Commit

Permalink
Issue #46: Added first shot at new custom bridge scene.
Browse files Browse the repository at this point in the history
  • Loading branch information
tladesignz committed Jan 13, 2023
1 parent 0fb6e2d commit bd9af9d
Show file tree
Hide file tree
Showing 5 changed files with 305 additions and 32 deletions.
8 changes: 8 additions & 0 deletions Orbot.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
A05B73B824755CE600930C40 /* MainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A05B73B724755CE600930C40 /* MainViewController.swift */; };
A05B73BD24755CE700930C40 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A05B73BC24755CE700930C40 /* Assets.xcassets */; };
A05DCD04297191760017B36A /* RoundedButtonRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = A05DCD03297191760017B36A /* RoundedButtonRow.swift */; };
A05DCD06297198540017B36A /* CustomBridgesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A05DCD05297198540017B36A /* CustomBridgesViewController.swift */; };
A05DCD0829719A1B0017B36A /* UIStoryboard.swift in Sources */ = {isa = PBXBuildFile; fileRef = A05DCD0729719A1B0017B36A /* UIStoryboard.swift */; };
A06470182477F7E900311CBE /* UITextView+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = A06470172477F7E900311CBE /* UITextView+Helpers.swift */; };
A06BEC73280090B300351868 /* ContentBlockerRequestHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = A06BEC72280090B300351868 /* ContentBlockerRequestHandler.swift */; };
A06BEC77280090B300351868 /* ContentBlocker.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = A06BEC6E280090B300351868 /* ContentBlocker.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
Expand Down Expand Up @@ -315,6 +317,8 @@
A05B73BC24755CE700930C40 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
A05B73C124755CE700930C40 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
A05DCD03297191760017B36A /* RoundedButtonRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoundedButtonRow.swift; sourceTree = "<group>"; };
A05DCD05297198540017B36A /* CustomBridgesViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomBridgesViewController.swift; sourceTree = "<group>"; };
A05DCD0729719A1B0017B36A /* UIStoryboard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIStoryboard.swift; sourceTree = "<group>"; };
A06470172477F7E900311CBE /* UITextView+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UITextView+Helpers.swift"; sourceTree = "<group>"; };
A064701A2478170F00311CBE /* README.md */ = {isa = PBXFileReference; indentWidth = 2; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; tabWidth = 2; usesTabs = 0; };
A064701B24781C5400311CBE /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
Expand Down Expand Up @@ -549,6 +553,7 @@
A05B73B724755CE600930C40 /* MainViewController.swift */,
A0EF119828043A9200A03017 /* BaseFormViewController.swift */,
A04672E9296DC85400BD0F2F /* BridgesViewController.swift */,
A05DCD05297198540017B36A /* CustomBridgesViewController.swift */,
A0C1D8A9292F840E00EB9DBB /* ChangeExitViewController.swift */,
A04E3678273D4BF100578FD4 /* AuthViewController.swift */,
A0DF48B928250A7F001EED78 /* ApiAccessViewController.swift */,
Expand Down Expand Up @@ -694,6 +699,7 @@
A0EF1196280439C200A03017 /* ContentBlockerViewController.swift */,
A08C8FEF2805D7220065B98D /* BlockerViewController.swift */,
A0EF119B280441C400A03017 /* BlockList.swift */,
A05DCD0729719A1B0017B36A /* UIStoryboard.swift */,
);
path = ContentBlocker;
sourceTree = "<group>";
Expand Down Expand Up @@ -1350,6 +1356,7 @@
A05DCD04297191760017B36A /* RoundedButtonRow.swift in Sources */,
A04672EA296DC85400BD0F2F /* BridgesViewController.swift in Sources */,
A0B167DE284F90560089EB7C /* ApiAccessCell.swift in Sources */,
A05DCD06297198540017B36A /* CustomBridgesViewController.swift in Sources */,
A0BBF1A927D77B18005BBA3A /* SettingsViewController.swift in Sources */,
A009F0822812EE9400A04480 /* TorCircuit+Helper.swift in Sources */,
A0A73608247587D300073C81 /* UIButton+Helpers.swift in Sources */,
Expand All @@ -1361,6 +1368,7 @@
A0A735EE24756CA200073C81 /* GetCircuitsMessage.swift in Sources */,
A06470182477F7E900311CBE /* UITextView+Helpers.swift in Sources */,
A01F34DF2652D082008F9912 /* Logger.swift in Sources */,
A05DCD0829719A1B0017B36A /* UIStoryboard.swift in Sources */,
A0A735E1247566CD00073C81 /* Config.m in Sources */,
A0A735EC24756CA200073C81 /* Message.swift in Sources */,
A0A735F224756D6B00073C81 /* FileManager+Helpers.swift in Sources */,
Expand Down
55 changes: 23 additions & 32 deletions Orbot/BridgesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,30 +74,19 @@ class BridgesViewController: BaseFormViewController, BridgesConfDelegate {
}
}

var transport: IPtProxyUI.Transport {
get {
Settings.transport
}
set {
Settings.transport = newValue
}
}
var transport: Transport = .none

var customBridges: [String]? {
get {
Settings.customBridges
}
set {
Settings.customBridges = newValue
}
}
var customBridges: [String]? = nil

private let section = SelectableSection<ListCheckRow<Option>>(nil, selectionType: .singleSelection(enableDeselection: false))


override func viewDidLoad() {
super.viewDidLoad()

transport = Settings.transport
customBridges = Settings.customBridges

tableView.separatorStyle = .none

navigationItem.title = NSLocalizedString("Choose How to Connect", comment: "")
Expand Down Expand Up @@ -140,7 +129,7 @@ class BridgesViewController: BaseFormViewController, BridgesConfDelegate {
row.title = NSLocalizedString("Next", comment: "")

default:
row.title = NSLocalizedString("Save", comment: "")
row.title = NSLocalizedString("Save", bundle: .iPtProxyUI, comment: "#bc-ignore!")
}
})
.onCellSelection({ [weak self] cell, row in
Expand All @@ -151,11 +140,25 @@ class BridgesViewController: BaseFormViewController, BridgesConfDelegate {
self?.navigationController?.pushViewController(vc, animated: true)

case .custom:
let vc = CustomBridgesViewController()
let vc = CustomBridgesViewController.make()
vc.delegate = self
self?.navigationController?.pushViewController(vc, animated: true)

default:
switch self?.section.selectedRow()?.value ?? .direct {
case .direct:
self?.transport = .none

case .snowflake:
self?.transport = .snowflake

case .snowflakeAmp:
self?.transport = .snowflakeAmp

default:
break
}

self?.save()
}
})
Expand All @@ -164,20 +167,8 @@ class BridgesViewController: BaseFormViewController, BridgesConfDelegate {
@objc
func save() {
Settings.smartConnect = false

switch section.selectedRow()?.value ?? .direct {
case .direct:
Settings.transport = .none

case .snowflake:
Settings.transport = .snowflake

case .snowflakeAmp:
Settings.transport = .snowflakeAmp

case .request, .custom:
Settings.transport = .custom
}
Settings.transport = transport
Settings.customBridges = customBridges

navigationController?.dismiss(animated: true)

Expand Down
14 changes: 14 additions & 0 deletions Orbot/ContentBlocker/UIStoryboard.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// UIStoryboard.swift
// Orbot
//
// Created by Benjamin Erhart on 13.01.23.
// Copyright © 2023 Guardian Project. All rights reserved.
//

import UIKit

extension UIStoryboard {

static let main = UIStoryboard(name: "Main", bundle: nil)
}
140 changes: 140 additions & 0 deletions Orbot/CustomBridgesViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
//
// CustomBridgesViewController.swift
// Orbot
//
// Created by Benjamin Erhart on 13.01.23.
// Copyright © 2023 Guardian Project. All rights reserved.
//

import UIKit
import IPtProxyUI

class CustomBridgesViewController: UIViewController, UITextViewDelegate, ScanQrDelegate {

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


weak var delegate: BridgesConfDelegate?


@IBOutlet weak var explanationLb: UILabel! {
didSet {
explanationLb.text = NSLocalizedString("A custom bridge is provided by someone you know. Ask within your trusted networks and organizations to see if anyone is hosting one.", comment: "")
}
}

@IBOutlet weak var bridgeLinesTv: UITextView? {
didSet {
bridgeLinesTv?.text = delegate?.customBridges?.joined(separator: "\n")
hintLb?.isHidden = !(bridgeLinesTv?.text.isEmpty ?? true)
}
}

@IBOutlet weak var hintLb: UILabel? {
didSet {
hintLb?.text = NSLocalizedString("Enter bridge address", comment: "")
hintLb?.isHidden = !(bridgeLinesTv?.text.isEmpty ?? true)
}
}

@IBOutlet weak var qrBt: UIButton! {
didSet {
qrBt.accessibilityLabel = NSLocalizedString("Scan QR Code", bundle: .iPtProxyUI, comment: "#bc-ignore!")
}
}

@IBOutlet weak var captionLb: UILabel! {
didSet {
captionLb.text = NSLocalizedString("You can enter multiple bridge addresses.", comment: "")
}
}

@IBOutlet weak var saveBt: UIButton! {
didSet {
saveBt.setTitle(NSLocalizedString("Save", bundle: .iPtProxyUI, comment: "#bc-ignore!"))
}
}


override func viewDidLoad() {
super.viewDidLoad()

navigationItem.title = NSLocalizedString("Custom Bridge", comment: "")

view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard)))
}


// MARK: UITextViewDelegate

func textViewShouldBeginEditing(_ textView: UITextView) -> Bool {
hintLb?.isHidden = true

return true
}

func textViewDidEndEditing(_ textView: UITextView) {
hintLb?.isHidden = !textView.text.isEmpty
}


// MARK: ScanQrDelegate

func scanned(value raw: String?) {
// They really had to use JSON for content encoding but with illegal single quotes instead
// of double quotes as per JSON standard. Srsly?
if let data = raw?.replacingOccurrences(of: "'", with: "\"").data(using: .utf8),
let newBridges = try? JSONSerialization.jsonObject(with: data, options: []) as? [String] {

bridgeLinesTv?.text = newBridges.joined(separator: "\n")
}
else {
AlertHelper.present(self, message:
String(format: NSLocalizedString(
"QR Code could not be decoded! Are you sure you scanned a QR code from %@?",
bundle: .iPtProxyUI, comment: ""), IPtProxyUI.CustomBridgesViewController.bridgesUrl))
}
}


// MARK: Actions

@IBAction
func save() {
navigationController?.popViewController(animated: true)

delegate?.customBridges = bridgeLinesTv?.text?
.components(separatedBy: "\n")
.map({ $0.trimmingCharacters(in: .whitespacesAndNewlines) })
.filter({ !$0.isEmpty && !$0.hasPrefix("//") && !$0.hasPrefix("#") })

if delegate?.customBridges?.isEmpty ?? true {
if delegate?.transport == .custom {
delegate?.transport = .none
}
}
else {
delegate?.transport = .custom
}

delegate?.save()
}

@IBAction
func scan() {
let vc = ScanQrViewController()
vc.delegate = self

navigationController?.pushViewController(vc, animated: true)
}


// MARK: Private Methods

@objc
private func dismissKeyboard() {
view.endEditing(true)
}
}
Loading

0 comments on commit bd9af9d

Please sign in to comment.