From c5179bc4a62d8bb90cfa6730804ec2888d6937f1 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Fri, 26 Jul 2024 00:11:24 +0200 Subject: [PATCH] Various fixes --- .../BrowserUI/Sources/BrowserScreen.swift | 5 +- .../BrowserUI/Sources/BrowserWebContent.swift | 50 +++++++++---------- 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/submodules/BrowserUI/Sources/BrowserScreen.swift b/submodules/BrowserUI/Sources/BrowserScreen.swift index bfd14aca62..c63dd013d7 100644 --- a/submodules/BrowserUI/Sources/BrowserScreen.swift +++ b/submodules/BrowserUI/Sources/BrowserScreen.swift @@ -1064,6 +1064,9 @@ public class BrowserScreen: ViewController, MinimizableController { openInUrl = url } + + let canOpenIn = !(self.contentState?.url.hasPrefix("tonsite") ?? false) + var items: [ContextMenuItem] = [] items.append(.custom(fontItem, false)) @@ -1105,7 +1108,7 @@ public class BrowserScreen: ViewController, MinimizableController { performAction.invoke(.addBookmark) action(.default) }))) - if !layout.metrics.isTablet { + if !layout.metrics.isTablet && canOpenIn { items.append(.action(ContextMenuActionItem(text: self.presentationData.strings.InstantPage_OpenInBrowser(openInTitle).string, icon: { theme in return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Browser"), color: theme.contextMenu.primaryColor) }, action: { [weak self] (controller, action) in if let self { self.context.sharedContext.applicationBindings.openUrl(openInUrl) diff --git a/submodules/BrowserUI/Sources/BrowserWebContent.swift b/submodules/BrowserUI/Sources/BrowserWebContent.swift index 5a3d848674..acf2633086 100644 --- a/submodules/BrowserUI/Sources/BrowserWebContent.swift +++ b/submodules/BrowserUI/Sources/BrowserWebContent.swift @@ -601,15 +601,15 @@ final class BrowserWebContent: UIView, BrowserContent, WKNavigationDelegate, WKU @available(iOS 13.0, *) func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, preferences: WKWebpagePreferences, decisionHandler: @escaping (WKNavigationActionPolicy, WKWebpagePreferences) -> Void) { - if #available(iOS 14.5, *), navigationAction.shouldPerformDownload { - self.presentDownloadConfirmation(fileName: navigationAction.request.mainDocumentURL?.lastPathComponent ?? "file", proceed: { download in - if download { - decisionHandler(.download, preferences) - } else { -// decisionHandler(.cancel, preferences) - } - }) - } else { +// if #available(iOS 14.5, *), navigationAction.shouldPerformDownload { +// self.presentDownloadConfirmation(fileName: navigationAction.request.mainDocumentURL?.lastPathComponent ?? "file", proceed: { download in +// if download { +// decisionHandler(.download, preferences) +// } else { +//// decisionHandler(.cancel, preferences) +// } +// }) +// } else { if let url = navigationAction.request.url?.absoluteString { if isTelegramMeLink(url) || isTelegraPhLink(url) { decisionHandler(.cancel, preferences) @@ -621,24 +621,24 @@ final class BrowserWebContent: UIView, BrowserContent, WKNavigationDelegate, WKU } else { decisionHandler(.allow, preferences) } - } +// } } - func webView(_ webView: WKWebView, decidePolicyFor navigationResponse: WKNavigationResponse, decisionHandler: @escaping (WKNavigationResponsePolicy) -> Void) { - if navigationResponse.canShowMIMEType { - decisionHandler(.allow) - } else if #available(iOS 14.5, *) { - self.presentDownloadConfirmation(fileName: navigationResponse.response.suggestedFilename ?? "file", proceed: { download in - if download { - decisionHandler(.download) - } else { - decisionHandler(.cancel) - } - }) - } else { - decisionHandler(.cancel) - } - } +// func webView(_ webView: WKWebView, decidePolicyFor navigationResponse: WKNavigationResponse, decisionHandler: @escaping (WKNavigationResponsePolicy) -> Void) { +// if navigationResponse.canShowMIMEType { +// decisionHandler(.allow) +// } else if #available(iOS 14.5, *) { +// self.presentDownloadConfirmation(fileName: navigationResponse.response.suggestedFilename ?? "file", proceed: { download in +// if download { +// decisionHandler(.download) +// } else { +// decisionHandler(.cancel) +// } +// }) +// } else { +// decisionHandler(.cancel) +// } +// } func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) { if let url = navigationAction.request.url?.absoluteString {