Various fixes

This commit is contained in:
Ilya Laktyushin
2024-07-26 00:11:24 +02:00
parent 332408acb7
commit c5179bc4a6
2 changed files with 29 additions and 26 deletions

View File

@@ -1064,6 +1064,9 @@ public class BrowserScreen: ViewController, MinimizableController {
openInUrl = url openInUrl = url
} }
let canOpenIn = !(self.contentState?.url.hasPrefix("tonsite") ?? false)
var items: [ContextMenuItem] = [] var items: [ContextMenuItem] = []
items.append(.custom(fontItem, false)) items.append(.custom(fontItem, false))
@@ -1105,7 +1108,7 @@ public class BrowserScreen: ViewController, MinimizableController {
performAction.invoke(.addBookmark) performAction.invoke(.addBookmark)
action(.default) 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 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 { if let self {
self.context.sharedContext.applicationBindings.openUrl(openInUrl) self.context.sharedContext.applicationBindings.openUrl(openInUrl)

View File

@@ -601,15 +601,15 @@ final class BrowserWebContent: UIView, BrowserContent, WKNavigationDelegate, WKU
@available(iOS 13.0, *) @available(iOS 13.0, *)
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, preferences: WKWebpagePreferences, decisionHandler: @escaping (WKNavigationActionPolicy, WKWebpagePreferences) -> Void) { func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, preferences: WKWebpagePreferences, decisionHandler: @escaping (WKNavigationActionPolicy, WKWebpagePreferences) -> Void) {
if #available(iOS 14.5, *), navigationAction.shouldPerformDownload { // if #available(iOS 14.5, *), navigationAction.shouldPerformDownload {
self.presentDownloadConfirmation(fileName: navigationAction.request.mainDocumentURL?.lastPathComponent ?? "file", proceed: { download in // self.presentDownloadConfirmation(fileName: navigationAction.request.mainDocumentURL?.lastPathComponent ?? "file", proceed: { download in
if download { // if download {
decisionHandler(.download, preferences) // decisionHandler(.download, preferences)
} else { // } else {
// decisionHandler(.cancel, preferences) //// decisionHandler(.cancel, preferences)
} // }
}) // })
} else { // } else {
if let url = navigationAction.request.url?.absoluteString { if let url = navigationAction.request.url?.absoluteString {
if isTelegramMeLink(url) || isTelegraPhLink(url) { if isTelegramMeLink(url) || isTelegraPhLink(url) {
decisionHandler(.cancel, preferences) decisionHandler(.cancel, preferences)
@@ -621,24 +621,24 @@ final class BrowserWebContent: UIView, BrowserContent, WKNavigationDelegate, WKU
} else { } else {
decisionHandler(.allow, preferences) decisionHandler(.allow, preferences)
} }
} // }
} }
func webView(_ webView: WKWebView, decidePolicyFor navigationResponse: WKNavigationResponse, decisionHandler: @escaping (WKNavigationResponsePolicy) -> Void) { // func webView(_ webView: WKWebView, decidePolicyFor navigationResponse: WKNavigationResponse, decisionHandler: @escaping (WKNavigationResponsePolicy) -> Void) {
if navigationResponse.canShowMIMEType { // if navigationResponse.canShowMIMEType {
decisionHandler(.allow) // decisionHandler(.allow)
} else if #available(iOS 14.5, *) { // } else if #available(iOS 14.5, *) {
self.presentDownloadConfirmation(fileName: navigationResponse.response.suggestedFilename ?? "file", proceed: { download in // self.presentDownloadConfirmation(fileName: navigationResponse.response.suggestedFilename ?? "file", proceed: { download in
if download { // if download {
decisionHandler(.download) // decisionHandler(.download)
} else { // } else {
decisionHandler(.cancel) // decisionHandler(.cancel)
} // }
}) // })
} else { // } else {
decisionHandler(.cancel) // decisionHandler(.cancel)
} // }
} // }
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) { func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
if let url = navigationAction.request.url?.absoluteString { if let url = navigationAction.request.url?.absoluteString {