Create handleUnreadCountDidChange as shared AppDelegate code.

This commit is contained in:
Brent Simmons 2024-07-02 21:43:52 -07:00
parent 79c2f4c7f5
commit 09cadf7f52
3 changed files with 20 additions and 6 deletions

View File

@ -56,6 +56,8 @@ import Sparkle
var isShutDownSyncDone = false
private static let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "AppDelegate")
@IBOutlet var debugMenuItem: NSMenuItem!
@IBOutlet var sortByOldestArticleOnTopMenuItem: NSMenuItem!
@IBOutlet var sortByNewestArticleOnTopMenuItem: NSMenuItem!
@ -65,9 +67,7 @@ import Sparkle
var unreadCount = 0 {
didSet {
if unreadCount != oldValue {
queueUpdateDockBadge()
AppNotification.postAppUnreadCountDidChange(from: self, unreadCount: unreadCount)
postUnreadCountDidChangeNotification()
handleUnreadCountDidChange()
}
}
}

View File

@ -26,4 +26,20 @@ extension AppDelegate: FaviconDownloaderDelegate, FeedIconDownloaderDelegate {
FaviconDownloader.shared.delegate = self
FeedIconDownloader.shared.delegate = self
}
func handleUnreadCountDidChange() {
AppNotification.postAppUnreadCountDidChange(from: self, unreadCount: unreadCount)
postUnreadCountDidChangeNotification()
updateBadge()
}
func updateBadge() {
#if os(macOS)
queueUpdateDockBadge()
#elseif os(iOS)
UNUserNotificationCenter.current().setBadgeCount(unreadCount)
#endif
}
}

View File

@ -46,9 +46,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
var unreadCount = 0 {
didSet {
if unreadCount != oldValue {
AppNotification.postAppUnreadCountDidChange(from: self, unreadCount: unreadCount)
postUnreadCountDidChangeNotification()
UNUserNotificationCenter.current().setBadgeCount(unreadCount)
handleUnreadCountDidChange()
}
}
}