Skip to content

Commit

Permalink
Issue #46: Added first implementation of first new scene for bridge s…
Browse files Browse the repository at this point in the history
…election.
  • Loading branch information
tladesignz committed Jan 13, 2023
1 parent 2991c2a commit 0fb6e2d
Show file tree
Hide file tree
Showing 4 changed files with 283 additions and 7 deletions.
8 changes: 8 additions & 0 deletions Orbot.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
A036701F292E70D60012C84A /* exit-node-countries.plist in Resources */ = {isa = PBXBuildFile; fileRef = A036701D292E70D60012C84A /* exit-node-countries.plist */; };
A03CFBB428B4CB0200D7A700 /* NSScrollView+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = A03CFBB328B4CB0200D7A700 /* NSScrollView+Helpers.swift */; };
A03CFBB828B5206500D7A700 /* SettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A03CFBB728B5206500D7A700 /* SettingsViewController.swift */; };
A04672EA296DC85400BD0F2F /* BridgesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A04672E9296DC85400BD0F2F /* BridgesViewController.swift */; };
A04E3679273D4BF100578FD4 /* AuthViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A04E3678273D4BF100578FD4 /* AuthViewController.swift */; };
A0507CF326F9FB8200F91105 /* NetworkExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A0507CF226F9FB8200F91105 /* NetworkExtension.framework */; };
A0507CF426F9FB8C00F91105 /* NetworkExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A0507CF226F9FB8200F91105 /* NetworkExtension.framework */; };
Expand All @@ -72,6 +73,7 @@
A05B73B424755CE600930C40 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A05B73B324755CE600930C40 /* AppDelegate.swift */; };
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 */; };
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 @@ -298,6 +300,7 @@
A0367840274E5E8000344B7F /* CHANGELOG.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = CHANGELOG.md; sourceTree = "<group>"; };
A03CFBB328B4CB0200D7A700 /* NSScrollView+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSScrollView+Helpers.swift"; sourceTree = "<group>"; };
A03CFBB728B5206500D7A700 /* SettingsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsViewController.swift; sourceTree = "<group>"; };
A04672E9296DC85400BD0F2F /* BridgesViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BridgesViewController.swift; sourceTree = "<group>"; };
A04E3678273D4BF100578FD4 /* AuthViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthViewController.swift; sourceTree = "<group>"; };
A0507CF226F9FB8200F91105 /* NetworkExtension.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = NetworkExtension.framework; path = System/Library/Frameworks/NetworkExtension.framework; sourceTree = SDKROOT; };
A0507CF526F9FB9400F91105 /* NetworkExtension.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = NetworkExtension.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/System/Library/Frameworks/NetworkExtension.framework; sourceTree = DEVELOPER_DIR; };
Expand All @@ -311,6 +314,7 @@
A05B73B724755CE600930C40 /* MainViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainViewController.swift; sourceTree = "<group>"; };
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>"; };
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 @@ -480,6 +484,7 @@
A0A73607247587D300073C81 /* UIButton+Helpers.swift */,
A06470172477F7E900311CBE /* UITextView+Helpers.swift */,
A00F5123274529B30037DD4A /* UIViewController+Helpers.swift */,
A05DCD03297191760017B36A /* RoundedButtonRow.swift */,
);
path = Helpers;
sourceTree = "<group>";
Expand Down Expand Up @@ -543,6 +548,7 @@
A00F51322745456A0037DD4A /* Main.storyboard */,
A05B73B724755CE600930C40 /* MainViewController.swift */,
A0EF119828043A9200A03017 /* BaseFormViewController.swift */,
A04672E9296DC85400BD0F2F /* BridgesViewController.swift */,
A0C1D8A9292F840E00EB9DBB /* ChangeExitViewController.swift */,
A04E3678273D4BF100578FD4 /* AuthViewController.swift */,
A0DF48B928250A7F001EED78 /* ApiAccessViewController.swift */,
Expand Down Expand Up @@ -1341,6 +1347,8 @@
A0EF1197280439C200A03017 /* ContentBlockerViewController.swift in Sources */,
A0A735EA24756CA200073C81 /* CloseCircuitsMessage.swift in Sources */,
A0274FED28E70B6300E767E9 /* SharedUtils.swift in Sources */,
A05DCD04297191760017B36A /* RoundedButtonRow.swift in Sources */,
A04672EA296DC85400BD0F2F /* BridgesViewController.swift in Sources */,
A0B167DE284F90560089EB7C /* ApiAccessCell.swift in Sources */,
A0BBF1A927D77B18005BBA3A /* SettingsViewController.swift in Sources */,
A009F0822812EE9400A04480 /* TorCircuit+Helper.swift in Sources */,
Expand Down
188 changes: 188 additions & 0 deletions Orbot/BridgesViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
//
// BridgesViewController.swift
// Orbot
//
// Created by Benjamin Erhart on 10.01.23.
// Copyright © 2023 Guardian Project. All rights reserved.
//

import UIKit
import Eureka
import IPtProxyUI

class BridgesViewController: BaseFormViewController, BridgesConfDelegate {

enum Option: String, CaseIterable {
case direct = "transport_none"
case snowflake = "transport_snowflake"
case snowflakeAmp = "transport_snowflake_amp"
case request = "request"
case custom = "transport_custom"

var localizedDescription: String {
switch self {
case .direct:
return NSLocalizedString("Direct connection to Tor", comment: "")

case .snowflake:
return NSLocalizedString("Snowflake", comment: "")

case .snowflakeAmp:
return NSLocalizedString("Snowflake (AMP rendezvous)", comment: "")

case .request:
return NSLocalizedString("Get a bridge from Tor (Obfs4)", comment: "")

case .custom:
return NSLocalizedString("Custom bridge", comment: "")
}
}

var longDescription: String {
switch self {
case .direct:
return NSLocalizedString("The best way to connect to Tor. Use if Tor is not blocked.", comment: "")

case .snowflake, .snowflakeAmp:
return NSLocalizedString("Connects through Tor volunteers. Gets around some Tor blocking.", comment: "")

case .request:
return NSLocalizedString("Cloaks your traffic. Gets around some Tor blocking.", comment: "")

case .custom:
return NSLocalizedString("Most likely to keep you connected if Tor is severly blocked. Requires a bridge address from someone you trust.", comment: "")
}
}

var isOn: Bool {
switch self {
case .direct:
return Settings.transport == .none

case .snowflake:
return Settings.transport == .snowflake

case .snowflakeAmp:
return Settings.transport == .snowflakeAmp

case .request:
return false

case .custom:
return Settings.transport == .custom
}
}
}

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

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

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


override func viewDidLoad() {
super.viewDidLoad()

tableView.separatorStyle = .none

navigationItem.title = NSLocalizedString("Choose How to Connect", comment: "")

section.onSelectSelectableRow = { [weak self] _, row in
guard let self = self else {
return
}

// Needed, otherwise rows don't get resized due to changing subtitle.
self.tableView.reloadData()
}

form
+++ section

for option in Option.allCases {
form.last!
<<< ListCheckRow<Option>() {
$0.cellStyle = .subtitle
$0.title = option.localizedDescription

$0.selectableValue = option
$0.value = option.isOn ? $0.selectableValue : nil

$0.cell.accessibilityIdentifier = option.rawValue
$0.cell.detailTextLabel?.numberOfLines = 0
$0.cell.backgroundColor = .init(named: .colorBlack2)
}
.cellUpdate({ cell, row in
cell.detailTextLabel?.text = row.value != nil ? row.selectableValue?.longDescription : nil
})
}

form
+++ RoundedButtonRow()
.cellUpdate({ [weak self] _, row in
switch self?.section.selectedRow()?.value ?? .direct {
case .request, .custom:
row.title = NSLocalizedString("Next", comment: "")

default:
row.title = NSLocalizedString("Save", comment: "")
}
})
.onCellSelection({ [weak self] cell, row in
switch self?.section.selectedRow()?.value ?? .direct {
case .request:
let vc = MoatViewController()
vc.delegate = self
self?.navigationController?.pushViewController(vc, animated: true)

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

default:
self?.save()
}
})
}

@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
}

navigationController?.dismiss(animated: true)

VpnManager.shared.configChanged()

NotificationCenter.default.post(name: .vpnStatusChanged, object: nil)
}
}
86 changes: 86 additions & 0 deletions Orbot/Helpers/RoundedButtonRow.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
//
// RoundedButtonRow.swift
// Orbot
//
// Created by Benjamin Erhart on 13.01.23.
// Copyright © 2023 Guardian Project. All rights reserved.
//

import Eureka

/**
Eureka button row with rounded corners and leading and trailing padding using a `UIButton` for the actual functionality.
*/
class RoundedButtonCell: ButtonCellOf<String> {

private lazy var button: UIButton = {
let button = UIButton(type: .system)

button.translatesAutoresizingMaskIntoConstraints = false

button.backgroundColor = .init(named: .colorAccent1)

return button
}()

override func setup() {
super.setup()

contentView.addSubview(button)

let row = row as? RoundedButtonRow

let ltp = row?.leadingTrailingPadding ?? 16
let tbp = row?.topBottomPadding ?? 0

button.heightAnchor.constraint(equalToConstant: row?.height ?? 48).isActive = true
button.topAnchor.constraint(equalTo: contentView.topAnchor, constant: tbp).isActive = true
button.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: ltp).isActive = true
button.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -ltp).isActive = true
button.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -tbp).isActive = true

button.layer.cornerRadius = row?.cornerRadius ?? 9

button.addTarget(self, action: #selector(tapped), for: .touchUpInside)

backgroundColor = .init(named: .colorBlack2)
}

override func update() {
button.setTitle(row.title)
}

@objc
private func tapped() {
row.didSelect()
}
}

final class RoundedButtonRow: Row<RoundedButtonCell>, RowType {

fileprivate var height: CGFloat = 48

fileprivate var cornerRadius: CGFloat = 9

fileprivate var leadingTrailingPadding: CGFloat = 16

fileprivate var topBottomPadding: CGFloat = 0


convenience init(tag: String?, height: CGFloat = 48, cornerRadius: CGFloat = 9, leadingTrailingPadding: CGFloat = 16, topBottomPadding: CGFloat = 0) {
self.init(tag: tag)

self.height = height
self.cornerRadius = cornerRadius
self.leadingTrailingPadding = leadingTrailingPadding
self.topBottomPadding = topBottomPadding
}

required init(tag: String?) {
super.init(tag: tag)

displayValueFor = nil
cellStyle = .default
}
}

8 changes: 1 addition & 7 deletions Orbot/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ class MainViewController: UIViewController {
@IBOutlet weak var logTv: UITextView!


private let bridgesConfDelegate = SharedUtils()


override func viewDidLoad() {
super.viewDidLoad()

Expand Down Expand Up @@ -153,10 +150,7 @@ class MainViewController: UIViewController {
}

@IBAction func changeBridges(_ sender: UIButton? = nil) {
let vc = BridgesConfViewController()
vc.delegate = bridgesConfDelegate

present(inNav: vc, view: sender ?? configureBt)
present(inNav: BridgesViewController(), view: sender ?? configureBt)
}

@discardableResult
Expand Down

0 comments on commit 0fb6e2d

Please sign in to comment.