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

View File

@ -26,4 +26,20 @@ extension AppDelegate: FaviconDownloaderDelegate, FeedIconDownloaderDelegate {
FaviconDownloader.shared.delegate = self FaviconDownloader.shared.delegate = self
FeedIconDownloader.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 { var unreadCount = 0 {
didSet { didSet {
if unreadCount != oldValue { if unreadCount != oldValue {
AppNotification.postAppUnreadCountDidChange(from: self, unreadCount: unreadCount) handleUnreadCountDidChange()
postUnreadCountDidChangeNotification()
UNUserNotificationCenter.current().setBadgeCount(unreadCount)
} }
} }
} }