Use high resolution Feed icons in the Sidebar #2320

This commit is contained in:
Maurice Parker 2020-08-07 19:44:12 -05:00
parent 69fb9421a6
commit 314d425c49
2 changed files with 16 additions and 16 deletions

View File

@ -13,15 +13,13 @@ import RSTree
class SidebarCell : NSTableCellView { class SidebarCell : NSTableCellView {
var image: NSImage? { var iconImage: IconImage? {
didSet { didSet {
if let image = image { if let image = iconImage {
faviconImageView.image = shouldShowImage ? image : nil faviconImageView.iconImage = shouldShowImage ? image : nil
faviconImageView.alphaValue = image.isTemplate ? 0.75 : 1.0
} }
else { else {
faviconImageView.image = nil faviconImageView.iconImage = nil
faviconImageView.alphaValue = 1.0
} }
} }
} }
@ -31,7 +29,7 @@ class SidebarCell : NSTableCellView {
if shouldShowImage != oldValue { if shouldShowImage != oldValue {
needsLayout = true needsLayout = true
} }
faviconImageView.image = shouldShowImage ? image : nil faviconImageView.iconImage = shouldShowImage ? iconImage : nil
} }
} }
@ -80,14 +78,7 @@ class SidebarCell : NSTableCellView {
return textField return textField
}() }()
private let faviconImageView: NSImageView = { private let faviconImageView = IconView()
let imageView = NSImageView(frame: NSRect.zero)
imageView.animates = false
imageView.imageAlignment = .alignCenter
imageView.imageScaling = .scaleProportionallyDown
imageView.wantsLayer = true
return imageView
}()
private let unreadCountView = UnreadCountView(frame: NSZeroRect) private let unreadCountView = UnreadCountView(frame: NSZeroRect)

View File

@ -73,6 +73,7 @@ protocol SidebarDelegate: class {
NotificationCenter.default.addObserver(self, selector: #selector(userDidAddFeed(_:)), name: .UserDidAddFeed, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(userDidAddFeed(_:)), name: .UserDidAddFeed, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(batchUpdateDidPerform(_:)), name: .BatchUpdateDidPerform, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(batchUpdateDidPerform(_:)), name: .BatchUpdateDidPerform, 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(webFeedIconDidBecomeAvailable(_:)), name: .WebFeedIconDidBecomeAvailable, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(webFeedSettingDidChange(_:)), name: .WebFeedSettingDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(webFeedSettingDidChange(_:)), name: .WebFeedSettingDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(displayNameDidChange(_:)), name: .DisplayNameDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(displayNameDidChange(_:)), name: .DisplayNameDidChange, object: nil)
@ -191,6 +192,11 @@ protocol SidebarDelegate: class {
applyToAvailableCells(configureFavicon) applyToAvailableCells(configureFavicon)
} }
@objc func webFeedIconDidBecomeAvailable(_ note: Notification) {
guard let webFeed = note.userInfo?[UserInfoKey.webFeed] as? WebFeed else { return }
configureCellsForRepresentedObject(webFeed)
}
@objc func webFeedSettingDidChange(_ note: Notification) { @objc func webFeedSettingDidChange(_ note: Notification) {
guard let webFeed = note.object as? WebFeed, let key = note.userInfo?[WebFeed.WebFeedSettingUserInfoKey] as? String else { guard let webFeed = note.object as? WebFeed, let key = note.userInfo?[WebFeed.WebFeedSettingUserInfoKey] as? String else {
return return
@ -733,7 +739,7 @@ private extension SidebarViewController {
} }
func configureFavicon(_ cell: SidebarCell, _ node: Node) { func configureFavicon(_ cell: SidebarCell, _ node: Node) {
cell.image = imageFor(node)?.image cell.iconImage = imageFor(node)
} }
func configureGroupCell(_ cell: NSTableCellView, _ node: Node) { func configureGroupCell(_ cell: NSTableCellView, _ node: Node) {
@ -741,6 +747,9 @@ private extension SidebarViewController {
} }
func imageFor(_ node: Node) -> IconImage? { func imageFor(_ node: Node) -> IconImage? {
if let feed = node.representedObject as? WebFeed, let feedIcon = appDelegate.webFeedIconDownloader.icon(for: feed) {
return feedIcon
}
if let smallIconProvider = node.representedObject as? SmallIconProvider { if let smallIconProvider = node.representedObject as? SmallIconProvider {
return smallIconProvider.smallIcon return smallIconProvider.smallIcon
} }