diff --git a/Core/Sources/Core/DataFile.swift b/Core/Sources/Core/DataFile.swift index 8913b3869..144cbb2b4 100644 --- a/Core/Sources/Core/DataFile.swift +++ b/Core/Sources/Core/DataFile.swift @@ -32,7 +32,7 @@ public protocol DataFileDelegate: AnyObject { private let fileURL: URL private lazy var postponingBlock: PostponingBlock = { - PostponingBlock(delayInterval: 1.0, name: "DataFile \(fileURL.absoluteString)") { [weak self] in + PostponingBlock(name: "DataFile \(fileURL.absoluteString)", delayInterval: 1.0) { [weak self] in self?.saveToDiskIfNeeded() } }() diff --git a/Core/Sources/Core/PostponingBlock.swift b/Core/Sources/Core/PostponingBlock.swift index ba5a4483a..428be788c 100644 --- a/Core/Sources/Core/PostponingBlock.swift +++ b/Core/Sources/Core/PostponingBlock.swift @@ -11,6 +11,8 @@ import os /// Runs a block of code in the future. Each time `runInFuture` is called, the block is postponed again until the future by `delayInterval`. @MainActor public final class PostponingBlock { + public static let delayIntervalForUI: TimeInterval = 0.05 + private let block: @MainActor () -> Void private let delayInterval: TimeInterval private let name: String // For debugging @@ -18,7 +20,7 @@ import os private let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "PostponingBlock") - public init(delayInterval: TimeInterval, name: String, block: @MainActor @escaping () -> Void) { + public init(name: String, delayInterval: TimeInterval = PostponingBlock.delayIntervalForUI, block: @MainActor @escaping () -> Void) { self.delayInterval = delayInterval self.name = name diff --git a/Mac/AppDelegate.swift b/Mac/AppDelegate.swift index 19e2c101e..3bac0fd43 100644 --- a/Mac/AppDelegate.swift +++ b/Mac/AppDelegate.swift @@ -71,7 +71,7 @@ import Sparkle @IBOutlet var checkForUpdatesMenuItem: NSMenuItem! private lazy var postponingUpdateDockBadgeBlock: PostponingBlock = { - PostponingBlock(delayInterval: 0.05, name: "Update Dock Badge", block: updateDockBadge) + PostponingBlock(name: "Update Dock Badge", delayInterval: 0.05, block: updateDockBadge) }() var unreadCount = 0 { diff --git a/Mac/MainWindow/MainWindowController.swift b/Mac/MainWindow/MainWindowController.swift index 09551a2b0..c42b4cc3a 100644 --- a/Mac/MainWindow/MainWindowController.swift +++ b/Mac/MainWindow/MainWindowController.swift @@ -60,6 +60,10 @@ final class MainWindowController : NSWindowController, NSUserInterfaceValidation private var searchSmartFeed: SmartFeed? = nil private var restoreArticleWindowScrollY: CGFloat? + private lazy var postponingMakeToolbarValidateBlock: PostponingBlock = { + PostponingBlock(name: "Make Toolbar Validate", delayInterval: 0.05, block: makeToolbarValidate) + }() + // MARK: - NSWindowController override func windowDidLoad() { @@ -147,7 +151,7 @@ final class MainWindowController : NSWindowController, NSUserInterfaceValidation // MARK: - Notifications @objc func refreshProgressDidChange(_ note: Notification) { - CoalescingQueue.standard.add(self, #selector(makeToolbarValidate)) + queueMakeToolbarValidate() } @objc func unreadCountDidChange(_ note: Notification) { @@ -195,7 +199,12 @@ final class MainWindowController : NSWindowController, NSUserInterfaceValidation // MARK: - Toolbar - @objc func makeToolbarValidate() { + func queueMakeToolbarValidate() { + + postponingMakeToolbarValidateBlock.runInFuture() + } + + func makeToolbarValidate() { window?.toolbar?.validateVisibleItems() } diff --git a/Shared/SmartFeeds/SmartFeed.swift b/Shared/SmartFeeds/SmartFeed.swift index 3c0785352..509efecb6 100644 --- a/Shared/SmartFeeds/SmartFeed.swift +++ b/Shared/SmartFeeds/SmartFeed.swift @@ -49,7 +49,7 @@ import Images #endif private lazy var postponingBlock: PostponingBlock = { - PostponingBlock(delayInterval: 1.0, name: "SmartFeed") { + PostponingBlock(name: "SmartFeed", delayInterval: 1.0) { Task { try? await self.fetchUnreadCounts() }