diff --git a/submodules/DebugSettingsUI/BUILD b/submodules/DebugSettingsUI/BUILD new file mode 100644 index 0000000000..21c2c558b8 --- /dev/null +++ b/submodules/DebugSettingsUI/BUILD @@ -0,0 +1,26 @@ +load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") + +swift_library( + name = "DebugSettingsUI", + module_name = "DebugSettingsUI", + srcs = glob([ + "Sources/**/*.swift", + ]), + deps = [ + "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit", + "//submodules/Display:Display", + "//submodules/Postbox:Postbox", + "//submodules/TelegramCore:TelegramCore", + "//submodules/SyncCore:SyncCore", + "//submodules/MtProtoKit:MtProtoKit", + "//submodules/TelegramPresentationData:TelegramPresentationData", + "//submodules/TelegramUIPreferences:TelegramUIPreferences", + "//submodules/ItemListUI:ItemListUI", + "//submodules/PresentationDataUtils:PresentationDataUtils", + "//submodules/OverlayStatusController:OverlayStatusController", + "//submodules/AccountContext:AccountContext", + ], + visibility = [ + "//visibility:public", + ], +) diff --git a/submodules/SettingsUI/Sources/DebugAccountsController.swift b/submodules/DebugSettingsUI/Sources/DebugAccountsController.swift similarity index 100% rename from submodules/SettingsUI/Sources/DebugAccountsController.swift rename to submodules/DebugSettingsUI/Sources/DebugAccountsController.swift diff --git a/submodules/SettingsUI/Sources/DebugController.swift b/submodules/DebugSettingsUI/Sources/DebugController.swift similarity index 95% rename from submodules/SettingsUI/Sources/DebugController.swift rename to submodules/DebugSettingsUI/Sources/DebugController.swift index 835d77c19f..9c4b1a535c 100644 --- a/submodules/SettingsUI/Sources/DebugController.swift +++ b/submodules/DebugSettingsUI/Sources/DebugController.swift @@ -13,7 +13,6 @@ import ItemListUI import PresentationDataUtils import OverlayStatusController import AccountContext -import TelegramCallsUI @objc private final class DebugControllerMailComposeDelegate: NSObject, MFMailComposeViewControllerDelegate { public func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) { @@ -191,7 +190,7 @@ private enum DebugControllerEntry: ItemListNodeEntry { var items: [ActionSheetButtonItem] = [] - if let context = arguments.context { + if let context = arguments.context, context.sharedContext.applicationBindings.isMainApp { items.append(ActionSheetButtonItem(title: "Via Telegram", color: .accent, action: { [weak actionSheet] in actionSheet?.dismissAnimated() @@ -261,7 +260,7 @@ private enum DebugControllerEntry: ItemListNodeEntry { var items: [ActionSheetButtonItem] = [] - if let context = arguments.context { + if let context = arguments.context, context.sharedContext.applicationBindings.isMainApp { items.append(ActionSheetButtonItem(title: "Via Telegram", color: .accent, action: { [weak actionSheet] in actionSheet?.dismissAnimated() @@ -343,7 +342,7 @@ private enum DebugControllerEntry: ItemListNodeEntry { var items: [ActionSheetButtonItem] = [] - if let context = arguments.context { + if let context = arguments.context, context.sharedContext.applicationBindings.isMainApp { items.append(ActionSheetButtonItem(title: "Via Telegram", color: .accent, action: { [weak actionSheet] in actionSheet?.dismissAnimated() @@ -438,7 +437,7 @@ private enum DebugControllerEntry: ItemListNodeEntry { var items: [ActionSheetButtonItem] = [] - if let context = arguments.context { + if let context = arguments.context, context.sharedContext.applicationBindings.isMainApp { items.append(ActionSheetButtonItem(title: "Via Telegram", color: .accent, action: { [weak actionSheet] in actionSheet?.dismissAnimated() @@ -781,42 +780,49 @@ private enum DebugControllerEntry: ItemListNodeEntry { } } -private func debugControllerEntries(presentationData: PresentationData, loggingSettings: LoggingSettings, mediaInputSettings: MediaInputSettings, experimentalSettings: ExperimentalUISettings, networkSettings: NetworkSettings?, hasLegacyAppData: Bool) -> [DebugControllerEntry] { +private func debugControllerEntries(sharedContext: SharedAccountContext, presentationData: PresentationData, loggingSettings: LoggingSettings, mediaInputSettings: MediaInputSettings, experimentalSettings: ExperimentalUISettings, networkSettings: NetworkSettings?, hasLegacyAppData: Bool) -> [DebugControllerEntry] { var entries: [DebugControllerEntry] = [] + + let isMainApp = sharedContext.applicationBindings.isMainApp entries.append(.sendLogs(presentationData.theme)) entries.append(.sendOneLog(presentationData.theme)) entries.append(.sendShareLogs) entries.append(.sendNotificationLogs(presentationData.theme)) entries.append(.sendCriticalLogs(presentationData.theme)) - entries.append(.accounts(presentationData.theme)) + if isMainApp { + entries.append(.accounts(presentationData.theme)) + } entries.append(.logToFile(presentationData.theme, loggingSettings.logToFile)) entries.append(.logToConsole(presentationData.theme, loggingSettings.logToConsole)) entries.append(.redactSensitiveData(presentationData.theme, loggingSettings.redactSensitiveData)) - - entries.append(.enableRaiseToSpeak(presentationData.theme, mediaInputSettings.enableRaiseToSpeak)) - entries.append(.keepChatNavigationStack(presentationData.theme, experimentalSettings.keepChatNavigationStack)) - #if DEBUG - entries.append(.skipReadHistory(presentationData.theme, experimentalSettings.skipReadHistory)) - #endif + + if isMainApp { + entries.append(.enableRaiseToSpeak(presentationData.theme, mediaInputSettings.enableRaiseToSpeak)) + entries.append(.keepChatNavigationStack(presentationData.theme, experimentalSettings.keepChatNavigationStack)) + #if DEBUG + entries.append(.skipReadHistory(presentationData.theme, experimentalSettings.skipReadHistory)) + #endif + } entries.append(.crashOnSlowQueries(presentationData.theme, experimentalSettings.crashOnLongQueries)) - entries.append(.clearTips(presentationData.theme)) - if hasLegacyAppData { - entries.append(.reimport(presentationData.theme)) + if isMainApp { + entries.append(.clearTips(presentationData.theme)) } entries.append(.resetData(presentationData.theme)) entries.append(.resetDatabase(presentationData.theme)) entries.append(.resetDatabaseAndCache(presentationData.theme)) entries.append(.resetHoles(presentationData.theme)) - entries.append(.reindexUnread(presentationData.theme)) + if isMainApp { + entries.append(.reindexUnread(presentationData.theme)) + } entries.append(.optimizeDatabase(presentationData.theme)) - entries.append(.knockoutWallpaper(presentationData.theme, experimentalSettings.knockoutWallpaper)) - entries.append(.demoVideoChats(experimentalSettings.demoVideoChats)) - entries.append(.playerEmbedding(experimentalSettings.playerEmbedding)) - entries.append(.playlistPlayback(experimentalSettings.playlistPlayback)) - - entries.append(.voiceConference) + if isMainApp { + entries.append(.knockoutWallpaper(presentationData.theme, experimentalSettings.knockoutWallpaper)) + entries.append(.demoVideoChats(experimentalSettings.demoVideoChats)) + entries.append(.playerEmbedding(experimentalSettings.playerEmbedding)) + entries.append(.playlistPlayback(experimentalSettings.playlistPlayback)) + } let codecs: [(String, String?)] = [ ("No Preference", nil), @@ -829,9 +835,11 @@ private func debugControllerEntries(presentationData: PresentationData, loggingS for i in 0 ..< codecs.count { entries.append(.preferredVideoCodec(i, codecs[i].0, codecs[i].1, experimentalSettings.preferredVideoCodec == codecs[i].1)) } - - entries.append(.disableVideoAspectScaling(experimentalSettings.disableVideoAspectScaling)) - entries.append(.enableVoipTcp(experimentalSettings.enableVoipTcp)) + + if isMainApp { + entries.append(.disableVideoAspectScaling(experimentalSettings.disableVideoAspectScaling)) + entries.append(.enableVoipTcp(experimentalSettings.enableVoipTcp)) + } if let backupHostOverride = networkSettings?.backupHostOverride { entries.append(.hostInfo(presentationData.theme, "Host: \(backupHostOverride)")) @@ -900,7 +908,7 @@ public func debugController(sharedContext: SharedAccountContext, context: Accoun } let controllerState = ItemListControllerState(presentationData: ItemListPresentationData(presentationData), title: .text("Debug"), leftNavigationButton: leftNavigationButton, rightNavigationButton: nil, backNavigationButton: ItemListBackButton(title: presentationData.strings.Common_Back)) - let listState = ItemListNodeState(presentationData: ItemListPresentationData(presentationData), entries: debugControllerEntries(presentationData: presentationData, loggingSettings: loggingSettings, mediaInputSettings: mediaInputSettings, experimentalSettings: experimentalSettings, networkSettings: networkSettings, hasLegacyAppData: hasLegacyAppData), style: .blocks) + let listState = ItemListNodeState(presentationData: ItemListPresentationData(presentationData), entries: debugControllerEntries(sharedContext: sharedContext, presentationData: presentationData, loggingSettings: loggingSettings, mediaInputSettings: mediaInputSettings, experimentalSettings: experimentalSettings, networkSettings: networkSettings, hasLegacyAppData: hasLegacyAppData), style: .blocks) return (controllerState, (listState, arguments)) } diff --git a/submodules/SettingsUI/BUILD b/submodules/SettingsUI/BUILD index 97155853ad..f8ead78c65 100644 --- a/submodules/SettingsUI/BUILD +++ b/submodules/SettingsUI/BUILD @@ -88,6 +88,7 @@ swift_library( "//submodules/AuthTransferUI:AuthTransferUI", "//submodules/WidgetSetupScreen:WidgetSetupScreen", "//submodules/UIKitRuntimeUtils:UIKitRuntimeUtils", + "//submodules/DebugSettingsUI:DebugSettingsUI", ], visibility = [ "//visibility:public", diff --git a/submodules/ShareController/Sources/ShareController.swift b/submodules/ShareController/Sources/ShareController.swift index 430accf2d7..1867d75dad 100644 --- a/submodules/ShareController/Sources/ShareController.swift +++ b/submodules/ShareController/Sources/ShareController.swift @@ -326,6 +326,8 @@ public final class ShareController: ViewController { } } } + + public var debugAction: (() -> Void)? public convenience init(context: AccountContext, subject: ShareControllerSubject, presetText: String? = nil, preferredAction: ShareControllerPreferredAction = .default, showInChat: ((Message) -> Void)? = nil, fromForeignApp: Bool = false, segmentedValues: [ShareControllerSegmentedValue]? = nil, externalShare: Bool = true, immediateExternalShare: Bool = false, switchableAccounts: [AccountWithInfo] = [], immediatePeerId: PeerId? = nil, forceTheme: PresentationTheme? = nil, forcedActionTitle: String? = nil) { self.init(sharedContext: context.sharedContext, currentContext: context, subject: subject, presetText: presetText, preferredAction: preferredAction, showInChat: showInChat, fromForeignApp: fromForeignApp, segmentedValues: segmentedValues, externalShare: externalShare, immediateExternalShare: immediateExternalShare, switchableAccounts: switchableAccounts, immediatePeerId: immediatePeerId, forceTheme: forceTheme, forcedActionTitle: forcedActionTitle) @@ -800,6 +802,9 @@ public final class ShareController: ViewController { strongSelf.view.endEditing(true) strongSelf.present(controller, in: .window(.root), with: ViewControllerPresentationArguments(presentationAnimation: .modalSheet)) } + self.controllerNode.debugAction = { [weak self] in + self?.debugAction?() + } self.displayNodeDidLoad() self.peersDisposable.set((self.peers.get() diff --git a/submodules/ShareController/Sources/ShareControllerNode.swift b/submodules/ShareController/Sources/ShareControllerNode.swift index 8047a4421f..0afd735957 100644 --- a/submodules/ShareController/Sources/ShareControllerNode.swift +++ b/submodules/ShareController/Sources/ShareControllerNode.swift @@ -61,6 +61,7 @@ final class ShareControllerNode: ViewControllerTracingNode, UIScrollViewDelegate var share: ((String, [PeerId]) -> Signal)? var shareExternal: (() -> Signal)? var switchToAnotherAccount: (() -> Void)? + var debugAction: (() -> Void)? var openStats: (() -> Void)? var completed: (([PeerId]) -> Void)? @@ -730,6 +731,8 @@ final class ShareControllerNode: ViewControllerTracingNode, UIScrollViewDelegate let animated = self.peersContentNode == nil let peersContentNode = SharePeersContainerNode(sharedContext: self.sharedContext, context: context, switchableAccounts: switchableAccounts, theme: self.presentationData.theme, strings: self.presentationData.strings, nameDisplayOrder: self.presentationData.nameDisplayOrder, peers: peers, accountPeer: accountPeer, controllerInteraction: self.controllerInteraction!, externalShare: self.externalShare, switchToAnotherAccount: { [weak self] in self?.switchToAnotherAccount?() + }, debugAction: { [weak self] in + self?.debugAction?() }, extendedInitialReveal: self.presetText != nil, segmentedValues: self.segmentedValues) self.peersContentNode = peersContentNode peersContentNode.openSearch = { [weak self] in diff --git a/submodules/ShareController/Sources/SharePeersContainerNode.swift b/submodules/ShareController/Sources/SharePeersContainerNode.swift index e323faa404..381beb78e5 100644 --- a/submodules/ShareController/Sources/SharePeersContainerNode.swift +++ b/submodules/ShareController/Sources/SharePeersContainerNode.swift @@ -81,6 +81,7 @@ final class SharePeersContainerNode: ASDisplayNode, ShareContentContainerNode { private let nameDisplayOrder: PresentationPersonNameOrder private let controllerInteraction: ShareControllerInteraction private let switchToAnotherAccount: () -> Void + private let debugAction: () -> Void private let extendedInitialReveal: Bool let accountPeer: Peer @@ -113,7 +114,7 @@ final class SharePeersContainerNode: ASDisplayNode, ShareContentContainerNode { let peersValue = Promise<[(RenderedPeer, PeerPresence?)]>() - init(sharedContext: SharedAccountContext, context: AccountContext, switchableAccounts: [AccountWithInfo], theme: PresentationTheme, strings: PresentationStrings, nameDisplayOrder: PresentationPersonNameOrder, peers: [(RenderedPeer, PeerPresence?)], accountPeer: Peer, controllerInteraction: ShareControllerInteraction, externalShare: Bool, switchToAnotherAccount: @escaping () -> Void, extendedInitialReveal: Bool, segmentedValues: [ShareControllerSegmentedValue]?) { + init(sharedContext: SharedAccountContext, context: AccountContext, switchableAccounts: [AccountWithInfo], theme: PresentationTheme, strings: PresentationStrings, nameDisplayOrder: PresentationPersonNameOrder, peers: [(RenderedPeer, PeerPresence?)], accountPeer: Peer, controllerInteraction: ShareControllerInteraction, externalShare: Bool, switchToAnotherAccount: @escaping () -> Void, debugAction: @escaping () -> Void, extendedInitialReveal: Bool, segmentedValues: [ShareControllerSegmentedValue]?) { self.sharedContext = sharedContext self.context = context self.theme = theme @@ -122,6 +123,7 @@ final class SharePeersContainerNode: ASDisplayNode, ShareContentContainerNode { self.controllerInteraction = controllerInteraction self.accountPeer = accountPeer self.switchToAnotherAccount = switchToAnotherAccount + self.debugAction = debugAction self.extendedInitialReveal = extendedInitialReveal self.segmentedValues = segmentedValues @@ -240,6 +242,8 @@ final class SharePeersContainerNode: ASDisplayNode, ShareContentContainerNode { self.segmentedNode.selectedIndexChanged = { [weak self] index in self?.segmentedSelectedIndexUpdated?(index) } + + self.contentTitleNode.view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.debugTapGesture(_:)))) } deinit { @@ -464,4 +468,27 @@ final class SharePeersContainerNode: ASDisplayNode, ShareContentContainerNode { @objc private func accountTapGesture(_ recognizer: UITapGestureRecognizer) { self.switchToAnotherAccount() } + + private var debugTapCounter: (Double, Int) = (0.0, 0) + + @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/TelegramUI/BUILD b/submodules/TelegramUI/BUILD index 6462149266..49302fd909 100644 --- a/submodules/TelegramUI/BUILD +++ b/submodules/TelegramUI/BUILD @@ -219,6 +219,7 @@ swift_library( "//submodules/ConfettiEffect:ConfettiEffect", "//submodules/Speak:Speak", "//submodules/PeerInfoAvatarListNode:PeerInfoAvatarListNode", + "//submodules/DebugSettingsUI:DebugSettingsUI", ], visibility = [ "//visibility:public", diff --git a/submodules/TelegramUI/Sources/AuthorizationSequencePhoneEntryController.swift b/submodules/TelegramUI/Sources/AuthorizationSequencePhoneEntryController.swift index 9ad2b45410..3b44aa35aa 100644 --- a/submodules/TelegramUI/Sources/AuthorizationSequencePhoneEntryController.swift +++ b/submodules/TelegramUI/Sources/AuthorizationSequencePhoneEntryController.swift @@ -12,6 +12,7 @@ import AccountContext import CountrySelectionUI import SettingsUI import PhoneNumberFormat +import DebugSettingsUI final class AuthorizationSequencePhoneEntryController: ViewController { private var controllerNode: AuthorizationSequencePhoneEntryControllerNode { diff --git a/submodules/TelegramUI/Sources/ShareExtensionContext.swift b/submodules/TelegramUI/Sources/ShareExtensionContext.swift index d5fd879439..f69336c477 100644 --- a/submodules/TelegramUI/Sources/ShareExtensionContext.swift +++ b/submodules/TelegramUI/Sources/ShareExtensionContext.swift @@ -23,6 +23,7 @@ import PresentationDataUtils import ChatImportUI import ZipArchive import ActivityIndicator +import DebugSettingsUI private let inForeground = ValuePromise(false, ignoreRepeated: true) @@ -393,6 +394,16 @@ public class ShareRootControllerImpl { shareController.dismissed = { _ in self?.getExtensionContext()?.completeRequest(returningItems: nil, completionHandler: nil) } + shareController.debugAction = { + guard let strongSelf = self else { + return + } + let presentationData = internalContext.sharedContext.currentPresentationData.with { $0 } + let navigationController = NavigationController(mode: .single, theme: NavigationControllerTheme(presentationTheme: presentationData.theme)) + strongSelf.navigationController = navigationController + navigationController.viewControllers = [debugController(sharedContext: context.sharedContext, context: context)] + strongSelf.mainWindow?.present(navigationController, on: .root) + } cancelImpl = { [weak shareController] in shareController?.dismiss(completion: { [weak self] in diff --git a/submodules/TelegramUI/Sources/TelegramRootController.swift b/submodules/TelegramUI/Sources/TelegramRootController.swift index 42f7e00bfc..2b96a8aa10 100644 --- a/submodules/TelegramUI/Sources/TelegramRootController.swift +++ b/submodules/TelegramUI/Sources/TelegramRootController.swift @@ -14,6 +14,7 @@ import ChatListUI import SettingsUI import AppBundle import DatePickerNode +import DebugSettingsUI public final class TelegramRootController: NavigationController { private let context: AccountContext