From 6e46b4c94a584cd827436cb0187017817563542f Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Mon, 29 Apr 2019 17:48:37 +0200 Subject: [PATCH 1/5] Put debug toolbar into navigation controller --- Passepartout-iOS/Base.lproj/Main.storyboard | 48 +++++++++------------ 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/Passepartout-iOS/Base.lproj/Main.storyboard b/Passepartout-iOS/Base.lproj/Main.storyboard index 2fc620a7..f9056474 100644 --- a/Passepartout-iOS/Base.lproj/Main.storyboard +++ b/Passepartout-iOS/Base.lproj/Main.storyboard @@ -398,43 +398,37 @@ - - - - - - - - - - - - - - - - - - - - - - + - - - - - + + + + + + + + + + + + + + + + + + + + From b6d419beed512802bebae1f5e845ff6dbdb2ce7b Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Mon, 29 Apr 2019 17:49:48 +0200 Subject: [PATCH 2/5] Make outlet optional for safety --- .../Scenes/DebugLogViewController.swift | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/Passepartout-iOS/Scenes/DebugLogViewController.swift b/Passepartout-iOS/Scenes/DebugLogViewController.swift index 0721c13a..f7b8c869 100644 --- a/Passepartout-iOS/Scenes/DebugLogViewController.swift +++ b/Passepartout-iOS/Scenes/DebugLogViewController.swift @@ -30,8 +30,8 @@ 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 deinit { @@ -44,11 +44,13 @@ 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 NotificationCenter.default.addObserver(self, selector: #selector(vpnDidPrepare), name: .VPNDidPrepare, object: nil) if vpn.isPrepared { @@ -56,8 +58,10 @@ class DebugLogViewController: UIViewController { } } + // MARK: Actions + @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 +86,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 +118,7 @@ class DebugLogViewController: UIViewController { } vpn.requestDebugLog(fallback: AppConstants.Log.debugSnapshot) { - self.textLog.text = $0 + self.textLog?.text = $0 updateBlock() } } From 16b8a44a30fc2a504af0d6a5661779a153628a73 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Mon, 29 Apr 2019 17:50:03 +0200 Subject: [PATCH 3/5] Hide bars on tap within debug log view --- .../Scenes/DebugLogViewController.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Passepartout-iOS/Scenes/DebugLogViewController.swift b/Passepartout-iOS/Scenes/DebugLogViewController.swift index f7b8c869..22600797 100644 --- a/Passepartout-iOS/Scenes/DebugLogViewController.swift +++ b/Passepartout-iOS/Scenes/DebugLogViewController.swift @@ -58,6 +58,20 @@ class DebugLogViewController: UIViewController { } } + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + + navigationController?.isToolbarHidden = false + navigationController?.hidesBarsOnTap = true + } + + override func viewWillDisappear(_ animated: Bool) { + super.viewWillDisappear(animated) + + navigationController?.isToolbarHidden = true + navigationController?.hidesBarsOnTap = false + } + // MARK: Actions @IBAction private func share(_ sender: Any?) { From 6ecf859a5e2824940fdc38a8974c99c427c06181 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Mon, 29 Apr 2019 17:59:01 +0200 Subject: [PATCH 4/5] Add custom tap recognizer to text view Stock gesture doesn't work on subview. --- Passepartout-iOS/Scenes/DebugLogViewController.swift | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Passepartout-iOS/Scenes/DebugLogViewController.swift b/Passepartout-iOS/Scenes/DebugLogViewController.swift index 22600797..4b884642 100644 --- a/Passepartout-iOS/Scenes/DebugLogViewController.swift +++ b/Passepartout-iOS/Scenes/DebugLogViewController.swift @@ -52,6 +52,9 @@ class DebugLogViewController: UIViewController { title = L10n.Service.Cells.DebugLog.caption 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 { startRefreshingLog() @@ -62,18 +65,22 @@ class DebugLogViewController: UIViewController { super.viewWillAppear(animated) navigationController?.isToolbarHidden = false - navigationController?.hidesBarsOnTap = true } override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(animated) navigationController?.isToolbarHidden = true - navigationController?.hidesBarsOnTap = false } // MARK: Actions + @objc private func toggleBars() { + let isHidden = navigationController?.isToolbarHidden ?? true + navigationController?.setNavigationBarHidden(!isHidden, animated: true) + navigationController?.setToolbarHidden(!isHidden, animated: true) + } + @IBAction private func share(_ sender: Any?) { guard let raw = textLog?.text, !raw.isEmpty else { let alert = Macros.alert(title, L10n.DebugLog.Alerts.EmptyLog.message) From 634f34405bb49b04a8db512e92eaf2916435c53c Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Tue, 30 Apr 2019 14:02:09 +0200 Subject: [PATCH 5/5] Only hide toolbar in debug log Split view controller is shi**y enough not to handle navigation bar properly on rotation. When in compact mode, the navigation bar comes from the split view controller. Hiding it and then going to regular (landscape), will leave the master without the navigation bar and no way to restore it. --- Passepartout-iOS/Scenes/DebugLogViewController.swift | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Passepartout-iOS/Scenes/DebugLogViewController.swift b/Passepartout-iOS/Scenes/DebugLogViewController.swift index 4b884642..f9705529 100644 --- a/Passepartout-iOS/Scenes/DebugLogViewController.swift +++ b/Passepartout-iOS/Scenes/DebugLogViewController.swift @@ -76,9 +76,10 @@ class DebugLogViewController: UIViewController { // MARK: Actions @objc private func toggleBars() { - let isHidden = navigationController?.isToolbarHidden ?? true - navigationController?.setNavigationBarHidden(!isHidden, animated: true) - navigationController?.setToolbarHidden(!isHidden, animated: true) + let nav = navigationController + let isHidden = nav?.isToolbarHidden ?? true +// nav?.setNavigationBarHidden(!isHidden, animated: true) + nav?.setToolbarHidden(!isHidden, animated: true) } @IBAction private func share(_ sender: Any?) {