Bot previews

This commit is contained in:
Isaac
2024-07-24 01:56:34 +08:00
parent f604bc114f
commit 42a6f6e8bc
52 changed files with 3806 additions and 523 deletions

View File

@@ -4,6 +4,7 @@ import Display
import AsyncDisplayKit
import WebKit
import TelegramPresentationData
import AccountContext
private class WeakPaymentScriptMessageHandler: NSObject, WKScriptMessageHandler {
private let f: (WKScriptMessage) -> ()
@@ -20,12 +21,14 @@ private class WeakPaymentScriptMessageHandler: NSObject, WKScriptMessageHandler
}
final class BotCheckoutWebInteractionControllerNode: ViewControllerTracingNode, WKNavigationDelegate {
private let context: AccountContext
private var presentationData: PresentationData
private let intent: BotCheckoutWebInteractionControllerIntent
private var webView: WKWebView?
init(presentationData: PresentationData, url: String, intent: BotCheckoutWebInteractionControllerIntent) {
init(context: AccountContext, presentationData: PresentationData, url: String, intent: BotCheckoutWebInteractionControllerIntent) {
self.context = context
self.presentationData = presentationData
self.intent = intent
@@ -146,6 +149,14 @@ final class BotCheckoutWebInteractionControllerNode: ViewControllerTracingNode,
decisionHandler(.allow)
}
} else {
if let url = navigationAction.request.url, let scheme = url.scheme {
let defaultSchemes: [String] = ["http", "https"]
if !defaultSchemes.contains(scheme) {
decisionHandler(.cancel)
self.context.sharedContext.applicationBindings.openUrl(url.absoluteString)
return
}
}
decisionHandler(.allow)
}
}