From 1a2ae61be41ed6835281278759b05401c15a9617 Mon Sep 17 00:00:00 2001 From: Ali <> Date: Thu, 1 Apr 2021 01:13:34 +0400 Subject: [PATCH] Add the ability to share logs before the UI loads --- submodules/Display/Source/WindowContent.swift | 36 ++++++++++++++++++- submodules/Postbox/Sources/Postbox.swift | 2 ++ .../TelegramUI/Sources/AppDelegate.swift | 12 +++++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/submodules/Display/Source/WindowContent.swift b/submodules/Display/Source/WindowContent.swift index df3eec9703..23b2b84cb5 100644 --- a/submodules/Display/Source/WindowContent.swift +++ b/submodules/Display/Source/WindowContent.swift @@ -270,8 +270,42 @@ public class Window1 { private var shouldNotAnimateLikelyKeyboardAutocorrectionSwitch: Bool = false public private(set) var forceInCallStatusBarText: String? = nil - public var inCallNavigate: (() -> Void)? { + public var inCallNavigate: (() -> Void)? + + private var debugTapCounter: (Double, Int) = (0.0, 0) + private var debugTapRecognizer: UITapGestureRecognizer? + public var debugAction: (() -> Void)? { didSet { + if self.debugAction != nil { + if self.debugTapRecognizer == nil { + let debugTapRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.debugTapGesture(_:))) + self.debugTapRecognizer = debugTapRecognizer + self.hostView.containerView.addGestureRecognizer(debugTapRecognizer) + } + } else if let debugTapRecognizer = self.debugTapRecognizer { + self.debugTapRecognizer = nil + self.hostView.containerView.removeGestureRecognizer(debugTapRecognizer) + } + } + } + @objc private func debugTapGesture(_ recognizer: UITapGestureRecognizer) { + if case .ended = recognizer.state { + let timestamp = CACurrentMediaTime() + if self.debugTapCounter.0 < timestamp - 0.4 { + self.debugTapCounter.0 = timestamp + self.debugTapCounter.1 = 0 + } + + if self.debugTapCounter.0 >= timestamp - 0.4 { + self.debugTapCounter.0 = timestamp + self.debugTapCounter.1 += 1 + } + + if self.debugTapCounter.1 >= 10 { + self.debugTapCounter.1 = 0 + + self.debugAction?() + } } } diff --git a/submodules/Postbox/Sources/Postbox.swift b/submodules/Postbox/Sources/Postbox.swift index b7ff4a1e0c..c6ea04c927 100644 --- a/submodules/Postbox/Sources/Postbox.swift +++ b/submodules/Postbox/Sources/Postbox.swift @@ -1406,6 +1406,8 @@ public final class Postbox { self.basePath = basePath self.seedConfiguration = seedConfiguration self.tempDir = tempDir + + sleep(1) print("MediaBox path: \(self.basePath + "/media")") diff --git a/submodules/TelegramUI/Sources/AppDelegate.swift b/submodules/TelegramUI/Sources/AppDelegate.swift index ff4ac28e74..87d08d9814 100644 --- a/submodules/TelegramUI/Sources/AppDelegate.swift +++ b/submodules/TelegramUI/Sources/AppDelegate.swift @@ -33,6 +33,7 @@ import AccountUtils import CoreSpotlight import LightweightAccountData import TelegramAudio +import DebugSettingsUI #if canImport(BackgroundTasks) import BackgroundTasks @@ -813,6 +814,15 @@ final class SharedApplicationContext { } } }) + + self.mainWindow.debugAction = { + self.mainWindow.debugAction = nil + + let presentationData = sharedContext.currentPresentationData.with { $0 } + let navigationController = NavigationController(mode: .single, theme: NavigationControllerTheme(presentationTheme: presentationData.theme)) + navigationController.viewControllers = [debugController(sharedContext: sharedContext, context: nil)] + self.mainWindow.present(navigationController, on: .root) + } presentationDataPromise.set(sharedContext.presentationData) @@ -1083,6 +1093,8 @@ final class SharedApplicationContext { print("Application: context took \(readyTime) to become ready") } print("Launch to ready took \((CFAbsoluteTimeGetCurrent() - launchStartTime) * 1000.0) ms") + + self.mainWindow.debugAction = nil self.mainWindow.viewController = context.rootController if firstTime {