Show unread count in dock badge. Force-update unread counts at startup.
This commit is contained in:
parent
324f330a3b
commit
fe29ccd2ed
@ -43,6 +43,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations {
|
|||||||
NSWindow.allowsAutomaticWindowTabbing = false
|
NSWindow.allowsAutomaticWindowTabbing = false
|
||||||
super.init()
|
super.init()
|
||||||
dockBadge.appDelegate = self
|
dockBadge.appDelegate = self
|
||||||
|
|
||||||
|
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - NSApplicationDelegate
|
// MARK: - NSApplicationDelegate
|
||||||
@ -64,6 +66,10 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
NSAppleEventManager.shared().setEventHandler(self, andSelector: #selector(AppDelegate.getURL(_:_:)), forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL))
|
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 {
|
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
|
||||||
@ -103,10 +109,12 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations {
|
|||||||
|
|
||||||
// MARK: Notifications
|
// MARK: Notifications
|
||||||
|
|
||||||
func unreadCountDidChange(_ note: Notification) {
|
@objc func unreadCountDidChange(_ note: Notification) {
|
||||||
|
|
||||||
|
if note.object is AccountManager {
|
||||||
unreadCount = AccountManager.shared.unreadCount
|
unreadCount = AccountManager.shared.unreadCount
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Main Window
|
// MARK: Main Window
|
||||||
|
|
||||||
|
@ -138,6 +138,10 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
|||||||
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil)
|
||||||
|
|
||||||
pullObjectsFromDisk()
|
pullObjectsFromDisk()
|
||||||
|
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.updateUnreadCount()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - API
|
// MARK: - API
|
||||||
|
@ -80,6 +80,10 @@ public final class AccountManager: UnreadCountProvider {
|
|||||||
readNonLocalAccountsFromDisk()
|
readNonLocalAccountsFromDisk()
|
||||||
|
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil)
|
||||||
|
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.updateUnreadCount()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: API
|
// MARK: API
|
||||||
@ -117,10 +121,7 @@ public final class AccountManager: UnreadCountProvider {
|
|||||||
|
|
||||||
func updateUnreadCount() {
|
func updateUnreadCount() {
|
||||||
|
|
||||||
let updatedUnreadCount = calculateUnreadCount(accounts)
|
unreadCount = calculateUnreadCount(accounts)
|
||||||
if updatedUnreadCount != unreadCount {
|
|
||||||
unreadCount = updatedUnreadCount
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Notifications
|
// MARK: Notifications
|
||||||
|
Loading…
x
Reference in New Issue
Block a user