mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-12-03 10:47:21 +00:00
Use UserDefaults for state restoration.
This commit is contained in:
1 parent
eeb97d85e4
commit
08e67d356e
2 files changed
+18
-7
No files matched your search
@@ -22,6 +22,7 @@ import UniformTypeIdentifiers
|
||||
private var readingActivity: NSUserActivity?
|
||||
private var readingArticle: Article?
|
||||
|
||||
#if os(macOS)
|
||||
var stateRestorationActivity: NSUserActivity {
|
||||
if let activity = readingActivity {
|
||||
return activity
|
||||
@@ -32,12 +33,21 @@ import UniformTypeIdentifiers
|
||||
}
|
||||
|
||||
let activity = NSUserActivity(activityType: ActivityType.restoration.rawValue)
|
||||
#if os(iOS)
|
||||
activity.persistentIdentifier = UUID().uuidString
|
||||
#endif
|
||||
activity.becomeCurrent()
|
||||
return activity
|
||||
}
|
||||
#else // iOS
|
||||
var stateRestorationActivity: NSUserActivity {
|
||||
// State restoration is now handled via UserDefaults (AppDefaults.selectedSidebarItem and AppDefaults.selectedArticle).
|
||||
// The reading/selecting activities are still maintained for Handoff, Spotlight, and Siri Shortcuts,
|
||||
// but we don't use them for same-device state restoration anymore.
|
||||
let activity = NSUserActivity(activityType: ActivityType.restoration.rawValue)
|
||||
activity.persistentIdentifier = UUID().uuidString
|
||||
activity.becomeCurrent()
|
||||
return activity
|
||||
}
|
||||
#endif
|
||||
|
||||
init() {
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(feedIconDidBecomeAvailable(_:)), name: .feedIconDidBecomeAvailable, object: nil)
|
||||
|
||||
@@ -27,8 +27,8 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
||||
rootViewController.preferredDisplayMode = .oneBesideSecondary
|
||||
|
||||
Task { @MainActor in
|
||||
// Ensure Feeds view shows on first run on iPad — otherwise the UI is empty.
|
||||
if UIDevice.current.userInterfaceIdiom == .pad && AppDefaults.shared.isFirstRun {
|
||||
// Ensure Feeds view shows on iPad — otherwise the UI may be empty.
|
||||
if UIDevice.current.userInterfaceIdiom == .pad {
|
||||
rootViewController.show(.primary)
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,7 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
||||
rootViewController.coordinator = coordinator
|
||||
rootViewController.delegate = coordinator
|
||||
|
||||
coordinator.restoreWindowState(session.stateRestorationActivity)
|
||||
coordinator.restoreWindowState(activity: session.stateRestorationActivity)
|
||||
|
||||
updateUserInterfaceStyle()
|
||||
|
||||
@@ -58,10 +58,11 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
||||
return
|
||||
}
|
||||
|
||||
if let userActivity = connectionOptions.userActivities.first ?? session.stateRestorationActivity {
|
||||
// Handle activities from external sources (Handoff, Spotlight, Siri Shortcuts).
|
||||
// Skip handling session.stateRestorationActivity since UserDefaults now handles state restoration.
|
||||
if let userActivity = connectionOptions.userActivities.first {
|
||||
coordinator.handle(userActivity)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func windowScene(_ windowScene: UIWindowScene, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
|
||||
|
||||
Reference in new issue
Block a user