From 09cadf7f522005dd45a579ef88260075dc19494f Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Tue, 2 Jul 2024 21:43:52 -0700 Subject: [PATCH] Create handleUnreadCountDidChange as shared AppDelegate code. --- Mac/AppDelegate.swift | 6 +++--- Shared/AppDelegate+Shared.swift | 16 ++++++++++++++++ iOS/AppDelegate.swift | 4 +--- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Mac/AppDelegate.swift b/Mac/AppDelegate.swift index a85e15235..214ec5dc0 100644 --- a/Mac/AppDelegate.swift +++ b/Mac/AppDelegate.swift @@ -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() } } } diff --git a/Shared/AppDelegate+Shared.swift b/Shared/AppDelegate+Shared.swift index 8a059fb9a..b309bc654 100644 --- a/Shared/AppDelegate+Shared.swift +++ b/Shared/AppDelegate+Shared.swift @@ -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 + } } diff --git a/iOS/AppDelegate.swift b/iOS/AppDelegate.swift index 5da52842f..f6f2c37cd 100644 --- a/iOS/AppDelegate.swift +++ b/iOS/AppDelegate.swift @@ -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() } } }