mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Delete appInfo stuff — it was confusing and overkill as a UserInfo helper.
This commit is contained in:
@@ -23,43 +23,16 @@ extension Notification.Name {
|
||||
static let MouseDidExitLink = Notification.Name("MouseDidExitLinkNotification")
|
||||
}
|
||||
|
||||
extension Notification {
|
||||
|
||||
var appInfo: AppInfo? {
|
||||
get {
|
||||
return AppInfo.pullFromUserInfo(userInfo)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
typealias UserInfoDictionary = [AnyHashable: Any]
|
||||
|
||||
final class AppInfo {
|
||||
struct UserInfoKey {
|
||||
|
||||
// These are things commonly passed around in Evergreen notifications.
|
||||
// Rather than setting these things using strings, we have a single AppInfo class
|
||||
// that the userInfo dictionary may contain.
|
||||
|
||||
var view: NSView?
|
||||
var article: Article?
|
||||
var articles: Set<Article>?
|
||||
var navigationKey: Int?
|
||||
var objects: [AnyObject]?
|
||||
var feed: Feed?
|
||||
var url: String?
|
||||
|
||||
static let appInfoKey = "appInfo"
|
||||
|
||||
var userInfo: UserInfoDictionary {
|
||||
get {
|
||||
return [AppInfo.appInfoKey: self] as UserInfoDictionary
|
||||
}
|
||||
}
|
||||
|
||||
static func pullFromUserInfo(_ userInfo: UserInfoDictionary?) -> AppInfo? {
|
||||
|
||||
return userInfo?[appInfoKey] as? AppInfo
|
||||
}
|
||||
static let view = "view"
|
||||
static let article = "article"
|
||||
static let articles = "articles"
|
||||
static let navigationKeyPressed = "navigationKeyPressed"
|
||||
static let objects = "objects"
|
||||
static let feed = "feed"
|
||||
static let url = "url"
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -185,9 +185,7 @@ private extension AddFeedController {
|
||||
}
|
||||
|
||||
if account.addFeed(feed, to: userEnteredFolder) {
|
||||
let appInfo = AppInfo()
|
||||
appInfo.feed = feed
|
||||
NotificationCenter.default.post(name: .UserDidAddFeed, object: self, userInfo: appInfo.userInfo)
|
||||
NotificationCenter.default.post(name: .UserDidAddFeed, object: self, userInfo: [UserInfoKey.feed: feed])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,13 +61,10 @@ final class DetailStatusBarView: NSView {
|
||||
|
||||
@objc func mouseDidEnterLink(_ notification: Notification) {
|
||||
|
||||
guard let appInfo = AppInfo.pullFromUserInfo(notification.userInfo) else {
|
||||
guard let userInfo = notification.userInfo, let view = userInfo[UserInfoKey.view] as? NSView, window === view.window else {
|
||||
return
|
||||
}
|
||||
guard let window = window, let notificationWindow = appInfo.view?.window, window === notificationWindow else {
|
||||
return
|
||||
}
|
||||
guard let link = appInfo.url else {
|
||||
guard let link = userInfo[UserInfoKey.url] as? String else {
|
||||
return
|
||||
}
|
||||
mouseoverLink = link
|
||||
@@ -75,22 +72,19 @@ final class DetailStatusBarView: NSView {
|
||||
|
||||
@objc func mouseDidExitLink(_ notification: Notification) {
|
||||
|
||||
guard let appInfo = AppInfo.pullFromUserInfo(notification.userInfo) else {
|
||||
return
|
||||
}
|
||||
guard let window = window, let notificationWindow = appInfo.view?.window, window === notificationWindow else {
|
||||
guard let view = notification.userInfo?[UserInfoKey.view] as? NSView, window === view.window else {
|
||||
return
|
||||
}
|
||||
mouseoverLink = nil
|
||||
}
|
||||
|
||||
@objc func timelineSelectionDidChange(_ note: Notification) {
|
||||
@objc func timelineSelectionDidChange(_ notification: Notification) {
|
||||
|
||||
let timelineView = note.appInfo?.view
|
||||
if timelineView?.window === self.window {
|
||||
mouseoverLink = nil
|
||||
article = note.appInfo?.article
|
||||
guard let view = notification.userInfo?[UserInfoKey.view] as? NSView, window === view.window else {
|
||||
return
|
||||
}
|
||||
mouseoverLink = nil
|
||||
article = notification.userInfo?[UserInfoKey.article] as? Article
|
||||
}
|
||||
|
||||
// MARK: Drawing
|
||||
|
||||
@@ -67,12 +67,17 @@ final class DetailViewController: NSViewController, WKNavigationDelegate, WKUIDe
|
||||
|
||||
// MARK: Notifications
|
||||
|
||||
@objc func timelineSelectionDidChange(_ note: Notification) {
|
||||
@objc func timelineSelectionDidChange(_ notification: Notification) {
|
||||
|
||||
let timelineView = note.appInfo?.view
|
||||
if timelineView?.window === self.view.window {
|
||||
article = note.appInfo?.article
|
||||
guard let userInfo = notification.userInfo else {
|
||||
return
|
||||
}
|
||||
guard let timelineView = userInfo[UserInfoKey.view] as? NSView, timelineView.window === view.window else {
|
||||
return
|
||||
}
|
||||
|
||||
let timelineArticle = userInfo[UserInfoKey.article] as? Article
|
||||
article = timelineArticle
|
||||
}
|
||||
|
||||
func viewWillStartLiveResize() {
|
||||
@@ -152,20 +157,20 @@ extension DetailViewController: WKScriptMessageHandler {
|
||||
return
|
||||
}
|
||||
|
||||
let appInfo = AppInfo()
|
||||
appInfo.view = self.view
|
||||
appInfo.url = link
|
||||
var userInfo = UserInfoDictionary()
|
||||
userInfo[UserInfoKey.view] = view
|
||||
userInfo[UserInfoKey.url] = link
|
||||
|
||||
NotificationCenter.default.post(name: .MouseDidEnterLink, object: self, userInfo: appInfo.userInfo)
|
||||
NotificationCenter.default.post(name: .MouseDidEnterLink, object: self, userInfo: userInfo)
|
||||
}
|
||||
|
||||
private func mouseDidExit(_ link: String) {
|
||||
|
||||
let appInfo = AppInfo()
|
||||
appInfo.view = self.view
|
||||
appInfo.url = link
|
||||
var userInfo = UserInfoDictionary()
|
||||
userInfo[UserInfoKey.view] = view
|
||||
userInfo[UserInfoKey.url] = link
|
||||
|
||||
NotificationCenter.default.post(name: .MouseDidExitLink, object: self, userInfo: appInfo.userInfo)
|
||||
NotificationCenter.default.post(name: .MouseDidExitLink, object: self, userInfo: userInfo)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
|
||||
|
||||
@objc func appNavigationKeyPressed(_ note: Notification) {
|
||||
|
||||
guard let navigationKey = note.appInfo?.navigationKey else {
|
||||
guard let navigationKey = note.userInfo?[UserInfoKey.navigationKeyPressed] else {
|
||||
return
|
||||
}
|
||||
guard let contentView = window?.contentView, let view = note.object as? NSView, view.isDescendant(of: contentView) else {
|
||||
|
||||
@@ -47,9 +47,7 @@ class SidebarOutlineView : NSOutlineView {
|
||||
}
|
||||
|
||||
if isNavigationKey {
|
||||
let appInfo = AppInfo()
|
||||
appInfo.navigationKey = ch
|
||||
NotificationCenter.default.post(name: .AppNavigationKeyPressed, object: self, userInfo: appInfo.userInfo)
|
||||
NotificationCenter.default.post(name: .AppNavigationKeyPressed, object: self, userInfo: [UserInfoKey.navigationKeyPressed: ch])
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -76,12 +76,12 @@ import RSCore
|
||||
rebuildTreeAndReloadDataIfNeeded()
|
||||
}
|
||||
|
||||
@objc dynamic func userDidAddFeed(_ note: Notification) {
|
||||
@objc dynamic func userDidAddFeed(_ notification: Notification) {
|
||||
|
||||
guard let appInfo = note.appInfo, let feed = appInfo.feed else {
|
||||
guard let feed = notification.userInfo?[UserInfoKey.feed] else {
|
||||
return
|
||||
}
|
||||
revealAndSelectRepresentedObject(feed)
|
||||
revealAndSelectRepresentedObject(feed as AnyObject)
|
||||
}
|
||||
|
||||
@objc func faviconDidBecomeAvailable(_ note: Notification) {
|
||||
@@ -253,13 +253,13 @@ private extension SidebarViewController {
|
||||
|
||||
func postSidebarSelectionDidChangeNotification(_ selectedObjects: [AnyObject]?) {
|
||||
|
||||
let appInfo = AppInfo()
|
||||
var userInfo = UserInfoDictionary()
|
||||
if let objects = selectedObjects {
|
||||
appInfo.objects = objects
|
||||
userInfo[UserInfoKey.objects] = objects
|
||||
}
|
||||
appInfo.view = outlineView
|
||||
userInfo[UserInfoKey.view] = outlineView
|
||||
|
||||
NotificationCenter.default.post(name: .SidebarSelectionDidChange, object: self, userInfo: appInfo.userInfo)
|
||||
NotificationCenter.default.post(name: .SidebarSelectionDidChange, object: self, userInfo: userInfo)
|
||||
}
|
||||
|
||||
func updateUnreadCounts(for objects: [AnyObject]) {
|
||||
|
||||
@@ -201,12 +201,20 @@ class TimelineViewController: NSViewController, KeyboardDelegate, UndoableComman
|
||||
|
||||
// MARK: - Notifications
|
||||
|
||||
@objc func sidebarSelectionDidChange(_ note: Notification) {
|
||||
@objc func sidebarSelectionDidChange(_ notification: Notification) {
|
||||
|
||||
let sidebarView = note.appInfo?.view
|
||||
guard let userInfo = notification.userInfo else {
|
||||
return
|
||||
}
|
||||
guard let sidebarView = userInfo[UserInfoKey.view] as? NSView, sidebarView.window === tableView.window else {
|
||||
return
|
||||
}
|
||||
|
||||
if sidebarView?.window === tableView.window {
|
||||
representedObjects = note.appInfo?.objects
|
||||
if let objects = userInfo[UserInfoKey.objects] as? [AnyObject] {
|
||||
representedObjects = objects
|
||||
}
|
||||
else {
|
||||
representedObjects = nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -398,13 +406,13 @@ extension TimelineViewController: NSTableViewDelegate {
|
||||
|
||||
private func postTimelineSelectionDidChangeNotification(_ selectedArticle: Article?) {
|
||||
|
||||
let appInfo = AppInfo()
|
||||
var userInfo = UserInfoDictionary()
|
||||
if let article = selectedArticle {
|
||||
appInfo.article = article
|
||||
userInfo[UserInfoKey.article] = article
|
||||
}
|
||||
appInfo.view = tableView
|
||||
userInfo[UserInfoKey.view] = tableView
|
||||
|
||||
NotificationCenter.default.post(name: .TimelineSelectionDidChange, object: self, userInfo: appInfo.userInfo)
|
||||
NotificationCenter.default.post(name: .TimelineSelectionDidChange, object: self, userInfo: userInfo)
|
||||
}
|
||||
|
||||
private func configureTimelineCell(_ cell: TimelineTableCellView, article: Article) {
|
||||
|
||||
Reference in New Issue
Block a user