2017-05-26 22:10:30 +02:00
|
|
|
//
|
2017-09-23 21:00:07 +02:00
|
|
|
// AppNotifications.swift
|
2018-08-29 07:18:24 +02:00
|
|
|
// NetNewsWire
|
2017-05-26 22:10:30 +02:00
|
|
|
//
|
|
|
|
// Created by Brent Simmons on 8/30/15.
|
|
|
|
// Copyright © 2015 Ranchero Software, LLC. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2019-04-15 22:03:05 +02:00
|
|
|
import Foundation
|
2018-07-24 03:29:08 +02:00
|
|
|
import Articles
|
2017-05-26 22:10:30 +02:00
|
|
|
|
|
|
|
extension Notification.Name {
|
2024-03-04 07:51:53 +01:00
|
|
|
|
2024-06-27 08:13:02 +02:00
|
|
|
static let appUnreadCountDidChange = Notification.Name("AppUnreadCountDidChangeNotification")
|
|
|
|
static let InspectableObjectsDidChange = Notification.Name("InspectableObjectsDidChangeNotification")
|
2017-10-22 00:56:01 +02:00
|
|
|
static let UserDidAddFeed = Notification.Name("UserDidAddFeedNotification")
|
2024-03-04 07:51:53 +01:00
|
|
|
static let LaunchedFromExternalAction = Notification.Name("LaunchedFromExternalAction")
|
2019-09-19 17:38:17 +02:00
|
|
|
|
|
|
|
#if !MAC_APP_STORE
|
|
|
|
static let WebInspectorEnabledDidChange = Notification.Name("WebInspectorEnabledDidChange")
|
|
|
|
#endif
|
2017-05-26 22:10:30 +02:00
|
|
|
}
|
2024-06-27 08:13:02 +02:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|