Merge pull request #450 from vincode-io/issue-404-405

Enabled body css class to follow system appearance changes between li…
This commit is contained in:
Brent Simmons 2018-09-10 13:02:20 -07:00 committed by GitHub
commit 3f0b8a8ce7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 5 deletions

View File

@ -20,6 +20,8 @@ class ArticleRenderer {
let article: Article let article: Article
let articleStyle: ArticleStyle let articleStyle: ArticleStyle
let appearance: NSAppearance?
static var faviconImgTagCache = [Feed: String]() static var faviconImgTagCache = [Feed: String]()
static var feedIconImgTagCache = [Feed: String]() static var feedIconImgTagCache = [Feed: String]()
@ -87,10 +89,12 @@ class ArticleRenderer {
return renderedHTML() return renderedHTML()
} }
init(article: Article, style: ArticleStyle) { init(article: Article, style: ArticleStyle, appearance: NSAppearance? = nil) {
self.article = article self.article = article
self.articleStyle = style self.articleStyle = style
self.appearance = appearance
} }
// MARK: Private // MARK: Private
@ -472,9 +476,9 @@ class ArticleRenderer {
</script> </script>
""" """
s += "\n\n</head><body onload='startup()' class=light>\n\n" let appearanceClass = appearance?.isDarkMode ?? false ? "dark" : "light"
s += "\n\n</head><body id='bodyId' onload='startup()' class=\(appearanceClass)>\n\n"
s += RSMacroProcessor.renderedText(withTemplate: template(), substitutions: substitutions(), macroStart: "[[", macroEnd: "]]") s += RSMacroProcessor.renderedText(withTemplate: template(), substitutions: substitutions(), macroStart: "[[", macroEnd: "]]")

View File

@ -195,7 +195,9 @@ private extension DetailViewController {
func reloadHTML() { func reloadHTML() {
if let article = article { if let article = article {
let articleRenderer = ArticleRenderer(article: article, style: ArticleStylesManager.shared.currentStyle) let articleRenderer = ArticleRenderer(article: article,
style: ArticleStylesManager.shared.currentStyle,
appearance: self.view.effectiveAppearance)
webview.loadHTMLString(articleRenderer.html, baseURL: articleRenderer.baseURL) webview.loadHTMLString(articleRenderer.html, baseURL: articleRenderer.baseURL)
} }
else { else {

View File

@ -30,6 +30,12 @@ final class DetailWebView: WKWebView {
super.willOpenMenu(menu, with: event) super.willOpenMenu(menu, with: event)
} }
override func viewDidChangeEffectiveAppearance() {
let bodyClass = effectiveAppearance.isDarkMode ? "dark" : "light"
evaluateJavaScript("document.getElementById('bodyId').className = '\(bodyClass)'")
}
} }
private extension NSUserInterfaceItemIdentifier { private extension NSUserInterfaceItemIdentifier {