mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2025-02-02 20:16:54 +01:00
Add deep linking to Mac app.
This commit is contained in:
parent
0c9a1ba8d0
commit
9203444552
@ -341,6 +341,11 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
|
|||||||
completionHandler([.alert, .badge, .sound])
|
completionHandler([.alert, .badge, .sound])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
|
||||||
|
mainWindowController?.handle(response)
|
||||||
|
completionHandler()
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Add Feed
|
// MARK: Add Feed
|
||||||
|
|
||||||
func addFeed(_ urlString: String?, name: String? = nil, account: Account? = nil, folder: Folder? = nil) {
|
func addFeed(_ urlString: String?, name: String? = nil, account: Account? = nil, folder: Folder? = nil) {
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import AppKit
|
import AppKit
|
||||||
|
import UserNotifications
|
||||||
import Articles
|
import Articles
|
||||||
import Account
|
import Account
|
||||||
import RSCore
|
import RSCore
|
||||||
@ -112,6 +113,12 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
|
|||||||
return sidebarViewController?.selectedObjects
|
return sidebarViewController?.selectedObjects
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handle(_ response: UNNotificationResponse) {
|
||||||
|
let userInfo = response.notification.request.content.userInfo
|
||||||
|
sidebarViewController?.deepLinkRevealAndSelect(for: userInfo)
|
||||||
|
currentTimelineViewController?.goToDeepLink(for: userInfo)
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Notifications
|
// MARK: - Notifications
|
||||||
|
|
||||||
// func window(_ window: NSWindow, willEncodeRestorableState state: NSCoder) {
|
// func window(_ window: NSWindow, willEncodeRestorableState state: NSCoder) {
|
||||||
|
@ -319,6 +319,13 @@ protocol SidebarDelegate: class {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func deepLinkRevealAndSelect(for userInfo: [AnyHashable : Any]) {
|
||||||
|
guard let accountNode = findAccountNode(userInfo), let feedNode = findFeedNode(userInfo, beginningAt: accountNode) else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
revealAndSelectRepresentedObject(feedNode.representedObject)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - NSUserInterfaceValidations
|
// MARK: - NSUserInterfaceValidations
|
||||||
@ -468,6 +475,36 @@ private extension SidebarViewController {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func findAccountNode(_ userInfo: [AnyHashable : Any]?) -> Node? {
|
||||||
|
guard let accountID = userInfo?[DeepLinkKey.accountID.rawValue] as? String else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if let node = treeController.rootNode.descendantNode(where: { ($0.representedObject as? Account)?.accountID == accountID }) {
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
guard let accountName = userInfo?[DeepLinkKey.accountName.rawValue] as? String else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if let node = treeController.rootNode.descendantNode(where: { ($0.representedObject as? Account)?.name == accountName }) {
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func findFeedNode(_ userInfo: [AnyHashable : Any]?, beginningAt startingNode: Node) -> Node? {
|
||||||
|
guard let feedID = userInfo?[DeepLinkKey.feedID.rawValue] as? String else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if let node = startingNode.descendantNode(where: { ($0.representedObject as? Feed)?.feedID == feedID }) {
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func configure(_ cell: SidebarCell, _ node: Node) {
|
func configure(_ cell: SidebarCell, _ node: Node) {
|
||||||
cell.cellAppearance = sidebarCellAppearance
|
cell.cellAppearance = sidebarCellAppearance
|
||||||
cell.name = nameFor(node)
|
cell.name = nameFor(node)
|
||||||
|
@ -387,6 +387,15 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
|||||||
|
|
||||||
// MARK: - Navigation
|
// MARK: - Navigation
|
||||||
|
|
||||||
|
func goToDeepLink(for userInfo: [AnyHashable : Any]) {
|
||||||
|
guard let articleID = userInfo[DeepLinkKey.articleID.rawValue] as? String else { return }
|
||||||
|
guard let ix = articles.firstIndex(where: { $0.articleID == articleID }) else { return }
|
||||||
|
|
||||||
|
NSCursor.setHiddenUntilMouseMoves(true)
|
||||||
|
tableView.rs_selectRow(ix)
|
||||||
|
tableView.scrollTo(row: ix)
|
||||||
|
}
|
||||||
|
|
||||||
func goToNextUnread() {
|
func goToNextUnread() {
|
||||||
guard let ix = indexOfNextUnreadArticle() else {
|
guard let ix = indexOfNextUnreadArticle() else {
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user