From 57399838dc8a20ad6274d6f56a30c42f8ffe2da0 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Wed, 12 Jun 2024 17:40:16 -0700 Subject: [PATCH] Add queueUpdateDockBadge. Use PostponingBlock instead of CoalescingQueue. --- Mac/AppDelegate.swift | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Mac/AppDelegate.swift b/Mac/AppDelegate.swift index ef846e6ed..19e2c101e 100644 --- a/Mac/AppDelegate.swift +++ b/Mac/AppDelegate.swift @@ -70,10 +70,14 @@ import Sparkle @IBOutlet var groupArticlesByFeedMenuItem: NSMenuItem! @IBOutlet var checkForUpdatesMenuItem: NSMenuItem! + private lazy var postponingUpdateDockBadgeBlock: PostponingBlock = { + PostponingBlock(delayInterval: 0.05, name: "Update Dock Badge", block: updateDockBadge) + }() + var unreadCount = 0 { didSet { if unreadCount != oldValue { - CoalescingQueue.standard.add(self, #selector(updateDockBadge)) + queueUpdateDockBadge() NotificationCenter.default.post(name: .appUnreadCountDidChange, object: self, userInfo: nil) postUnreadCountDidChangeNotification() } @@ -401,7 +405,7 @@ import Sparkle lastRefreshInterval = AppDefaults.shared.refreshInterval } - updateDockBadge() + queueUpdateDockBadge() } @objc func didWakeNotification(_ note: Notification) { @@ -536,7 +540,12 @@ import Sparkle } // MARK: - Dock Badge - @objc func updateDockBadge() { + + func queueUpdateDockBadge() { + postponingUpdateDockBadgeBlock.runInFuture() + } + + func updateDockBadge() { let label = unreadCount > 0 ? "\(unreadCount)" : "" NSApplication.shared.dockTile.badgeLabel = label }