Darken and lighten the accent color for the article view.
This commit is contained in:
parent
1e1fce59da
commit
6a384d99e6
|
@ -12,6 +12,11 @@ import RSCore
|
||||||
import RSWeb
|
import RSWeb
|
||||||
import Articles
|
import Articles
|
||||||
|
|
||||||
|
extension Notification.Name {
|
||||||
|
static let appleColorPreferencesChangedNotification = Notification.Name("AppleColorPreferencesChangedNotification")
|
||||||
|
static let appleInterfaceThemeChangedNotification = Notification.Name("AppleInterfaceThemeChangedNotification")
|
||||||
|
}
|
||||||
|
|
||||||
protocol DetailWebViewControllerDelegate: class {
|
protocol DetailWebViewControllerDelegate: class {
|
||||||
func mouseDidEnter(_: DetailWebViewController, link: String)
|
func mouseDidEnter(_: DetailWebViewController, link: String)
|
||||||
func mouseDidExit(_: 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(webFeedIconDidBecomeAvailable(_:)), name: .WebFeedIconDidBecomeAvailable, object: nil)
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(avatarDidBecomeAvailable(_:)), name: .AvatarDidBecomeAvailable, 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)
|
||||||
|
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)
|
webView.loadFileURL(ArticleRenderer.blank.url, allowingReadAccessTo: ArticleRenderer.blank.baseURL)
|
||||||
}
|
}
|
||||||
|
@ -136,6 +145,14 @@ final class DetailWebViewController: NSViewController, WKUIDelegate {
|
||||||
reloadArticleImage()
|
reloadArticleImage()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc func appleColorPreferencesChanged(_ note: Notification) {
|
||||||
|
reloadHTML()
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc func appleInterfaceThemeChanged(_ note: Notification) {
|
||||||
|
reloadHTML()
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Media Functions
|
// MARK: Media Functions
|
||||||
|
|
||||||
func stopMediaPlayback() {
|
func stopMediaPlayback() {
|
||||||
|
|
|
@ -261,9 +261,25 @@ private extension ArticleRenderer {
|
||||||
guard let linkColor = NSColor.controlAccentColor.usingColorSpace(.deviceRGB) else {
|
guard let linkColor = NSColor.controlAccentColor.usingColorSpace(.deviceRGB) else {
|
||||||
return d
|
return d
|
||||||
}
|
}
|
||||||
let red = Int(round(linkColor.redComponent * 0xFF))
|
|
||||||
let green = Int(round(linkColor.greenComponent * 0xFF))
|
let red: Int
|
||||||
let blue = Int(round(linkColor.blueComponent * 0xFF))
|
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-r"] = String(red)
|
||||||
d["accent-g"] = String(green)
|
d["accent-g"] = String(green)
|
||||||
|
|
Loading…
Reference in New Issue