From ada188209eba9803979452c9fe26915c03f3156c Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Tue, 16 Jul 2024 06:41:23 +0400 Subject: [PATCH] Various improvements --- .../Telegram-iOS/en.lproj/Localizable.strings | 2 ++ .../BrowserNavigationBarComponent.swift | 1 + .../DataAndStorageSettingsController.swift | 4 ++- .../Data and Storage/WebBrowserItem.swift | 26 +++++++++++++------ .../WebBrowserSettingsController.swift | 9 ++++--- submodules/TelegramUI/Sources/OpenUrl.swift | 26 +++++++++---------- 6 files changed, 42 insertions(+), 26 deletions(-) diff --git a/Telegram/Telegram-iOS/en.lproj/Localizable.strings b/Telegram/Telegram-iOS/en.lproj/Localizable.strings index 7c75dcd015..80ea7e8f73 100644 --- a/Telegram/Telegram-iOS/en.lproj/Localizable.strings +++ b/Telegram/Telegram-iOS/en.lproj/Localizable.strings @@ -12526,6 +12526,8 @@ Sorry for the inconvenience."; "Browser.ContextMenu.CopyLink" = "Copy Link"; "Browser.ContextMenu.Share" = "Share"; +"WebBrowser.Telegram" = "Telegram"; + "Monetization.Proceeds.Ton.Info" = "TON from your total balance can be used for ads or withdrawn as rewards 3 days after they are earned."; "Monetization.Proceeds.Stars.Info" = "Stars from your total balance can be used for ads or withdrawn as rewards 21 days after they are earned."; "Monetization.Proceeds.TonAndStars.Info" = "Stars and TON from your total balance can be used for ads or withdrawn as rewards 21 and 3 days respectively after they are earned."; diff --git a/submodules/BrowserUI/Sources/BrowserNavigationBarComponent.swift b/submodules/BrowserUI/Sources/BrowserNavigationBarComponent.swift index a20a2db6cd..c873ddbaef 100644 --- a/submodules/BrowserUI/Sources/BrowserNavigationBarComponent.swift +++ b/submodules/BrowserUI/Sources/BrowserNavigationBarComponent.swift @@ -178,6 +178,7 @@ final class BrowserNavigationBarComponent: CombinedComponent { context.add(readingProgress .position(CGPoint(x: readingProgress.size.width / 2.0, y: size.height / 2.0)) + .opacity(context.component.centerItem?.id == AnyHashable("search") ? 0.0 : 1.0) ) context.add(separator diff --git a/submodules/SettingsUI/Sources/Data and Storage/DataAndStorageSettingsController.swift b/submodules/SettingsUI/Sources/Data and Storage/DataAndStorageSettingsController.swift index e5f16c1201..d3a2363d15 100644 --- a/submodules/SettingsUI/Sources/Data and Storage/DataAndStorageSettingsController.swift +++ b/submodules/SettingsUI/Sources/Data and Storage/DataAndStorageSettingsController.swift @@ -917,8 +917,10 @@ public func dataAndStorageController(context: AccountContext, focusOnItemTag: Da let defaultWebBrowser: String if let option = options.first(where: { $0.identifier == webBrowserSettings.defaultWebBrowser }) { defaultWebBrowser = option.title - } else { + } else if webBrowserSettings.defaultWebBrowser == "inApp" { defaultWebBrowser = presentationData.strings.WebBrowser_InAppSafari + } else { + defaultWebBrowser = presentationData.strings.WebBrowser_Telegram } let controllerState = ItemListControllerState(presentationData: ItemListPresentationData(presentationData), title: .text(presentationData.strings.ChatSettings_Title), leftNavigationButton: nil, rightNavigationButton: nil, backNavigationButton: ItemListBackButton(title: presentationData.strings.Common_Back), animateChanges: false) diff --git a/submodules/SettingsUI/Sources/Data and Storage/WebBrowserItem.swift b/submodules/SettingsUI/Sources/Data and Storage/WebBrowserItem.swift index 480f42c5f7..5dcd3e2263 100644 --- a/submodules/SettingsUI/Sources/Data and Storage/WebBrowserItem.swift +++ b/submodules/SettingsUI/Sources/Data and Storage/WebBrowserItem.swift @@ -8,18 +8,20 @@ import TelegramPresentationData import ItemListUI import PhotoResources import OpenInExternalAppUI +import AccountContext +import AppBundle class WebBrowserItem: ListViewItem, ItemListItem { - let engine: TelegramEngine + let context: AccountContext let presentationData: ItemListPresentationData let title: String - let application: OpenInApplication + let application: OpenInApplication? let checked: Bool public let sectionId: ItemListSectionId let action: () -> Void - public init(engine: TelegramEngine, presentationData: ItemListPresentationData, title: String, application: OpenInApplication, checked: Bool, sectionId: ItemListSectionId, action: @escaping () -> Void) { - self.engine = engine + public init(context: AccountContext, presentationData: ItemListPresentationData, title: String, application: OpenInApplication?, checked: Bool, sectionId: ItemListSectionId, action: @escaping () -> Void) { + self.context = context self.presentationData = presentationData self.title = title self.application = application @@ -131,6 +133,7 @@ private final class WebBrowserItemNode: ListViewItemNode { let makeIconLayout = self.iconNode.asyncLayout() let currentItem = self.item + return { item, params, neighbors in let leftInset: CGFloat = params.leftInset + 16.0 + 43.0 @@ -140,18 +143,25 @@ private final class WebBrowserItemNode: ListViewItemNode { let imageApply = makeIconLayout(arguments) var updatedIconSignal: Signal<(TransformImageArguments) -> DrawingContext?, NoError>? - if currentItem?.application != item.application { + if currentItem == nil { switch item.application { + case .none: + let icons = item.context.sharedContext.applicationBindings.getAvailableAlternateIcons() + let current = item.context.sharedContext.applicationBindings.getAlternateIconName() + let currentIcon = icons.first(where: { $0.name == current })?.imageName ?? "BlueIcon" + if let image = UIImage(named: currentIcon, in: getAppBundle(), compatibleWith: nil) { + updatedIconSignal = openInAppIcon(engine: item.context.engine, appIcon: .image(image: image)) + } case .safari: if let image = UIImage(bundleImageName: "Open In/Safari") { - updatedIconSignal = openInAppIcon(engine: item.engine, appIcon: .image(image: image)) + updatedIconSignal = openInAppIcon(engine: item.context.engine, appIcon: .image(image: image)) } case .maps: if let image = UIImage(bundleImageName: "Open In/Maps") { - updatedIconSignal = openInAppIcon(engine: item.engine, appIcon: .image(image: image)) + updatedIconSignal = openInAppIcon(engine: item.context.engine, appIcon: .image(image: image)) } case let .other(_, identifier, _, store): - updatedIconSignal = openInAppIcon(engine: item.engine, appIcon: .resource(resource: OpenInAppIconResource(appStoreId: identifier, store: store))) + updatedIconSignal = openInAppIcon(engine: item.context.engine, appIcon: .resource(resource: OpenInAppIconResource(appStoreId: identifier, store: store))) } } diff --git a/submodules/SettingsUI/Sources/Data and Storage/WebBrowserSettingsController.swift b/submodules/SettingsUI/Sources/Data and Storage/WebBrowserSettingsController.swift index d35202da74..e5555124ab 100644 --- a/submodules/SettingsUI/Sources/Data and Storage/WebBrowserSettingsController.swift +++ b/submodules/SettingsUI/Sources/Data and Storage/WebBrowserSettingsController.swift @@ -26,7 +26,7 @@ private enum WebBrowserSettingsSection: Int32 { private enum WebBrowserSettingsControllerEntry: ItemListNodeEntry { case browserHeader(PresentationTheme, String) - case browser(PresentationTheme, String, OpenInApplication, String?, Bool, Int32) + case browser(PresentationTheme, String, OpenInApplication?, String?, Bool, Int32) var section: ItemListSectionId { switch self { @@ -71,7 +71,7 @@ private enum WebBrowserSettingsControllerEntry: ItemListNodeEntry { case let .browserHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) case let .browser(_, title, application, identifier, selected, _): - return WebBrowserItem(engine: arguments.context.engine, presentationData: presentationData, title: title, application: application, checked: selected, sectionId: self.section) { + return WebBrowserItem(context: arguments.context, presentationData: presentationData, title: title, application: application, checked: selected, sectionId: self.section) { arguments.updateDefaultBrowser(identifier) } } @@ -84,9 +84,10 @@ private func webBrowserSettingsControllerEntries(context: AccountContext, presen let options = availableOpenInOptions(context: context, item: .url(url: "http://telegram.org")) entries.append(.browserHeader(presentationData.theme, presentationData.strings.WebBrowser_DefaultBrowser)) - entries.append(.browser(presentationData.theme, presentationData.strings.WebBrowser_InAppSafari, .safari, nil, selectedBrowser == nil, 0)) + entries.append(.browser(presentationData.theme, presentationData.strings.WebBrowser_Telegram, nil, nil, selectedBrowser == nil, 0)) + entries.append(.browser(presentationData.theme, presentationData.strings.WebBrowser_InAppSafari, .safari, "inApp", selectedBrowser == "inApp", 1)) - var index: Int32 = 1 + var index: Int32 = 2 for option in options { entries.append(.browser(presentationData.theme, option.title, option.application, option.identifier, option.identifier == selectedBrowser, index)) index += 1 diff --git a/submodules/TelegramUI/Sources/OpenUrl.swift b/submodules/TelegramUI/Sources/OpenUrl.swift index e6a021bbfc..096aec778f 100644 --- a/submodules/TelegramUI/Sources/OpenUrl.swift +++ b/submodules/TelegramUI/Sources/OpenUrl.swift @@ -1044,8 +1044,19 @@ func openExternalUrlImpl(context: AccountContext, urlContext: OpenURLContext, ur let _ = (settings |> deliverOnMainQueue).startStandalone(next: { settings in - if settings.defaultWebBrowser == nil { - if isCompact && context.sharedContext.immediateExperimentalUISettings.browserExperiment { + if let defaultWebBrowser = settings.defaultWebBrowser, defaultWebBrowser != "inApp" { + let openInOptions = availableOpenInOptions(context: context, item: .url(url: url)) + if let option = openInOptions.first(where: { $0.identifier == settings.defaultWebBrowser }) { + if case let .openUrl(url) = option.action() { + context.sharedContext.applicationBindings.openUrl(url) + } else { + context.sharedContext.applicationBindings.openUrl(url) + } + } else { + context.sharedContext.applicationBindings.openUrl(url) + } + } else { + if settings.defaultWebBrowser == nil && isCompact { let controller = BrowserScreen(context: context, subject: .webPage(url: parsedUrl.absoluteString)) navigationController?.pushViewController(controller) } else { @@ -1058,17 +1069,6 @@ func openExternalUrlImpl(context: AccountContext, urlContext: OpenURLContext, ur context.sharedContext.applicationBindings.openUrl(parsedUrl.absoluteString) } } - } else { - let openInOptions = availableOpenInOptions(context: context, item: .url(url: url)) - if let option = openInOptions.first(where: { $0.identifier == settings.defaultWebBrowser }) { - if case let .openUrl(url) = option.action() { - context.sharedContext.applicationBindings.openUrl(url) - } else { - context.sharedContext.applicationBindings.openUrl(url) - } - } else { - context.sharedContext.applicationBindings.openUrl(url) - } } }) }