Add last-refresh time to status bar and make it default.

This commit is contained in:
Brent Simmons committed 2026-10-20 12:00:12 -07:00
1 parent 86101e444b
commit e4eefa31df
2 files changed
+47 -11

No files matched your search

+9 -4
View File
@@ -15,17 +15,21 @@ enum FontSize: Int {
case veryLarge = 3 case veryLarge = 3
} }
/// What the status bar’s count text shows. Clicking the text switches between them. /// What the status bar’s count text shows. Clicking the text cycles through them.
enum StatusBarCountMode: Int { enum StatusBarCountMode: Int {
case unreadCount = 0 case unreadCount = 0
case foldersAndFeeds = 1 case foldersAndFeeds = 1
case lastRefresh = 2
var toggled: StatusBarCountMode { /// The mode after this one when clicking. Skips the unread count when unread counts are hidden.
func next(includingUnreadCount: Bool) -> StatusBarCountMode {
switch self { switch self {
case .lastRefresh:
includingUnreadCount ? .unreadCount : .foldersAndFeeds
case .unreadCount: case .unreadCount:
.foldersAndFeeds .foldersAndFeeds
case .foldersAndFeeds: case .foldersAndFeeds:
.unreadCount .lastRefresh
} }
} }
} }
@@ -336,7 +340,7 @@ final class AppDefaults: Sendable {
var statusBarCountMode: StatusBarCountMode { var statusBarCountMode: StatusBarCountMode {
get { get {
StatusBarCountMode(rawValue: AppDefaults.int(for: Key.statusBarCountMode)) ?? .unreadCount StatusBarCountMode(rawValue: AppDefaults.int(for: Key.statusBarCountMode)) ?? .lastRefresh
} }
set { set {
AppDefaults.setInt(for: Key.statusBarCountMode, newValue.rawValue) AppDefaults.setInt(for: Key.statusBarCountMode, newValue.rawValue)
@@ -403,6 +407,7 @@ final class AppDefaults: Sendable {
Key.useColumnLayout: false, Key.useColumnLayout: false,
Key.showStatusBar: Self.showStatusBarDefault, Key.showStatusBar: Self.showStatusBarDefault,
Key.showStatusBarThemeMenu: true, Key.showStatusBarThemeMenu: true,
Key.statusBarCountMode: StatusBarCountMode.lastRefresh.rawValue,
"NSScrollViewShouldScrollUnderTitlebar": false, "NSScrollViewShouldScrollUnderTitlebar": false,
Key.refreshInterval: RefreshInterval.every2Hours.rawValue, Key.refreshInterval: RefreshInterval.every2Hours.rawValue,
Key.showDebugMenu: showDebugMenu, Key.showDebugMenu: showDebugMenu,
@@ -214,6 +214,19 @@ final class MainWindowStatusBarView: NSView {
CoalescingQueue.standard.add(self, #selector(updateCountLabel)) CoalescingQueue.standard.add(self, #selector(updateCountLabel))
} }
// The last refresh time shows the date only when it’s not today, so it changes at midnight.
@objc func handleCalendarDayChanged(_ notification: Notification) {
updateCountLabel()
}
@objc func handleCurrentLocaleDidChange(_ notification: Notification) {
updateCountLabel()
}
@objc func handleSystemTimeZoneDidChange(_ notification: Notification) {
updateCountLabel()
}
@objc func handleArticleThemeNamesDidChange(_ notification: Notification) { @objc func handleArticleThemeNamesDidChange(_ notification: Notification) {
updateThemePopUpButton() updateThemePopUpButton()
} }
@@ -239,11 +252,7 @@ final class MainWindowStatusBarView: NSView {
} }
@objc func toggleCountMode(_ sender: Any?) { @objc func toggleCountMode(_ sender: Any?) {
// With unread counts hidden, the folders and feeds count is the only mode. AppDefaults.shared.statusBarCountMode = effectiveCountMode.next(includingUnreadCount: Self.showsUnreadCounts)
guard Self.showsUnreadCounts else {
return
}
AppDefaults.shared.statusBarCountMode = AppDefaults.shared.statusBarCountMode.toggled
} }
} }
@@ -344,6 +353,9 @@ private extension MainWindowStatusBarView {
NotificationCenter.default.addObserver(self, selector: #selector(handleAccountChildrenDidChange(_:)), name: .UserDidDeleteAccount, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(handleAccountChildrenDidChange(_:)), name: .UserDidDeleteAccount, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(handleAccountChildrenDidChange(_:)), name: .AccountStateDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(handleAccountChildrenDidChange(_:)), name: .AccountStateDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(handleProgressInfoDidChange(_:)), name: .progressInfoDidChange, object: CombinedRefreshProgress.shared) NotificationCenter.default.addObserver(self, selector: #selector(handleProgressInfoDidChange(_:)), name: .progressInfoDidChange, object: CombinedRefreshProgress.shared)
NotificationCenter.default.addObserver(self, selector: #selector(handleCalendarDayChanged(_:)), name: .NSCalendarDayChanged, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(handleCurrentLocaleDidChange(_:)), name: NSLocale.currentLocaleDidChangeNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(handleSystemTimeZoneDidChange(_:)), name: .NSSystemTimeZoneDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(handleArticleThemeNamesDidChange(_:)), name: .ArticleThemeNamesDidChangeNotification, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(handleArticleThemeNamesDidChange(_:)), name: .ArticleThemeNamesDidChangeNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(handleCurrentArticleThemeDidChange(_:)), name: .CurrentArticleThemeDidChangeNotification, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(handleCurrentArticleThemeDidChange(_:)), name: .CurrentArticleThemeDidChangeNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(handleUserDefaultsDidChange(_:)), name: UserDefaults.didChangeNotification, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(handleUserDefaultsDidChange(_:)), name: UserDefaults.didChangeNotification, object: nil)
@@ -409,13 +421,24 @@ private extension MainWindowStatusBarView {
AppDefaults.shared.unreadCountDisplay == .count AppDefaults.shared.unreadCountDisplay == .count
} }
/// The saved mode, except that hidden unread counts (hidden or a dot) mean folders and feeds. /// The saved mode, except that the unread count becomes the last refresh time when unread counts are hidden (hidden or a dot).
var effectiveCountMode: StatusBarCountMode { var effectiveCountMode: StatusBarCountMode {
Self.showsUnreadCounts ? AppDefaults.shared.statusBarCountMode : .foldersAndFeeds let mode = AppDefaults.shared.statusBarCountMode
if mode == .unreadCount && !Self.showsUnreadCounts {
return .lastRefresh
}
return mode
} }
func countText() -> String { func countText() -> String {
switch effectiveCountMode { switch effectiveCountMode {
case .lastRefresh:
guard let lastRefreshDate = AccountManager.shared.lastRefreshCompletedDate else {
return NSLocalizedString("Not updated yet", comment: "Status bar: no refresh has completed yet")
}
let formatString = NSLocalizedString("Updated %@", comment: "Updated")
return String(format: formatString, Self.lastRefreshDateString(lastRefreshDate))
case .unreadCount: case .unreadCount:
let formatString = NSLocalizedString("%d unread", comment: "Unread") let formatString = NSLocalizedString("%d unread", comment: "Unread")
return String.localizedStringWithFormat(formatString, AccountManager.shared.unreadCount) return String.localizedStringWithFormat(formatString, AccountManager.shared.unreadCount)
@@ -429,6 +452,14 @@ private extension MainWindowStatusBarView {
} }
} }
/// Just the time when it’s today, otherwise the date and time — in the user’s locale.
static func lastRefreshDateString(_ date: Date) -> String {
if Calendar.current.isDateInToday(date) {
return date.formatted(date: .omitted, time: .shortened)
}
return date.formatted(date: .abbreviated, time: .shortened)
}
// MARK: - Link // MARK: - Link
/// The link’s contextual menu. Copy copies the whole link, with its scheme. /// The link’s contextual menu. Copy copies the whole link, with its scheme.