mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Persist and restore container expanded state across application launches. Issue #1361
This commit is contained in:
@@ -540,8 +540,9 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner {
|
||||
}
|
||||
|
||||
if let indexPath = dataSource.indexPath(for: node) {
|
||||
coordinator.selectFeed(indexPath, animated: animated)
|
||||
completion?()
|
||||
coordinator.selectFeed(indexPath, animated: animated) {
|
||||
completion?()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -60,6 +60,7 @@
|
||||
<string>Grant permission to save images from the article.</string>
|
||||
<key>NSUserActivityTypes</key>
|
||||
<array>
|
||||
<string>Restoration</string>
|
||||
<string>AddWebFeedIntent</string>
|
||||
<string>NextUnread</string>
|
||||
<string>ReadArticle</string>
|
||||
|
||||
@@ -101,8 +101,12 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
|
||||
private let treeControllerDelegate = WebFeedTreeControllerDelegate()
|
||||
private let treeController: TreeController
|
||||
|
||||
var stateRestorationActivity: NSUserActivity? {
|
||||
return activityManager.stateRestorationActivity
|
||||
var stateRestorationActivity: NSUserActivity {
|
||||
let activity = activityManager.stateRestorationActivity
|
||||
var userInfo = activity.userInfo == nil ? [AnyHashable: Any]() : activity.userInfo
|
||||
userInfo![UserInfoKey.windowState] = windowState()
|
||||
activity.userInfo = userInfo
|
||||
return activity
|
||||
}
|
||||
|
||||
var isRootSplitCollapsed: Bool {
|
||||
@@ -315,11 +319,20 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
|
||||
return rootSplitViewController
|
||||
}
|
||||
|
||||
func restoreWindowState(_ activity: NSUserActivity) {
|
||||
if let windowState = activity.userInfo?[UserInfoKey.windowState] as? [AnyHashable: Any] {
|
||||
restoreWindowState(windowState)
|
||||
rebuildShadowTable()
|
||||
masterFeedViewController.reloadFeeds()
|
||||
}
|
||||
}
|
||||
|
||||
func handle(_ activity: NSUserActivity) {
|
||||
selectFeed(nil, animated: false) {
|
||||
|
||||
guard let activityType = ActivityType(rawValue: activity.activityType) else { return }
|
||||
switch activityType {
|
||||
case .restoration:
|
||||
break
|
||||
case .selectFeed:
|
||||
self.handleSelectFeed(activity.userInfo)
|
||||
case .nextUnread:
|
||||
@@ -329,7 +342,6 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
|
||||
case .addFeedIntent:
|
||||
self.showAdd(.feed)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1744,6 +1756,20 @@ private extension SceneCoordinator {
|
||||
|
||||
// MARK: NSUserActivity
|
||||
|
||||
func windowState() -> [AnyHashable: Any] {
|
||||
let containerIdentifierUserInfos = expandedTable.map( { $0.userInfo })
|
||||
return [
|
||||
UserInfoKey.containerExpandedWindowState: containerIdentifierUserInfos
|
||||
]
|
||||
}
|
||||
|
||||
func restoreWindowState(_ windowState: [AnyHashable: Any]) {
|
||||
if let containerIdentifierUserInfos = windowState[UserInfoKey.containerExpandedWindowState] as? [[AnyHashable: Any]] {
|
||||
let containerIdentifers = containerIdentifierUserInfos.compactMap( { ContainerIdentifier(userInfo: $0) })
|
||||
expandedTable = Set(containerIdentifers)
|
||||
}
|
||||
}
|
||||
|
||||
func handleSelectFeed(_ userInfo: [AnyHashable : Any]?) {
|
||||
guard let userInfo = userInfo,
|
||||
let feedIdentifierUserInfo = userInfo[UserInfoKey.feedIdentifier] as? [AnyHashable : Any],
|
||||
|
||||
@@ -23,6 +23,10 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
||||
window!.tintColor = AppAssets.primaryAccentColor
|
||||
window!.rootViewController = coordinator.start(for: window!.frame.size)
|
||||
|
||||
if let stateRestorationActivity = session.stateRestorationActivity {
|
||||
coordinator.restoreWindowState(stateRestorationActivity)
|
||||
}
|
||||
|
||||
if let shortcutItem = connectionOptions.shortcutItem {
|
||||
window!.makeKeyAndVisible()
|
||||
handleShortcutItem(shortcutItem)
|
||||
|
||||
Reference in New Issue
Block a user