From 896f649ca68b5d4ee75eaa064aa5e4c554363cd7 Mon Sep 17 00:00:00 2001 From: Kylmakalle Date: Thu, 4 Jul 2024 02:53:11 +0300 Subject: [PATCH] Force System Share sheet tg://sg/debug --- Swiftgram/SGDebugUI/Sources/SGDebugUI.swift | 14 ++++++++++++-- .../SGSimpleSettings/Sources/SimpleSettings.swift | 7 ++++++- .../ShareController/Sources/ShareController.swift | 5 +++++ .../TelegramUI/Sources/OpenChatMessage.swift | 1 + 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/Swiftgram/SGDebugUI/Sources/SGDebugUI.swift b/Swiftgram/SGDebugUI/Sources/SGDebugUI.swift index 5b356aef66..45905ead93 100644 --- a/Swiftgram/SGDebugUI/Sources/SGDebugUI.swift +++ b/Swiftgram/SGDebugUI/Sources/SGDebugUI.swift @@ -26,8 +26,12 @@ private enum SGDebugActions: String { case clearRegDateCache } +private enum SGDebugToggles: String { + case forceImmediateShareSheet +} -private typealias SGDebugControllerEntry = SGItemListUIEntry + +private typealias SGDebugControllerEntry = SGItemListUIEntry private func SGDebugControllerEntries(presentationData: PresentationData) -> [SGDebugControllerEntry] { var entries: [SGDebugControllerEntry] = [] @@ -37,6 +41,7 @@ private func SGDebugControllerEntries(presentationData: PresentationData) -> [SG entries.append(.action(id: id.count, section: .base, actionType: .flexing, text: "FLEX", kind: .generic)) #endif entries.append(.action(id: id.count, section: .base, actionType: .clearRegDateCache, text: "Clear Regdate cache", kind: .generic)) + entries.append(.toggle(id: id.count, section: .base, settingName: .forceImmediateShareSheet, value: SGSimpleSettings.shared.forceSystemSharing, text: "Force System Share Sheet", enabled: true)) return entries } @@ -51,7 +56,12 @@ public func sgDebugController(context: AccountContext) -> ViewController { let simplePromise = ValuePromise(true, ignoreRepeated: false) - let arguments = SGItemListArguments(context: context, action: { actionType in + let arguments = SGItemListArguments(context: context, setBoolValue: { toggleName, value in + switch toggleName { + case .forceImmediateShareSheet: + SGSimpleSettings.shared.forceSystemSharing = value + } + }, action: { actionType in let presentationData = context.sharedContext.currentPresentationData.with { $0 } switch actionType { case .clearRegDateCache: diff --git a/Swiftgram/SGSimpleSettings/Sources/SimpleSettings.swift b/Swiftgram/SGSimpleSettings/Sources/SimpleSettings.swift index b6f02fe12b..a0da8c3286 100644 --- a/Swiftgram/SGSimpleSettings/Sources/SimpleSettings.swift +++ b/Swiftgram/SGSimpleSettings/Sources/SimpleSettings.swift @@ -102,6 +102,7 @@ public class SGSimpleSettings { case forceEmojiTab case forceBuiltInMic case hideChannelBottomButton + case forceSystemSharing } public enum DownloadSpeedBoostValues: String, CaseIterable { @@ -187,7 +188,8 @@ public class SGSimpleSettings { Keys.messageDoubleTapActionOutgoing.rawValue: MessageDoubleTapAction.default.rawValue, Keys.wideChannelPosts.rawValue: false, Keys.forceEmojiTab.rawValue: false, - Keys.hideChannelBottomButton.rawValue: false + Keys.hideChannelBottomButton.rawValue: false, + Keys.forceSystemSharing.rawValue: false, ] @UserDefault(key: Keys.hidePhoneInSettings.rawValue) @@ -350,6 +352,9 @@ public class SGSimpleSettings { @UserDefault(key: Keys.hideChannelBottomButton.rawValue) public var hideChannelBottomButton: Bool + + @UserDefault(key: Keys.forceSystemSharing.rawValue) + public var forceSystemSharing: Bool } extension SGSimpleSettings { diff --git a/submodules/ShareController/Sources/ShareController.swift b/submodules/ShareController/Sources/ShareController.swift index 721e4dd82e..d7d4b2726d 100644 --- a/submodules/ShareController/Sources/ShareController.swift +++ b/submodules/ShareController/Sources/ShareController.swift @@ -1,4 +1,5 @@ import Foundation +import SGSimpleSettings import UIKit import Display import AsyncDisplayKit @@ -461,6 +462,10 @@ public final class ShareController: ViewController { public var parentNavigationController: NavigationController? 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, updatedPresentationData: (initial: PresentationData, signal: Signal)? = nil, forceTheme: PresentationTheme? = nil, forcedActionTitle: String? = nil, shareAsLink: Bool = false, collectibleItemInfo: TelegramCollectibleItemInfo? = nil) { + var immediateExternalShare = immediateExternalShare + if SGSimpleSettings.shared.forceSystemSharing { + immediateExternalShare = true + } self.init( environment: ShareControllerAppEnvironment(sharedContext: context.sharedContext), currentContext: ShareControllerAppAccountContext(context: context), diff --git a/submodules/TelegramUI/Sources/OpenChatMessage.swift b/submodules/TelegramUI/Sources/OpenChatMessage.swift index 30f7ee7b64..f4f1a1aa9c 100644 --- a/submodules/TelegramUI/Sources/OpenChatMessage.swift +++ b/submodules/TelegramUI/Sources/OpenChatMessage.swift @@ -1,4 +1,5 @@ import Foundation +import SGSimpleSettings import Display import AsyncDisplayKit import Postbox