diff --git a/Evergreen/AppDelegate.swift b/Evergreen/AppDelegate.swift index 530a193e5..40e8587b1 100644 --- a/Evergreen/AppDelegate.swift +++ b/Evergreen/AppDelegate.swift @@ -43,6 +43,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations { NSWindow.allowsAutomaticWindowTabbing = false super.init() dockBadge.appDelegate = self + + NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil) } // MARK: - NSApplicationDelegate @@ -64,6 +66,10 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations { #endif NSAppleEventManager.shared().setEventHandler(self, andSelector: #selector(AppDelegate.getURL(_:_:)), forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL)) + + DispatchQueue.main.async { + self.unreadCount = AccountManager.shared.unreadCount + } } func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool { @@ -103,9 +109,11 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations { // MARK: Notifications - func unreadCountDidChange(_ note: Notification) { + @objc func unreadCountDidChange(_ note: Notification) { - unreadCount = AccountManager.shared.unreadCount + if note.object is AccountManager { + unreadCount = AccountManager.shared.unreadCount + } } // MARK: Main Window diff --git a/Frameworks/Account/Account.swift b/Frameworks/Account/Account.swift index 535ed5f0d..ffb5a4b45 100644 --- a/Frameworks/Account/Account.swift +++ b/Frameworks/Account/Account.swift @@ -138,6 +138,10 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil) pullObjectsFromDisk() + + DispatchQueue.main.async { + self.updateUnreadCount() + } } // MARK: - API diff --git a/Frameworks/Account/AccountManager.swift b/Frameworks/Account/AccountManager.swift index 8f5feb5c9..bc47c7dce 100644 --- a/Frameworks/Account/AccountManager.swift +++ b/Frameworks/Account/AccountManager.swift @@ -80,6 +80,10 @@ public final class AccountManager: UnreadCountProvider { readNonLocalAccountsFromDisk() NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil) + + DispatchQueue.main.async { + self.updateUnreadCount() + } } // MARK: API @@ -117,10 +121,7 @@ public final class AccountManager: UnreadCountProvider { func updateUnreadCount() { - let updatedUnreadCount = calculateUnreadCount(accounts) - if updatedUnreadCount != unreadCount { - unreadCount = updatedUnreadCount - } + unreadCount = calculateUnreadCount(accounts) } // MARK: Notifications