Merge branch 'extend-debug-log-viewport'

This commit is contained in:
Davide De Rosa 2019-05-01 23:00:01 +02:00
commit 610d3f4344
2 changed files with 57 additions and 37 deletions

View File

@ -398,9 +398,17 @@
<fontDescription key="fontDescription" name="CourierNewPSMT" family="Courier New" pointSize="14"/>
<textInputTraits key="textInputTraits" autocorrectionType="no"/>
</textView>
<toolbar opaque="NO" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="L2r-Gc-jgW">
<rect key="frame" x="0.0" y="623" width="375" height="44"/>
<items>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="EID-0c-3tN" firstAttribute="trailing" secondItem="Aex-ay-Bvb" secondAttribute="trailing" id="MxQ-FS-qWF"/>
<constraint firstItem="EID-0c-3tN" firstAttribute="bottom" secondItem="Aex-ay-Bvb" secondAttribute="bottom" id="Uwp-4b-lh8"/>
<constraint firstItem="Aex-ay-Bvb" firstAttribute="top" secondItem="EID-0c-3tN" secondAttribute="top" id="dQv-Al-Hx5"/>
<constraint firstItem="Aex-ay-Bvb" firstAttribute="leading" secondItem="EID-0c-3tN" secondAttribute="leading" id="uaR-uG-IC6"/>
</constraints>
<viewLayoutGuide key="safeArea" id="EID-0c-3tN"/>
</view>
<toolbarItems>
<barButtonItem systemItem="rewind" id="dzc-CH-vwc">
<connections>
<action selector="previousSession" destination="KmS-dJ-DVx" id="mbh-60-0C4"/>
@ -418,23 +426,9 @@
<action selector="share:" destination="KmS-dJ-DVx" id="32r-VS-qvc"/>
</connections>
</barButtonItem>
</items>
</toolbar>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="EID-0c-3tN" firstAttribute="trailing" secondItem="Aex-ay-Bvb" secondAttribute="trailing" id="MxQ-FS-qWF"/>
<constraint firstItem="Aex-ay-Bvb" firstAttribute="top" secondItem="EID-0c-3tN" secondAttribute="top" id="dQv-Al-Hx5"/>
<constraint firstItem="L2r-Gc-jgW" firstAttribute="top" secondItem="Aex-ay-Bvb" secondAttribute="bottom" id="e6U-Xm-pES"/>
<constraint firstItem="L2r-Gc-jgW" firstAttribute="leading" secondItem="DQA-dJ-PeF" secondAttribute="leading" id="iuO-hK-K2Z"/>
<constraint firstItem="L2r-Gc-jgW" firstAttribute="bottom" secondItem="EID-0c-3tN" secondAttribute="bottom" id="lG5-6f-HvB"/>
<constraint firstAttribute="trailing" secondItem="L2r-Gc-jgW" secondAttribute="trailing" id="paj-ca-wpL"/>
<constraint firstItem="Aex-ay-Bvb" firstAttribute="leading" secondItem="EID-0c-3tN" secondAttribute="leading" id="uaR-uG-IC6"/>
</constraints>
<viewLayoutGuide key="safeArea" id="EID-0c-3tN"/>
</view>
<toolbarItems/>
</toolbarItems>
<navigationItem key="navigationItem" id="Wbs-3b-OSm"/>
<simulatedToolbarMetrics key="simulatedBottomBarMetrics"/>
<connections>
<outlet property="textLog" destination="Aex-ay-Bvb" id="9l9-Nk-Dz3"/>
</connections>

View File

@ -30,7 +30,7 @@ import Passepartout_Core
private let log = SwiftyBeaver.self
class DebugLogViewController: UIViewController {
@IBOutlet private weak var textLog: UITextView!
@IBOutlet private weak var textLog: UITextView?
private let vpn = VPN.shared
@ -44,11 +44,16 @@ class DebugLogViewController: UIViewController {
applyDetailTitle(Theme.current)
}
// MARK: UIViewController
override func viewDidLoad() {
super.viewDidLoad()
title = L10n.Service.Cells.DebugLog.caption
textLog.contentInsetAdjustmentBehavior = .never
textLog?.contentInsetAdjustmentBehavior = .never
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(toggleBars))
textLog?.addGestureRecognizer(tapGestureRecognizer)
NotificationCenter.default.addObserver(self, selector: #selector(vpnDidPrepare), name: .VPNDidPrepare, object: nil)
if vpn.isPrepared {
@ -56,8 +61,29 @@ class DebugLogViewController: UIViewController {
}
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.isToolbarHidden = false
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
navigationController?.isToolbarHidden = true
}
// MARK: Actions
@objc private func toggleBars() {
let nav = navigationController
let isHidden = nav?.isToolbarHidden ?? true
// nav?.setNavigationBarHidden(!isHidden, animated: true)
nav?.setToolbarHidden(!isHidden, animated: true)
}
@IBAction private func share(_ sender: Any?) {
guard let raw = textLog.text, !raw.isEmpty else {
guard let raw = textLog?.text, !raw.isEmpty else {
let alert = Macros.alert(title, L10n.DebugLog.Alerts.EmptyLog.message)
alert.addCancelAction(L10n.Global.ok)
present(alert, animated: true, completion: nil)
@ -82,19 +108,19 @@ class DebugLogViewController: UIViewController {
}
@IBAction private func previousSession() {
textLog.findPrevious(string: GroupConstants.VPN.sessionMarker)
textLog?.findPrevious(string: GroupConstants.VPN.sessionMarker)
}
@IBAction private func nextSession() {
textLog.findNext(string: GroupConstants.VPN.sessionMarker)
textLog?.findNext(string: GroupConstants.VPN.sessionMarker)
}
private func startRefreshingLog() {
vpn.requestDebugLog(fallback: AppConstants.Log.debugSnapshot) {
self.textLog.text = $0
self.textLog?.text = $0
DispatchQueue.main.async {
self.textLog.scrollToEnd()
self.textLog?.scrollToEnd()
self.refreshLogInBackground()
}
}
@ -114,7 +140,7 @@ class DebugLogViewController: UIViewController {
}
vpn.requestDebugLog(fallback: AppConstants.Log.debugSnapshot) {
self.textLog.text = $0
self.textLog?.text = $0
updateBlock()
}
}