mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2025-01-18 12:31:01 +01:00
Add support appUnreadCountDidChange Notification.
This commit is contained in:
parent
8cd69d7509
commit
00f3b423f6
@ -11,8 +11,8 @@ import Articles
|
|||||||
|
|
||||||
extension Notification.Name {
|
extension Notification.Name {
|
||||||
|
|
||||||
static let appUnreadCountDidChange = Notification.Name("TimelineSelectionDidChangeNotification")
|
static let appUnreadCountDidChange = Notification.Name("AppUnreadCountDidChangeNotification")
|
||||||
static let InspectableObjectsDidChange = Notification.Name("TimelineSelectionDidChangeNotification")
|
static let InspectableObjectsDidChange = Notification.Name("InspectableObjectsDidChangeNotification")
|
||||||
static let UserDidAddFeed = Notification.Name("UserDidAddFeedNotification")
|
static let UserDidAddFeed = Notification.Name("UserDidAddFeedNotification")
|
||||||
static let LaunchedFromExternalAction = Notification.Name("LaunchedFromExternalAction")
|
static let LaunchedFromExternalAction = Notification.Name("LaunchedFromExternalAction")
|
||||||
|
|
||||||
@ -20,3 +20,32 @@ extension Notification.Name {
|
|||||||
static let WebInspectorEnabledDidChange = Notification.Name("WebInspectorEnabledDidChange")
|
static let WebInspectorEnabledDidChange = Notification.Name("WebInspectorEnabledDidChange")
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct AppNotificationUserInfoKey {
|
||||||
|
|
||||||
|
static let unreadCount = "unreadCount"
|
||||||
|
}
|
||||||
|
|
||||||
|
extension Notification {
|
||||||
|
|
||||||
|
var unreadCount: Int? {
|
||||||
|
guard name == .appUnreadCountDidChange else {
|
||||||
|
assertionFailure("This is to be used only with the .appUnreadCountDidChange notification")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
guard let userInfo, let count = userInfo[AppNotificationUserInfoKey.unreadCount] as? Int else {
|
||||||
|
assertionFailure("Missing unread count in notification")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct AppNotification {
|
||||||
|
|
||||||
|
static func postAppUnreadCountDidChange(from: Any, unreadCount: Int) {
|
||||||
|
var userInfo = [AnyHashable: Any]()
|
||||||
|
userInfo[AppNotificationUserInfoKey.unreadCount] = unreadCount
|
||||||
|
NotificationCenter.default.post(name: .appUnreadCountDidChange, object: from, userInfo: userInfo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user