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

View File

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

View File

@ -20,7 +20,7 @@ import RSCore
static let articleUTIInternalType = NSPasteboard.PasteboardType(rawValue: articleUTIInternal)
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) {