This commit is contained in:
Balazs Perlaki-Horvath 2023-11-14 09:52:07 +01:00 committed by Kelson
parent 8f3cd6f371
commit 21b33a1c76

View File

@ -8,13 +8,12 @@
import WebKit
final class BrowserUIDelegate: NSObject, WKUIDelegate {
@Published private(set) var externalURL: URL?
#if os(macOS)
func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration,
for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? {
func webView(_: WKWebView, createWebViewWith _: WKWebViewConfiguration,
for navigationAction: WKNavigationAction, windowFeatures _: WKWindowFeatures) -> WKWebView?
{
guard navigationAction.targetFrame == nil else { return nil }
guard let newUrl = navigationAction.request.url else { return nil }
@ -42,14 +41,15 @@ final class BrowserUIDelegate: NSObject, WKUIDelegate {
#if os(iOS)
func webView(_ webView: WKWebView,
contextMenuConfigurationForElement elementInfo: WKContextMenuElementInfo,
completionHandler: @escaping (UIContextMenuConfiguration?) -> Void) {
completionHandler: @escaping (UIContextMenuConfiguration?) -> Void)
{
guard let url = elementInfo.linkURL, url.isKiwixURL else { completionHandler(nil); return }
let configuration = UIContextMenuConfiguration(
previewProvider: {
let webView = WKWebView(frame: .zero, configuration: WebViewConfiguration())
webView.load(URLRequest(url: url))
return WebViewController(webView: webView)
}, actionProvider: { suggestedActions in
}, actionProvider: { _ in
var actions = [UIAction]()
// open url