Update Mac app to work with latest ActivityManager.

This commit is contained in:
Maurice Parker 2019-11-14 15:35:19 -06:00
parent 3df757ae39
commit 15e62a0750
5 changed files with 21 additions and 15 deletions

View File

@ -117,14 +117,16 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
func handle(_ response: UNNotificationResponse) {
let userInfo = response.notification.request.content.userInfo
sidebarViewController?.deepLinkRevealAndSelect(for: userInfo)
currentTimelineViewController?.goToDeepLink(for: userInfo)
guard let articlePathUserInfo = userInfo[UserInfoKey.articlePath] as? [AnyHashable : Any] else { return }
sidebarViewController?.deepLinkRevealAndSelect(for: articlePathUserInfo)
currentTimelineViewController?.goToDeepLink(for: articlePathUserInfo)
}
func handle(_ activity: NSUserActivity) {
guard let userInfo = activity.userInfo else { return }
sidebarViewController?.deepLinkRevealAndSelect(for: userInfo)
currentTimelineViewController?.goToDeepLink(for: userInfo)
guard let articlePathUserInfo = userInfo[UserInfoKey.articlePath] as? [AnyHashable : Any] else { return }
sidebarViewController?.deepLinkRevealAndSelect(for: articlePathUserInfo)
currentTimelineViewController?.goToDeepLink(for: articlePathUserInfo)
}
// MARK: - Notifications
@ -479,7 +481,7 @@ extension MainWindowController: TimelineContainerViewControllerDelegate {
let detailState: DetailState
if let articles = articles {
if articles.count == 1 {
activityManager.reading(articles.first!)
activityManager.reading(fetcher: nil, article: articles.first)
if articles.first?.feed?.isArticleExtractorAlwaysOn ?? false {
detailState = .loading
startArticleExtractorForCurrentLink()

View File

@ -484,7 +484,7 @@ private extension SidebarViewController {
}
func findAccountNode(_ userInfo: [AnyHashable : Any]?) -> Node? {
guard let accountID = userInfo?[DeepLinkKey.accountID.rawValue] as? String else {
guard let accountID = userInfo?[ArticlePathKey.accountID] as? String else {
return nil
}
@ -492,7 +492,7 @@ private extension SidebarViewController {
return node
}
guard let accountName = userInfo?[DeepLinkKey.accountName.rawValue] as? String else {
guard let accountName = userInfo?[ArticlePathKey.accountName] as? String else {
return nil
}
@ -504,7 +504,7 @@ private extension SidebarViewController {
}
func findFeedNode(_ userInfo: [AnyHashable : Any]?, beginningAt startingNode: Node) -> Node? {
guard let feedID = userInfo?[DeepLinkKey.feedID.rawValue] as? String else {
guard let feedID = userInfo?[ArticlePathKey.feedID] as? String else {
return nil
}
if let node = startingNode.descendantNode(where: { ($0.representedObject as? Feed)?.feedID == feedID }) {

View File

@ -388,7 +388,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
// MARK: - Navigation
func goToDeepLink(for userInfo: [AnyHashable : Any]) {
guard let articleID = userInfo[DeepLinkKey.articleID.rawValue] as? String else { return }
guard let articleID = userInfo[ArticlePathKey.articleID] as? String else { return }
guard let ix = articles.firstIndex(where: { $0.articleID == articleID }) else { return }
NSCursor.setHiddenUntilMouseMoves(true)

View File

@ -45,7 +45,7 @@
</dict>
<key>NSUserActivityTypes</key>
<array>
<string>com.ranchero.NetNewsWire.ReadArticle</string>
<string>ReadArticle</string>
</array>
<key>NSAppleEventsUsageDescription</key>
<string>NetNewsWire communicates with other apps on your Mac when you choose to share an article.</string>

View File

@ -80,7 +80,7 @@ class ActivityManager {
invalidateReading()
invalidateNextUnread()
guard let fetcher = fetcher, let article = article else { return }
guard let article = article else { return }
readingActivity = makeReadArticleActivity(fetcher: fetcher, article: article)
#if os(iOS)
@ -176,13 +176,17 @@ private extension ActivityManager {
return activity
}
func makeReadArticleActivity(fetcher: ArticleFetcher, article: Article) -> NSUserActivity {
func makeReadArticleActivity(fetcher: ArticleFetcher?, article: Article) -> NSUserActivity {
let activity = NSUserActivity(activityType: ActivityType.readArticle.rawValue)
activity.title = ArticleStringFormatter.truncatedTitle(article)
let articleFetcherIdentifierUserInfo = fetcher.articleFetcherType?.userInfo ?? [AnyHashable: Any]()
let articlePathUserInfo = article.pathUserInfo
activity.userInfo = [UserInfoKey.feedIdentifier: articleFetcherIdentifierUserInfo, UserInfoKey.articlePath: articlePathUserInfo]
if let fetcher = fetcher {
let articleFetcherIdentifierUserInfo = fetcher.articleFetcherType?.userInfo ?? [AnyHashable: Any]()
let articlePathUserInfo = article.pathUserInfo
activity.userInfo = [UserInfoKey.feedIdentifier: articleFetcherIdentifierUserInfo, UserInfoKey.articlePath: articlePathUserInfo]
} else {
activity.userInfo = [UserInfoKey.articlePath: article.pathUserInfo]
}
activity.requiredUserInfoKeys = Set(activity.userInfo!.keys.map { $0 as! String })
activity.isEligibleForHandoff = true