Skip to content

Commit

Permalink
Issue #46: Re-added reading a QR-code from a stored image.
Browse files Browse the repository at this point in the history
  • Loading branch information
tladesignz committed Jan 18, 2023
1 parent d66f991 commit a6e8d99
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 69 deletions.
90 changes: 54 additions & 36 deletions Orbot.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@
A01AB5F428A53465008A79EE /* Resources */,
61AE61C4AE5791BF2DBDCC61 /* [CP] Embed Pods Frameworks */,
A01AB6AC28A55706008A79EE /* Embed Foundation Extensions */,
A8CC658E10E591DC6C1D0A6E /* [CP] Copy Pods Resources */,
FDA880FFFC27B6247F09BD65 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand All @@ -826,7 +826,7 @@
A06D605C29019D33001A2E2C /* Embed Frameworks */,
A01AB69C28A55706008A79EE /* Frameworks */,
A01AB69D28A55706008A79EE /* Resources */,
021E681CE032ED2489488CC7 /* [CP] Copy Pods Resources */,
363815AD4FC35F4FA60A8AB5 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand All @@ -848,7 +848,7 @@
A05B73AE24755CE600930C40 /* Resources */,
A0A735D9247561F200073C81 /* Embed Foundation Extensions */,
EA613F0B6D61304A533884FE /* [CP] Embed Pods Frameworks */,
329E559D33FDBA00740F2EDE /* [CP] Copy Pods Resources */,
FE3803C7B1CE3627FE4B1C9A /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand Down Expand Up @@ -889,6 +889,7 @@
A06D605F29019D3B001A2E2C /* Embed Frameworks */,
A0A735CA247561F200073C81 /* Frameworks */,
A0A735CB247561F200073C81 /* Resources */,
D3E635B33EF710F6A8858CE4 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand Down Expand Up @@ -1052,7 +1053,7 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
021E681CE032ED2489488CC7 /* [CP] Copy Pods Resources */ = {
363815AD4FC35F4FA60A8AB5 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
Expand All @@ -1069,23 +1070,6 @@
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-TorVPN Mac/Pods-TorVPN Mac-resources.sh\"\n";
showEnvVarsInLog = 0;
};
329E559D33FDBA00740F2EDE /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Orbot/Pods-Orbot-resources-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Copy Pods Resources";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Orbot/Pods-Orbot-resources-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Orbot/Pods-Orbot-resources.sh\"\n";
showEnvVarsInLog = 0;
};
409194A5E6D0FCFF456B4364 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -1185,43 +1169,43 @@
shellPath = /bin/sh;
shellScript = "if [ -f /opt/homebrew/bin/bartycrouch ]; then\n /opt/homebrew/bin/bartycrouch update -x\n /opt/homebrew/bin/bartycrouch lint -x\nelse\n echo \"warning: BartyCrouch not installed. Download it form https://github.com/Flinesoft/BartyCrouch\"\nfi\n";
};
A8CC658E10E591DC6C1D0A6E /* [CP] Copy Pods Resources */ = {
C22D403EE9EDFB01567D08D4 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Orbot Mac/Pods-Orbot Mac-resources-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Copy Pods Resources";
inputPaths = (
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
"${PODS_ROOT}/Manifest.lock",
);
name = "[CP] Check Pods Manifest.lock";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Orbot Mac/Pods-Orbot Mac-resources-${CONFIGURATION}-output-files.xcfilelist",
);
outputPaths = (
"$(DERIVED_FILE_DIR)/Pods-TorVPN-checkManifestLockResult.txt",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Orbot Mac/Pods-Orbot Mac-resources.sh\"\n";
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
C22D403EE9EDFB01567D08D4 /* [CP] Check Pods Manifest.lock */ = {
D3E635B33EF710F6A8858CE4 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-TorVPN/Pods-TorVPN-resources-${CONFIGURATION}-input-files.xcfilelist",
);
inputPaths = (
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
"${PODS_ROOT}/Manifest.lock",
);
name = "[CP] Check Pods Manifest.lock";
name = "[CP] Copy Pods Resources";
outputFileListPaths = (
);
outputPaths = (
"$(DERIVED_FILE_DIR)/Pods-TorVPN-checkManifestLockResult.txt",
"${PODS_ROOT}/Target Support Files/Pods-TorVPN/Pods-TorVPN-resources-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-TorVPN/Pods-TorVPN-resources.sh\"\n";
showEnvVarsInLog = 0;
};
D760D1C316485BFBD3413FB4 /* [CP] Check Pods Manifest.lock */ = {
Expand Down Expand Up @@ -1263,6 +1247,40 @@
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Orbot/Pods-Orbot-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
FDA880FFFC27B6247F09BD65 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Orbot Mac/Pods-Orbot Mac-resources-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Copy Pods Resources";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Orbot Mac/Pods-Orbot Mac-resources-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Orbot Mac/Pods-Orbot Mac-resources.sh\"\n";
showEnvVarsInLog = 0;
};
FE3803C7B1CE3627FE4B1C9A /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Orbot/Pods-Orbot-resources-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Copy Pods Resources";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Orbot/Pods-Orbot-resources-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Orbot/Pods-Orbot-resources.sh\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
Expand Down
2 changes: 1 addition & 1 deletion Orbot/AuthViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class AuthViewController: UITableViewController, ScanQrDelegate {
addBt.accessibilityLabel = L10n.add

let scanBt = UIBarButtonItem(barButtonSystemItem: .camera, target: self, action: #selector(qr))
scanBt.accessibilityLabel = NSLocalizedString("Scan QR Code", bundle: Bundle.iPtProxyUI, comment: "#bc-ignore!")
scanBt.accessibilityLabel = IPtProxyUI.L10n.scanQrCode

navigationItem.rightBarButtonItems = [addBt, scanBt]

Expand Down
69 changes: 52 additions & 17 deletions Orbot/CustomBridgesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

import UIKit
import IPtProxyUI
import PhotosUI

class CustomBridgesViewController: UIViewController, UITextViewDelegate, ScanQrDelegate {
class CustomBridgesViewController: UIViewController, UITextViewDelegate, ScanQrDelegate, PHPickerViewControllerDelegate {

static func make() -> Self {
UIStoryboard.main.instantiateViewController(withIdentifier: "custom_bridges_vc") as! Self
Expand All @@ -27,8 +28,7 @@ class CustomBridgesViewController: UIViewController, UITextViewDelegate, ScanQrD

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

Expand All @@ -39,9 +39,15 @@ class CustomBridgesViewController: UIViewController, UITextViewDelegate, ScanQrD
}
}

@IBOutlet weak var fileBt: UIButton! {
didSet {
fileBt.accessibilityLabel = IPtProxyUI.L10n.uploadQrCode
}
}

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

Expand Down Expand Up @@ -91,7 +97,7 @@ class CustomBridgesViewController: UIViewController, UITextViewDelegate, ScanQrD
func scanned(bridges: [String]) {
navigationController?.popViewController(animated: true)

bridgeLinesTv?.text = bridges.joined(separator: "\n")
set(bridges: bridges)
}

func scanned(error: Error) {
Expand All @@ -107,21 +113,45 @@ class CustomBridgesViewController: UIViewController, UITextViewDelegate, ScanQrD
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("#") })
Helpers.update(delegate: delegate, bridgeLinesTv?.text)

delegate?.save()
}

@IBAction
func pickImage() {
var conf = PHPickerConfiguration()
conf.filter = PHPickerFilter.images

let vc = PHPickerViewController(configuration: conf)
vc.delegate = self

present(vc, animated: true)
}


// MARK: PHPickerViewControllerDelegate

if delegate?.customBridges?.isEmpty ?? true {
if delegate?.transport == .custom {
delegate?.transport = .none
func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
picker.dismiss(animated: true)

results.first?.itemProvider.loadObject(ofClass: UIImage.self) { [weak self] object, error in
guard let self = self
else {
return
}
}
else {
delegate?.transport = .custom
}

delegate?.save()
let bridges = BaseScanViewController.extractBridges(from: object as? UIImage)

DispatchQueue.main.async {
if let bridges = bridges {
self.set(bridges: bridges)
}
else {
AlertHelper.present(self, message: ScanError.notBridges.localizedDescription)
}
}
}
}


Expand All @@ -131,4 +161,9 @@ class CustomBridgesViewController: UIViewController, UITextViewDelegate, ScanQrD
private func dismissKeyboard() {
view.endEditing(true)
}

private func set(bridges: [String]?) {
bridgeLinesTv?.text = bridges?.joined(separator: "\n")
hintLb?.isHidden = !(bridgeLinesTv?.text.isEmpty ?? true)
}
}
26 changes: 24 additions & 2 deletions Orbot/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,24 @@ Use Smart Connect</string>
<color key="textColor" systemColor="secondaryLabelColor"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Lt3-rU-Mu7">
<rect key="frame" x="262" y="166.5" width="34" height="34"/>
<color key="backgroundColor" name="Accent1"/>
<constraints>
<constraint firstAttribute="width" constant="34" id="KcC-Iq-TT3"/>
<constraint firstAttribute="height" constant="34" id="z49-cR-5Rh"/>
</constraints>
<state key="normal" title="Button"/>
<buttonConfiguration key="configuration" style="plain" image="qrcode" catalog="system"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius">
<integer key="value" value="9"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
<connections>
<action selector="pickImage" destination="6kb-zv-6wX" eventType="touchUpInside" id="CTt-wk-Qmr"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="VRb-W0-xpo">
<rect key="frame" x="262" y="208.5" width="34" height="34"/>
<color key="backgroundColor" name="Accent1"/>
Expand All @@ -263,7 +281,7 @@ Use Smart Connect</string>
<constraint firstAttribute="width" constant="34" id="Mnz-BY-bik"/>
</constraints>
<state key="normal" title="Button"/>
<buttonConfiguration key="configuration" style="plain" image="qrcode" catalog="system"/>
<buttonConfiguration key="configuration" style="plain" image="qrcode.viewfinder" catalog="system"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius">
<integer key="value" value="9"/>
Expand Down Expand Up @@ -309,6 +327,8 @@ Use Smart Connect</string>
<constraint firstItem="tDF-LV-ID2" firstAttribute="trailing" secondItem="4mX-7j-zgh" secondAttribute="trailing" constant="16" id="f9b-L2-ek9"/>
<constraint firstItem="HJK-0r-KNm" firstAttribute="top" secondItem="4mX-7j-zgh" secondAttribute="bottom" constant="8" symbolic="YES" id="gj7-Z8-eo2"/>
<constraint firstItem="gJk-qF-0Bs" firstAttribute="top" secondItem="4mX-7j-zgh" secondAttribute="top" constant="8" id="k53-VX-vus"/>
<constraint firstItem="Lt3-rU-Mu7" firstAttribute="bottom" secondItem="VRb-W0-xpo" secondAttribute="top" constant="-8" id="kBg-ZQ-hoy"/>
<constraint firstItem="Lt3-rU-Mu7" firstAttribute="trailing" secondItem="4mX-7j-zgh" secondAttribute="trailing" constant="-8" id="keG-sz-sJt"/>
<constraint firstItem="tDF-LV-ID2" firstAttribute="trailing" secondItem="s44-F2-HgM" secondAttribute="trailing" constant="16" id="klZ-hD-Wpb"/>
<constraint firstItem="tDF-LV-ID2" firstAttribute="trailing" secondItem="TKe-Uw-2gL" secondAttribute="trailing" constant="16" id="lmz-JU-pJR"/>
<constraint firstItem="VRb-W0-xpo" firstAttribute="bottom" secondItem="4mX-7j-zgh" secondAttribute="bottom" constant="-8" id="mOk-Yz-keb"/>
Expand All @@ -323,6 +343,7 @@ Use Smart Connect</string>
<outlet property="bridgeLinesTv" destination="4mX-7j-zgh" id="lsx-RM-dc3"/>
<outlet property="captionLb" destination="HJK-0r-KNm" id="vNV-q5-7pi"/>
<outlet property="explanationLb" destination="TKe-Uw-2gL" id="fSE-Ck-ppz"/>
<outlet property="fileBt" destination="Lt3-rU-Mu7" id="K6K-oN-1qY"/>
<outlet property="hintLb" destination="gJk-qF-0Bs" id="nt3-6u-9jP"/>
<outlet property="qrBt" destination="VRb-W0-xpo" id="W4U-Mx-38h"/>
<outlet property="saveBt" destination="s44-F2-HgM" id="q6p-ZS-jlx"/>
Expand Down Expand Up @@ -512,10 +533,11 @@ Use Smart Connect</string>
<resources>
<image name="chart.bar.doc.horizontal" catalog="system" width="115" height="128"/>
<image name="ellipsis" catalog="system" width="128" height="37"/>
<image name="noise" width="64" height="64"/>
<image name="noise" width="32" height="32"/>
<image name="orbie.off" width="132" height="125"/>
<image name="orbie.shadow" width="65" height="9"/>
<image name="qrcode" catalog="system" width="128" height="114"/>
<image name="qrcode.viewfinder" catalog="system" width="128" height="115"/>
<namedColor name="Accent1">
<color red="0.45500001311302185" green="0.14100000262260437" blue="0.81199997663497925" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</namedColor>
Expand Down
7 changes: 5 additions & 2 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ def tor
end

def iptproxy
pod 'IPtProxyUI', :git => 'https://github.com/tladesignz/IPtProxyUI-ios' #'~> 1.10' #:git => 'https://github.com/tladesignz/IPtProxyUI-ios' # :path => '../IPtProxyUI-ios'
pod 'IPtProxyUI/AppEx', :git => 'https://github.com/tladesignz/IPtProxyUI-ios'
# '~> 1.10'
# :git => 'https://github.com/tladesignz/IPtProxyUI-ios'
# :path => '../IPtProxyUI-ios'
end

target 'Orbot' do
Expand All @@ -30,8 +33,8 @@ target 'TorVPN' do
platform :ios, '15.0'

tor
iptproxy

pod 'IPtProxyUI/AppEx', :git => 'https://github.com/tladesignz/IPtProxyUI-ios'
pod 'GCDWebServerExtension', :git => 'https://github.com/tladesignz/GCDWebServer.git'
end

Expand Down
Loading

0 comments on commit a6e8d99

Please sign in to comment.