Darken and lighten the accent color for the article view.

This commit is contained in:
Maurice Parker 2020-03-20 08:13:39 -05:00
parent 1e1fce59da
commit 6a384d99e6
2 changed files with 36 additions and 3 deletions

View File

@ -12,6 +12,11 @@ import RSCore
import RSWeb
import Articles
extension Notification.Name {
static let appleColorPreferencesChangedNotification = Notification.Name("AppleColorPreferencesChangedNotification")
static let appleInterfaceThemeChangedNotification = Notification.Name("AppleInterfaceThemeChangedNotification")
}
protocol DetailWebViewControllerDelegate: class {
func mouseDidEnter(_: DetailWebViewController, link: String)
func mouseDidExit(_: DetailWebViewController, link: String)
@ -118,6 +123,10 @@ final class DetailWebViewController: NSViewController, WKUIDelegate {
NotificationCenter.default.addObserver(self, selector: #selector(webFeedIconDidBecomeAvailable(_:)), name: .WebFeedIconDidBecomeAvailable, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(avatarDidBecomeAvailable(_:)), name: .AvatarDidBecomeAvailable, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(faviconDidBecomeAvailable(_:)), name: .FaviconDidBecomeAvailable, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(faviconDidBecomeAvailable(_:)), name: .FaviconDidBecomeAvailable, object: nil)
DistributedNotificationCenter.default().addObserver(self, selector: #selector(appleColorPreferencesChanged(_:)), name: .appleColorPreferencesChangedNotification, object: nil)
DistributedNotificationCenter.default().addObserver(self, selector: #selector(appleInterfaceThemeChanged(_:)), name: .appleInterfaceThemeChangedNotification, object: nil)
webView.loadFileURL(ArticleRenderer.blank.url, allowingReadAccessTo: ArticleRenderer.blank.baseURL)
}
@ -136,6 +145,14 @@ final class DetailWebViewController: NSViewController, WKUIDelegate {
reloadArticleImage()
}
@objc func appleColorPreferencesChanged(_ note: Notification) {
reloadHTML()
}
@objc func appleInterfaceThemeChanged(_ note: Notification) {
reloadHTML()
}
// MARK: Media Functions
func stopMediaPlayback() {

View File

@ -261,9 +261,25 @@ private extension ArticleRenderer {
guard let linkColor = NSColor.controlAccentColor.usingColorSpace(.deviceRGB) else {
return d
}
let red = Int(round(linkColor.redComponent * 0xFF))
let green = Int(round(linkColor.greenComponent * 0xFF))
let blue = Int(round(linkColor.blueComponent * 0xFF))
let red: Int
let green: Int
let blue: Int
if NSApplication.shared.effectiveAppearance.isDarkMode {
let brighten = CGFloat(0.25)
let baseRed = linkColor.redComponent * 0xFF
red = Int(round(((255 - baseRed) * brighten)) + round(baseRed))
let baseGreen = linkColor.greenComponent * 0xFF
green = Int(round(((255 - baseGreen) * brighten)) + round(baseGreen))
let baseBlue = linkColor.blueComponent * 0xFF
blue = Int(round(((255 - baseBlue) * brighten)) + round(baseBlue))
} else {
let darken = CGFloat(0.75)
red = Int(round(linkColor.redComponent * 0xFF * darken))
green = Int(round(linkColor.greenComponent * 0xFF * darken))
blue = Int(round(linkColor.blueComponent * 0xFF * darken))
}
d["accent-r"] = String(red)
d["accent-g"] = String(green)