Remove no-longer needed appearance code, now that WKWebView supports @media(prefers-color-scheme: dark).

This commit is contained in:
Brent Simmons 2019-04-02 21:57:34 -07:00
parent ed101b0028
commit b65d563c7c
3 changed files with 14 additions and 22 deletions

View File

@ -15,30 +15,28 @@ struct ArticleRenderer {
private let article: Article? private let article: Article?
private let articleStyle: ArticleStyle private let articleStyle: ArticleStyle
private let appearance: NSAppearance?
private let title: String private let title: String
private init(article: Article?, style: ArticleStyle, appearance: NSAppearance?) { private init(article: Article?, style: ArticleStyle) {
self.article = article self.article = article
self.articleStyle = style self.articleStyle = style
self.appearance = appearance
self.title = article?.title ?? "" self.title = article?.title ?? ""
} }
// MARK: - API // MARK: - API
static func articleHTML(article: Article, style: ArticleStyle, appearance: NSAppearance?) -> String { static func articleHTML(article: Article, style: ArticleStyle) -> String {
let renderer = ArticleRenderer(article: article, style: style, appearance: appearance) let renderer = ArticleRenderer(article: article, style: style)
return renderer.articleHTML return renderer.articleHTML
} }
static func multipleSelectionHTML(style: ArticleStyle, appearance: NSAppearance?) -> String { static func multipleSelectionHTML(style: ArticleStyle) -> String {
let renderer = ArticleRenderer(article: nil, style: style, appearance: appearance) let renderer = ArticleRenderer(article: nil, style: style)
return renderer.multipleSelectionHTML return renderer.multipleSelectionHTML
} }
static func noSelectionHTML(style: ArticleStyle, appearance: NSAppearance?) -> String { static func noSelectionHTML(style: ArticleStyle) -> String {
let renderer = ArticleRenderer(article: nil, style: style, appearance: appearance) let renderer = ArticleRenderer(article: nil, style: style)
return renderer.noSelectionHTML return renderer.noSelectionHTML
} }
} }
@ -338,8 +336,7 @@ private extension ArticleRenderer {
""" """
let appearanceClass = appearance?.isDarkMode ?? false ? "dark" : "light" s += "\n\n</head><body onload='startup()'>\n\n"
s += "\n\n</head><body id='bodyId' onload='startup()' class=\(appearanceClass)>\n\n"
s += body s += body
s += "\n\n</body></html>" s += "\n\n</body></html>"

View File

@ -61,12 +61,8 @@ final class DetailWebViewController: NSViewController, WKUIDelegate {
} }
view = webview view = webview
DispatchQueue.main.async { self.reloadHTML()
// Must do this async, because reloadHTML references view.effectiveAppearance,
// which causes loadView to get called. Infinite loop.
self.reloadHTML()
}
} }
// MARK: Scrolling // MARK: Scrolling
@ -119,17 +115,16 @@ private extension DetailWebViewController {
func reloadHTML() { func reloadHTML() {
let style = ArticleStylesManager.shared.currentStyle let style = ArticleStylesManager.shared.currentStyle
let appearance = view.effectiveAppearance
let html: String let html: String
var baseURL: URL? = nil var baseURL: URL? = nil
switch state { switch state {
case .noSelection: case .noSelection:
html = ArticleRenderer.noSelectionHTML(style: style, appearance: appearance) html = ArticleRenderer.noSelectionHTML(style: style)
case .multipleSelection: case .multipleSelection:
html = ArticleRenderer.multipleSelectionHTML(style: style, appearance: appearance) html = ArticleRenderer.multipleSelectionHTML(style: style)
case .article(let article): case .article(let article):
html = ArticleRenderer.articleHTML(article: article, style: style, appearance: appearance) html = ArticleRenderer.articleHTML(article: article, style: style)
baseURL = article.baseURL baseURL = article.baseURL
} }

View File

@ -20,7 +20,7 @@ import RSCore
static let articleUTIInternalType = NSPasteboard.PasteboardType(rawValue: articleUTIInternal) static let articleUTIInternalType = NSPasteboard.PasteboardType(rawValue: articleUTIInternal)
private lazy var renderedHTML: String = { private lazy var renderedHTML: String = {
return ArticleRenderer.articleHTML(article: article, style: ArticleStylesManager.shared.currentStyle, appearance: nil) return ArticleRenderer.articleHTML(article: article, style: ArticleStylesManager.shared.currentStyle)
}() }()
init(article: Article) { init(article: Article) {