Fix previewing HTTP(S) URLs

This commit is contained in:
Shadowfacts 2020-12-20 15:07:37 -05:00
parent a0a12f3865
commit d4af73a18e
1 changed files with 13 additions and 3 deletions

View File

@ -11,6 +11,7 @@ import WebKit
import GeminiProtocol import GeminiProtocol
import GeminiFormat import GeminiFormat
import GeminiRenderer import GeminiRenderer
import SafariServices
class BrowserWebViewController: UIViewController { class BrowserWebViewController: UIViewController {
@ -252,12 +253,16 @@ extension BrowserWebViewController: WKNavigationDelegate {
extension BrowserWebViewController: WKUIDelegate { extension BrowserWebViewController: WKUIDelegate {
func webView(_ webView: WKWebView, contextMenuConfigurationForElement elementInfo: WKContextMenuElementInfo, completionHandler: @escaping (UIContextMenuConfiguration?) -> Void) { func webView(_ webView: WKWebView, contextMenuConfigurationForElement elementInfo: WKContextMenuElementInfo, completionHandler: @escaping (UIContextMenuConfiguration?) -> Void) {
guard let url = elementInfo.linkURL, guard let url = elementInfo.linkURL,
url.scheme == "gemini" else { url.scheme == "gemini" || url.scheme == "http" || url.scheme == "https" else {
completionHandler(nil) completionHandler(nil)
return return
} }
let config = UIContextMenuConfiguration(identifier: nil) { let config = UIContextMenuConfiguration(identifier: nil) {
return BrowserWebViewController(navigator: self.navigator, url: url) if url.scheme == "gemini" {
return BrowserWebViewController(navigator: self.navigator, url: url)
} else {
return SFSafariViewController(url: url)
}
} actionProvider: { (_) in } actionProvider: { (_) in
return nil return nil
} }
@ -266,8 +271,13 @@ extension BrowserWebViewController: WKUIDelegate {
func webView(_ webView: WKWebView, contextMenuForElement elementInfo: WKContextMenuElementInfo, willCommitWithAnimator animator: UIContextMenuInteractionCommitAnimating) { func webView(_ webView: WKWebView, contextMenuForElement elementInfo: WKContextMenuElementInfo, willCommitWithAnimator animator: UIContextMenuInteractionCommitAnimating) {
animator.preferredCommitStyle = .pop animator.preferredCommitStyle = .pop
let url = elementInfo.linkURL!
animator.addCompletion { animator.addCompletion {
self.navigator.changeURL(elementInfo.linkURL!) if url.scheme == "http" || url.scheme == "https" {
self.present(animator.previewViewController!, animated: true)
} else {
self.navigator.changeURL(url)
}
} }
} }
} }