From 2dfec502619556db397362154481512d845019e5 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Tue, 12 Feb 2019 18:12:12 -0800 Subject: [PATCH] Create and use DetailWebViewControllerDelegate. --- .../Detail/DetailViewController.swift | 9 ++++++-- .../Detail/DetailWebViewController.swift | 22 +++++++------------ 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/NetNewsWire/MainWindow/Detail/DetailViewController.swift b/NetNewsWire/MainWindow/Detail/DetailViewController.swift index 250e28de5..4d0e61b55 100644 --- a/NetNewsWire/MainWindow/Detail/DetailViewController.swift +++ b/NetNewsWire/MainWindow/Detail/DetailViewController.swift @@ -153,15 +153,20 @@ extension DetailViewController: WKScriptMessageHandler { mouseDidExit(link) } } +} - private func mouseDidEnter(_ link: String) { +// MARK: DetailWebViewControllerDelegate + +extension DetailViewController: DetailWebViewControllerDelegate { + + func mouseDidEnter(_ link: String) { guard !link.isEmpty else { return } statusBarView.mouseoverLink = link } - private func mouseDidExit(_ link: String) { + func mouseDidExit(_ link: String) { statusBarView.mouseoverLink = nil } } diff --git a/NetNewsWire/MainWindow/Detail/DetailWebViewController.swift b/NetNewsWire/MainWindow/Detail/DetailWebViewController.swift index f50fd8c5b..44579f34d 100644 --- a/NetNewsWire/MainWindow/Detail/DetailWebViewController.swift +++ b/NetNewsWire/MainWindow/Detail/DetailWebViewController.swift @@ -17,8 +17,14 @@ enum DetailWebViewState: Equatable { case article(Article) } +protocol DetailWebViewControllerDelegate: class { + func mouseDidEnter(_ link: String) + func mouseDidExit(_ link: String) +} + final class DetailWebViewController: NSViewController, WKUIDelegate { + weak var delegate: DetailWebViewControllerDelegate? var webview: DetailWebView! var state: DetailWebViewState = .noSelection { didSet { @@ -66,25 +72,13 @@ final class DetailWebViewController: NSViewController, WKUIDelegate { extension DetailWebViewController: WKScriptMessageHandler { func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) { - if message.name == MessageName.mouseDidEnter, let link = message.body as? String { - mouseDidEnter(link) + delegate?.mouseDidEnter(link) } else if message.name == MessageName.mouseDidExit, let link = message.body as? String{ - mouseDidExit(link) + delegate?.mouseDidExit(link) } } - - private func mouseDidEnter(_ link: String) { - guard !link.isEmpty else { - return - } -// statusBarView.mouseoverLink = link - } - - private func mouseDidExit(_ link: String) { -// statusBarView.mouseoverLink = nil - } } // MARK: - WKNavigationDelegate