From 128b727f4264bbdc7b8d7a1500bf4c0d70ddbd78 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sat, 7 Nov 2026 15:44:20 -0800 Subject: [PATCH] Add setting to fade read articles in timeline on Mac. --- .../Timeline/TimelineViewController.swift | 47 +++++++++++- .../AppearancePreferencesViewController.swift | 15 ++++ .../Base.lproj/AppearancePreferencesView.xib | 76 +++++++++++-------- .../AppearancePreferencesView.xcstrings | 12 +++ Shared/AppDefaults.swift | 14 +++- Shared/AppNotifications.swift | 1 + 6 files changed, 131 insertions(+), 34 deletions(-) diff --git a/Mac/MainWindow/Timeline/TimelineViewController.swift b/Mac/MainWindow/Timeline/TimelineViewController.swift index 330de5633..7b1898ba5 100644 --- a/Mac/MainWindow/Timeline/TimelineViewController.swift +++ b/Mac/MainWindow/Timeline/TimelineViewController.swift @@ -263,6 +263,14 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr } } } + private var fadesReadArticles = AppDefaults.timelineFadeReadArticles { + didSet { + if fadesReadArticles != oldValue { + reloadVisibleCells() + } + } + } + private static let readArticleAlphaValue: CGFloat = 0.6 private struct ArticleIdentityKey: Equatable { let accountID: String @@ -296,6 +304,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr textSize = AppDefaults.timelineTextSize numberOfLines = AppDefaults.timelineNumberOfLines showFullTitles = AppDefaults.timelineShowFullTitles + fadesReadArticles = AppDefaults.timelineFadeReadArticles updateGridStyle() thumbnailsDisplay = AppDefaults.timelineThumbnailsDisplay updateCellAppearances() @@ -334,6 +343,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr NotificationCenter.default.addObserver(self, selector: #selector(handleTimelineTextSizeDidChange(_:)), name: .timelineTextSizeDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(handleTimelineNumberOfLinesDidChange(_:)), name: .timelineNumberOfLinesDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(handleTimelineShowFullTitlesDidChange(_:)), name: .timelineShowFullTitlesDidChange, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(handleTimelineFadeReadArticlesDidChange(_:)), name: .timelineFadeReadArticlesDidChange, object: nil) didRegisterForNotifications = true } @@ -845,6 +855,10 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr showFullTitles = AppDefaults.timelineShowFullTitles } + @objc func handleTimelineFadeReadArticlesDidChange(_ notification: Notification) { + fadesReadArticles = AppDefaults.timelineFadeReadArticles + } + @objc func handleTimelineIconSizeDidChange(_ notification: Notification) { updateCellAppearances() rowHeights.removeAll() @@ -1296,10 +1310,14 @@ extension TimelineViewController: NSTableViewDelegate { private static let timelineCellIdentifier = NSUserInterfaceItemIdentifier(rawValue: "timelineCell") func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? { - if layout == .column { - return columnCellView(for: tableColumn, row: row) + let cellView = layout == .column ? columnCellView(for: tableColumn, row: row) : standardCellView(for: row) + if let cellView { + applyReadFading(to: cellView, row: row) } + return cellView + } + private func standardCellView(for row: Int) -> NSView { func configure(_ cell: TimelineTableCellView) { cell.cellAppearance = showIcons ? cellAppearanceWithIcon : cellAppearance if let article = articles.articleAtRow(row) { @@ -1325,6 +1343,8 @@ extension TimelineViewController: NSTableViewDelegate { } func tableViewSelectionDidChange(_ notification: Notification) { + applyReadFadingToAvailableRows() + if selectedArticles.isEmpty { selectionDidChange(nil) return @@ -1365,6 +1385,29 @@ extension TimelineViewController: NSTableViewDelegate { cell.cellData = TimelineCellData(article: article, showFeedName: showFeedNames, feedName: article.feed?.nameForDisplay, byline: article.byline(), iconImage: iconImage, showIcon: showIcons, thumbnail: thumbnail, showThumbnail: showThumbnail) } + /// Fades the cell views, not the row view, so the selection highlight and separators stay full strength. + /// The selected row never fades, since selecting an article marks it read. + private func applyReadFading(to cellView: NSView, row: Int) { + var alphaValue: CGFloat = 1.0 + if fadesReadArticles, let article = articles.articleAtRow(row), article.status.read, !tableView.isRowSelected(row) { + alphaValue = Self.readArticleAlphaValue + } + if cellView.alphaValue != alphaValue { + cellView.alphaValue = alphaValue + } + } + + /// Selection changes don’t reload cells. + private func applyReadFadingToAvailableRows() { + tableView.enumerateAvailableRowViews { rowView, row in + for column in 0.. + @@ -30,14 +31,14 @@ - + - + - + @@ -45,7 +46,7 @@ - + @@ -66,10 +67,10 @@ - + - + @@ -77,7 +78,7 @@ - + @@ -95,7 +96,7 @@ - + @@ -119,7 +120,7 @@ - + @@ -127,7 +128,7 @@ - + - + @@ -168,7 +169,7 @@ - + @@ -185,7 +186,7 @@ - + @@ -193,7 +194,7 @@ - + @@ -201,7 +202,7 @@ - + @@ -218,7 +219,7 @@ - + @@ -226,7 +227,7 @@ - + @@ -244,7 +245,7 @@ - + @@ -252,7 +253,7 @@ - + @@ -274,7 +275,7 @@ - + @@ -282,7 +283,7 @@ - + @@ -302,7 +303,7 @@ - + @@ -320,7 +321,7 @@ - + @@ -338,7 +339,7 @@ + @@ -514,7 +525,10 @@ - + + + + diff --git a/Mac/Preferences/Appearance/mul.lproj/AppearancePreferencesView.xcstrings b/Mac/Preferences/Appearance/mul.lproj/AppearancePreferencesView.xcstrings index 4a9dbec37..88710683f 100644 --- a/Mac/Preferences/Appearance/mul.lproj/AppearancePreferencesView.xcstrings +++ b/Mac/Preferences/Appearance/mul.lproj/AppearancePreferencesView.xcstrings @@ -325,6 +325,18 @@ } } }, + "tlB-fR-0c1.title" : { + "comment" : "Class = \"NSButtonCell\"; title = \"Fade read articles\"; ObjectID = \"tlB-fR-0c1\";", + "extractionState" : "extracted_with_value", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "new", + "value" : "Fade read articles" + } + } + } + }, "tlB-sP-0c1.title" : { "comment" : "Class = \"NSButtonCell\"; title = \"Show separators\"; ObjectID = \"tlB-sP-0c1\";", "extractionState" : "extracted_with_value", diff --git a/Shared/AppDefaults.swift b/Shared/AppDefaults.swift index 2b079211b..72fdefeaa 100644 --- a/Shared/AppDefaults.swift +++ b/Shared/AppDefaults.swift @@ -35,6 +35,7 @@ enum AppDefaults { static let timelineTextSize = "timelineTextSize" static let timelineNumberOfLines = "timelineNumberOfLines" static let timelineShowFullTitles = "timelineShowFullTitles" + static let timelineFadeReadArticles = "timelineFadeReadArticles" } /// Registered by both platforms. Each platform’s registerDefaults adds its own. @@ -53,7 +54,8 @@ enum AppDefaults { Key.showUnreadFeed: true, Key.showStarredFeed: true, Key.timelineTextSize: TimelineTextSize.medium.rawValue, - Key.timelineShowFullTitles: false + Key.timelineShowFullTitles: false, + Key.timelineFadeReadArticles: false ] } @@ -249,6 +251,16 @@ enum AppDefaults { NotificationCenter.default.post(name: .timelineShowFullTitlesDidChange, object: nil) } } + + static var timelineFadeReadArticles: Bool { + get { + UserDefaults.standard.bool(forKey: Key.timelineFadeReadArticles) + } + set { + UserDefaults.standard.set(newValue, forKey: Key.timelineFadeReadArticles) + NotificationCenter.default.post(name: .timelineFadeReadArticlesDidChange, object: nil) + } + } } // MARK: - Helpers diff --git a/Shared/AppNotifications.swift b/Shared/AppNotifications.swift index 220e630ac..eb6a5f022 100644 --- a/Shared/AppNotifications.swift +++ b/Shared/AppNotifications.swift @@ -18,4 +18,5 @@ extension Notification.Name { static let timelineIconSizeDidChange = Notification.Name("TimelineIconSizeDidChangeNotification") static let timelineNumberOfLinesDidChange = Notification.Name("TimelineNumberOfLinesDidChangeNotification") static let timelineShowFullTitlesDidChange = Notification.Name("TimelineShowFullTitlesDidChangeNotification") + static let timelineFadeReadArticlesDidChange = Notification.Name("TimelineFadeReadArticlesDidChangeNotification") }