Skip to content

Commit

Permalink
Issue #46: Reworked double buttons on main scene to button and switch.
Browse files Browse the repository at this point in the history
  • Loading branch information
tladesignz committed Mar 13, 2023
1 parent 6fd9b46 commit 66943f0
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 93 deletions.
77 changes: 35 additions & 42 deletions Orbot Mac/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions Orbot Mac/Helpers/NSButton+Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,10 @@ extension NSButton {
attributedAlternateTitle = title ?? NSAttributedString(string: "")
}
}

class NonDimmingNSButtonCell: NSButtonCell {

override func drawTitle(_ title: NSAttributedString, withFrame frame: NSRect, in controlView: NSView) -> NSRect {
return super.drawTitle(isEnabled ? title : attributedTitle, withFrame: frame, in: controlView)
}
}
35 changes: 20 additions & 15 deletions Orbot Mac/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,17 @@ class MainViewController: NSViewController, NSWindowDelegate, NSToolbarItemValid
}
}

@IBOutlet weak var control2Bt: NSButton! {
@IBOutlet weak var smartConnectSw: NSButton! {
didSet {
control2Bt.setAttributedTitle(SharedUtils.smartConnectButtonLabel(buttonFontSize: control2Bt.font?.pointSize))
control2Bt.isBordered = false
control2Bt.wantsLayer = true
control2Bt.layer?.backgroundColor = NSColor.black3.cgColor
control2Bt.layer?.cornerRadius = 5
smartConnectSw.setAttributedTitle(NSAttributedString(
string: L10n.runSmartConnectToFindTheBestWay,
attributes: [.foregroundColor: NSColor.white]))
}
}
@IBOutlet weak var control2BtHeight: NSLayoutConstraint!

@IBOutlet weak var configureBt: NSButton! {
didSet {
configureBt.setTitle(NSLocalizedString("Choose How to Connect", comment: ""))
configureBt.setTitle(L10n.chooseHowToConnect)
configureBt.setAccessibilityIdentifier("bridge_configuration")
}
}
Expand Down Expand Up @@ -113,11 +110,21 @@ class MainViewController: NSViewController, NSWindowDelegate, NSToolbarItemValid
// MARK: Actions

@IBAction func control(_ sender: Any) {
if let sender = sender as? NSButton, sender == control2Bt {
Settings.smartConnect = true
SharedUtils.control(startOnly: false)
}

@IBAction func toggleSmartConnect(_ sender: NSView) {
guard smartConnectSw.isEnabled else {
return
}

SharedUtils.control(startOnly: false)
if sender != smartConnectSw {
smartConnectSw.state = smartConnectSw.state == .on ? .off : .on
}

Settings.smartConnect = smartConnectSw.state == .on

updateUi()
}

@IBAction func controlSnowflakeProxy(_ sender: Any) {
Expand Down Expand Up @@ -193,10 +200,8 @@ class MainViewController: NSViewController, NSWindowDelegate, NSToolbarItemValid
statusSubLb.stringValue = statusSubtext
controlBt.setAttributedTitle(buttonTitle)

let hide = Settings.smartConnect || VpnManager.shared.status != .disconnected

control2BtHeight.constant = hide ? 0 : 64
control2Bt.isHidden = hide
smartConnectSw.state = Settings.smartConnect ? .on : .off
smartConnectSw.isEnabled = VpnManager.shared.status == .disconnected

configureBt.isHidden = !showConfButton
}
Expand Down
2 changes: 1 addition & 1 deletion Orbot/BridgesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class BridgesViewController: BaseFormViewController, BridgesConfDelegate, MFMail

tableView.separatorStyle = .none

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

section.onSelectSelectableRow = { [weak self] _, row in
guard let self = self else {
Expand Down
73 changes: 46 additions & 27 deletions Orbot/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -65,30 +65,42 @@
<action selector="control:" destination="BYZ-38-t0r" eventType="touchUpInside" id="ydS-c1-J2s"/>
</connections>
</button>
<button opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="wordWrap" role="primary" translatesAutoresizingMaskIntoConstraints="NO" id="l6h-oq-v3K">
<rect key="frame" x="32" y="425" width="256" height="64"/>
<color key="backgroundColor" name="Black3"/>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Oag-Ga-fc5">
<rect key="frame" x="16" y="433" width="288" height="34"/>
<subviews>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="NTl-GO-uMk">
<rect key="frame" x="20" y="1.5" width="51" height="31"/>
<constraints>
<constraint firstAttribute="width" constant="49" id="nwy-i2-zYn"/>
</constraints>
<color key="onTintColor" systemColor="labelColor"/>
<color key="thumbTintColor" name="Black1"/>
<connections>
<action selector="toggleSmartConnect:" destination="BYZ-38-t0r" eventType="valueChanged" id="8np-OU-qdM"/>
</connections>
</switch>
<label opaque="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Run Smart Connect to find the best way" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="bzM-gx-Huz">
<rect key="frame" x="77" y="0.0" width="191" height="34"/>
<gestureRecognizers/>
<fontDescription key="fontDescription" style="UICTFontTextStyleFootnote"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
<connections>
<outletCollection property="gestureRecognizers" destination="20l-7Y-KB6" appends="YES" id="MWd-1d-0Rh"/>
</connections>
</label>
</subviews>
<constraints>
<constraint firstAttribute="width" constant="256" id="8Aj-Zd-c5X"/>
<constraint firstAttribute="height" constant="64" id="T3P-lN-hzs"/>
<constraint firstItem="NTl-GO-uMk" firstAttribute="leading" secondItem="Oag-Ga-fc5" secondAttribute="leading" constant="20" symbolic="YES" id="6K1-J1-uqJ"/>
<constraint firstAttribute="trailing" secondItem="bzM-gx-Huz" secondAttribute="trailing" constant="20" symbolic="YES" id="EO1-kp-Ahh"/>
<constraint firstAttribute="bottom" secondItem="bzM-gx-Huz" secondAttribute="bottom" id="bAg-2d-9My"/>
<constraint firstItem="bzM-gx-Huz" firstAttribute="top" secondItem="Oag-Ga-fc5" secondAttribute="top" id="ddU-hU-GMN"/>
<constraint firstItem="NTl-GO-uMk" firstAttribute="centerY" secondItem="Oag-Ga-fc5" secondAttribute="centerY" id="ghr-c5-1QR"/>
<constraint firstItem="bzM-gx-Huz" firstAttribute="leading" secondItem="NTl-GO-uMk" secondAttribute="trailing" constant="8" symbolic="YES" id="nrd-Kh-evF"/>
</constraints>
<fontDescription key="fontDescription" style="UICTFontTextStyleTitle1"/>
<inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
<state key="normal">
<string key="title">Start
Use Smart Connect</string>
</state>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius">
<integer key="value" value="9"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
<connections>
<action selector="control:" destination="BYZ-38-t0r" eventType="touchUpInside" id="tj9-JA-yz0"/>
</connections>
</button>
</view>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="4D2-gT-gQC">
<rect key="frame" x="32" y="497" width="256" height="48"/>
<rect key="frame" x="32" y="499" width="256" height="48"/>
<constraints>
<constraint firstAttribute="height" constant="48" id="KGe-ln-kBc"/>
<constraint firstAttribute="width" constant="256" id="bqX-o7-8Ig"/>
Expand Down Expand Up @@ -150,7 +162,6 @@ Use Smart Connect</string>
<gestureRecognizers/>
<constraints>
<constraint firstItem="RHK-rR-QxJ" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="0oq-dk-hja"/>
<constraint firstItem="l6h-oq-v3K" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="25v-SK-qy0"/>
<constraint firstItem="4D2-gT-gQC" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="4Hp-RR-Xwb"/>
<constraint firstItem="eEm-Rp-xCs" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="16" id="DGb-sI-OMr"/>
<constraint firstItem="RHK-rR-QxJ" firstAttribute="top" secondItem="eEm-Rp-xCs" secondAttribute="bottom" constant="32" id="Ez5-F4-IIt"/>
Expand All @@ -159,13 +170,16 @@ Use Smart Connect</string>
<constraint firstItem="hc2-uq-S3p" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="S0N-A6-A5V"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="trJ-w6-CDg" secondAttribute="trailing" constant="16" id="Smj-HX-Vt1"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="eEm-Rp-xCs" secondAttribute="trailing" constant="16" id="Um4-Z8-Lnu"/>
<constraint firstItem="4D2-gT-gQC" firstAttribute="top" secondItem="l6h-oq-v3K" secondAttribute="bottom" constant="8" symbolic="YES" id="WH2-kO-x5e"/>
<constraint firstItem="trJ-w6-CDg" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="16" id="Wk8-Jf-aT6"/>
<constraint firstItem="4D2-gT-gQC" firstAttribute="top" secondItem="Oag-Ga-fc5" secondAttribute="bottom" constant="32" id="Yxs-5U-Vhz"/>
<constraint firstItem="Oag-Ga-fc5" firstAttribute="top" secondItem="RHK-rR-QxJ" secondAttribute="bottom" constant="16" id="Zng-zT-ock"/>
<constraint firstItem="eEm-Rp-xCs" firstAttribute="top" secondItem="trJ-w6-CDg" secondAttribute="bottom" constant="8" symbolic="YES" id="eGL-ef-JqZ"/>
<constraint firstItem="hc2-uq-S3p" firstAttribute="top" secondItem="1N5-w4-uQk" secondAttribute="bottom" constant="8" symbolic="YES" id="fNW-xw-N94"/>
<constraint firstItem="Oag-Ga-fc5" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="16" id="fV5-q1-W9a"/>
<constraint firstItem="trJ-w6-CDg" firstAttribute="top" secondItem="hc2-uq-S3p" secondAttribute="bottom" constant="8" symbolic="YES" id="jkI-FK-1uP"/>
<constraint firstItem="Oag-Ga-fc5" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="kg1-Gm-WEF"/>
<constraint firstItem="48u-FW-Qyr" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" id="n3U-aF-Z1D"/>
<constraint firstItem="l6h-oq-v3K" firstAttribute="top" secondItem="RHK-rR-QxJ" secondAttribute="bottom" constant="8" symbolic="YES" id="rmO-ju-YlO"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" relation="lessThanOrEqual" secondItem="Oag-Ga-fc5" secondAttribute="trailing" constant="16" id="ofl-Qt-bFe"/>
<constraint firstItem="48u-FW-Qyr" firstAttribute="bottom" secondItem="8bC-Xf-vdC" secondAttribute="bottom" id="stN-RM-dne"/>
<constraint firstAttribute="centerX" relation="lessThanOrEqual" secondItem="48u-FW-Qyr" secondAttribute="trailing" constant="32" id="v0O-35-Pck"/>
<constraint firstItem="48u-FW-Qyr" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" id="ybe-1K-dUF"/>
Expand Down Expand Up @@ -196,8 +210,6 @@ Use Smart Connect</string>
</navigationItem>
<connections>
<outlet property="configureBt" destination="4D2-gT-gQC" id="BzC-HQ-bEE"/>
<outlet property="control2Bt" destination="l6h-oq-v3K" id="vEm-sI-OE5"/>
<outlet property="control2BtHeight" destination="T3P-lN-hzs" id="xkP-FG-Y21"/>
<outlet property="controlBt" destination="RHK-rR-QxJ" id="eOS-d8-hnA"/>
<outlet property="logBt" destination="2Pk-78-bJO" id="Wja-ru-8lH"/>
<outlet property="logContainer" destination="48u-FW-Qyr" id="pu3-SA-Xqe"/>
Expand All @@ -207,6 +219,8 @@ Use Smart Connect</string>
<outlet property="settingsBt" destination="ni1-t3-I0T" id="9Fk-Cd-K9y"/>
<outlet property="shadowImg" destination="hc2-uq-S3p" id="Us5-Lf-lzv"/>
<outlet property="shadowImgHeight" destination="0OM-UZ-cSx" id="CUt-0D-Cy6"/>
<outlet property="smartConnectLb" destination="bzM-gx-Huz" id="h1u-nH-FLY"/>
<outlet property="smartConnectSw" destination="NTl-GO-uMk" id="elE-2x-CHE"/>
<outlet property="statusIcon" destination="1N5-w4-uQk" id="RXg-Gg-tqm"/>
<outlet property="statusIconWidth" destination="Wnm-LL-BGe" id="HIB-BT-gjB"/>
<outlet property="statusLb" destination="trJ-w6-CDg" id="2On-Ts-emC"/>
Expand All @@ -219,6 +233,11 @@ Use Smart Connect</string>
<action selector="hideLogs" destination="BYZ-38-t0r" id="D1N-8l-KRA"/>
</connections>
</tapGestureRecognizer>
<tapGestureRecognizer id="20l-7Y-KB6" userLabel="toggle-smart-connect-on-label">
<connections>
<action selector="toggleSmartConnect:" destination="BYZ-38-t0r" id="b2B-at-m0n"/>
</connections>
</tapGestureRecognizer>
</objects>
<point key="canvasLocation" x="130.40000000000001" y="137.18140929535232"/>
</scene>
Expand Down Expand Up @@ -721,7 +740,7 @@ Use Smart Connect</string>
<objects>
<navigationController id="zOy-O2-NNl" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="Sy3-W1-eYI">
<rect key="frame" x="0.0" y="0.0" width="320" height="50"/>
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<textAttributes key="titleTextAttributes">
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
Expand Down
28 changes: 20 additions & 8 deletions Orbot/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ class MainViewController: UIViewController {

@IBOutlet weak var controlBt: UIButton!

@IBOutlet weak var control2Bt: UIButton! {
@IBOutlet weak var smartConnectSw: UISwitch!
@IBOutlet weak var smartConnectLb: UILabel! {
didSet {
control2Bt.setAttributedTitle(SharedUtils.smartConnectButtonLabel(buttonFontSize: control2Bt.titleLabel?.font.pointSize))
smartConnectLb.text = L10n.runSmartConnectToFindTheBestWay
}
}
@IBOutlet weak var control2BtHeight: NSLayoutConstraint!

@IBOutlet weak var configureBt: UIButton! {
didSet {
configureBt.setTitle(NSLocalizedString("Choose How to Connect", comment: ""))
configureBt.setTitle(L10n.chooseHowToConnect)
configureBt.accessibilityIdentifier = "bridge_configuration"
}
}
Expand Down Expand Up @@ -205,11 +205,21 @@ class MainViewController: UIViewController {
}

@IBAction func control(_ sender: UIButton? = nil) {
if sender == control2Bt {
Settings.smartConnect = true
SharedUtils.control(startOnly: false)
}

@IBAction func toggleSmartConnect(_ sender: UIView) {
guard smartConnectSw.isEnabled else {
return
}

SharedUtils.control(startOnly: false)
if sender != smartConnectSw {
smartConnectSw.setOn(!smartConnectSw.isOn, animated: true)
}

Settings.smartConnect = smartConnectSw.isOn

updateUi()
}

@IBAction func changeLog() {
Expand Down Expand Up @@ -298,7 +308,9 @@ class MainViewController: UIViewController {
statusLb.attributedText = statusText
statusSubLb.text = statusSubtext
controlBt.setAttributedTitle(buttonTitle)
control2BtHeight.constant = Settings.smartConnect || VpnManager.shared.status != .disconnected ? 0 : 64

smartConnectSw.isOn = Settings.smartConnect
smartConnectSw.isEnabled = VpnManager.shared.status == .disconnected

logSc.setEnabled(Settings.transport != .none, forSegmentAt: 1)

Expand Down
8 changes: 8 additions & 0 deletions Shared/L10n.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ class L10n {
Bundle.main.version, Bundle.main.build)
}

static var runSmartConnectToFindTheBestWay: String {
NSLocalizedString("Run Smart Connect to find the best way", comment: "")
}

static var chooseHowToConnect: String {
NSLocalizedString("Choose How to Connect", comment: "")
}

static var log: String {
NSLocalizedString("Log", comment: "")
}
Expand Down
Binary file modified Shared/de.lproj/Localizable.strings
Binary file not shown.
3 changes: 3 additions & 0 deletions Shared/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,9 @@
/* No comment provided by engineer. */
"Refresh" = "Refresh";

/* No comment provided by engineer. */
"Run Smart Connect to find the best way" = "Run Smart Connect to find the best way";

/* No comment provided by engineer. */
"Scan a bridge QR code" = "Scan a bridge QR code";

Expand Down

0 comments on commit 66943f0

Please sign in to comment.