Enabled body css class to follow system appearance changes between light and dark modes. Issue #404 & Issue #405
This commit is contained in:
parent
fe8af23718
commit
ddb7eb6ee1
|
@ -20,6 +20,8 @@ class ArticleRenderer {
|
|||
|
||||
let article: Article
|
||||
let articleStyle: ArticleStyle
|
||||
let appearance: NSAppearance?
|
||||
|
||||
static var faviconImgTagCache = [Feed: String]()
|
||||
static var feedIconImgTagCache = [Feed: String]()
|
||||
|
||||
|
@ -87,10 +89,12 @@ class ArticleRenderer {
|
|||
return renderedHTML()
|
||||
}
|
||||
|
||||
init(article: Article, style: ArticleStyle) {
|
||||
init(article: Article, style: ArticleStyle, appearance: NSAppearance? = nil) {
|
||||
|
||||
self.article = article
|
||||
self.articleStyle = style
|
||||
self.appearance = appearance
|
||||
|
||||
}
|
||||
|
||||
// MARK: Private
|
||||
|
@ -473,8 +477,8 @@ class ArticleRenderer {
|
|||
|
||||
"""
|
||||
|
||||
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: "]]")
|
||||
|
||||
|
|
|
@ -195,7 +195,9 @@ private extension DetailViewController {
|
|||
func reloadHTML() {
|
||||
|
||||
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)
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -30,6 +30,12 @@ final class DetailWebView: WKWebView {
|
|||
|
||||
super.willOpenMenu(menu, with: event)
|
||||
}
|
||||
|
||||
override func viewDidChangeEffectiveAppearance() {
|
||||
let bodyClass = effectiveAppearance.isDarkMode ? "dark" : "light"
|
||||
evaluateJavaScript("document.getElementById('bodyId').className = '\(bodyClass)'")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private extension NSUserInterfaceItemIdentifier {
|
||||
|
|
Loading…
Reference in New Issue