diff --git a/iOS/Article/ArticleIconSchemeHandler.swift b/iOS/Article/ArticleIconSchemeHandler.swift index 62fe0ee62..c1bc6df7c 100644 --- a/iOS/Article/ArticleIconSchemeHandler.swift +++ b/iOS/Article/ArticleIconSchemeHandler.swift @@ -8,19 +8,23 @@ import Foundation import WebKit -import Articles -class ArticleIconSchemeHandler: NSObject, WKURLSchemeHandler { +protocol ArticleIconSchemeHandlerDelegate: AnyObject { - weak var coordinator: SceneCoordinator? - - init(coordinator: SceneCoordinator) { - self.coordinator = coordinator + func iconImage(for articleID: String) -> IconImage? +} + +final class ArticleIconSchemeHandler: NSObject, WKURLSchemeHandler { + + weak var delegate: ArticleIconSchemeHandlerDelegate? + + init(delegate: ArticleIconSchemeHandlerDelegate) { + self.delegate = delegate } func webView(_ webView: WKWebView, start urlSchemeTask: WKURLSchemeTask) { - guard let url = urlSchemeTask.request.url, let coordinator = coordinator else { + guard let url = urlSchemeTask.request.url, let delegate else { urlSchemeTask.didFailWithError(URLError(.fileDoesNotExist)) return } @@ -29,7 +33,7 @@ class ArticleIconSchemeHandler: NSObject, WKURLSchemeHandler { return } let articleID = components.path - guard let iconImage = coordinator.articleFor(articleID)?.iconImage() else { + guard let iconImage = delegate.iconImage(for: articleID) else { urlSchemeTask.didFailWithError(URLError(.fileDoesNotExist)) return } @@ -49,12 +53,10 @@ class ArticleIconSchemeHandler: NSObject, WKURLSchemeHandler { urlSchemeTask.didReceive(data) urlSchemeTask.didFinish() } - } func webView(_ webView: WKWebView, stop urlSchemeTask: WKURLSchemeTask) { urlSchemeTask.didFailWithError(URLError(.unknown)) } - } diff --git a/iOS/Article/WebViewController.swift b/iOS/Article/WebViewController.swift index f03775035..d19bbbe3c 100644 --- a/iOS/Article/WebViewController.swift +++ b/iOS/Article/WebViewController.swift @@ -39,7 +39,7 @@ class WebViewController: UIViewController { private var isFullScreenAvailable: Bool { return AppDefaults.shared.articleFullscreenAvailable && traitCollection.userInterfaceIdiom == .phone && coordinator.isRootSplitCollapsed } - private lazy var articleIconSchemeHandler = ArticleIconSchemeHandler(coordinator: coordinator); + private lazy var articleIconSchemeHandler = ArticleIconSchemeHandler(delegate: self); private lazy var transition = ImageTransition(controller: self) private var clickedImageCompletion: (() -> Void)? @@ -326,6 +326,16 @@ extension WebViewController: ArticleExtractorDelegate { } + +// MARK: ArticleIconSchemeHandlerDelegate + +extension WebViewController: ArticleIconSchemeHandlerDelegate { + + func iconImage(for articleID: String) -> IconImage? { + coordinator.articleFor(articleID)?.iconImage() + } +} + // MARK: UIContextMenuInteractionDelegate extension WebViewController: UIContextMenuInteractionDelegate {