From 102ffbdc4bae8343df1f91af4694b20dd94a03dc Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Thu, 3 Dec 2026 09:38:51 -0800 Subject: [PATCH] Remove obsolete state restoration migration from iOS. --- Shared/UserInfoKey.swift | 1 - iOS/AppDefaults+iOS.swift | 101 ------------------------------------- iOS/SceneCoordinator.swift | 9 ++-- iOS/SceneDelegate.swift | 2 +- 4 files changed, 4 insertions(+), 109 deletions(-) diff --git a/Shared/UserInfoKey.swift b/Shared/UserInfoKey.swift index eef2e90d3..e5887808d 100644 --- a/Shared/UserInfoKey.swift +++ b/Shared/UserInfoKey.swift @@ -20,7 +20,6 @@ struct UserInfoKey { static let windowFullScreenState = "windowFullScreenState" static let containerExpandedWindowState = "containerExpandedWindowState" static let readFeedsFilterState = "readFeedsFilterState" - static let readArticlesFilterState = "readArticlesFilterState" static let readArticlesFilterStateKeys = "readArticlesFilterStateKey" static let readArticlesFilterStateValues = "readArticlesFilterStateValue" static let selectedFeedsState = "selectedFeedsState" diff --git a/iOS/AppDefaults+iOS.swift b/iOS/AppDefaults+iOS.swift index 4274ce253..a51c06612 100644 --- a/iOS/AppDefaults+iOS.swift +++ b/iOS/AppDefaults+iOS.swift @@ -31,7 +31,6 @@ extension AppDefaults.Key { static let foldersShowingReadArticles = "foldersShowingReadArticles" static let selectedSidebarItem = "selectedSidebarItem" static let selectedArticle = "selectedArticle" - static let didMigrateLegacyStateRestorationInfo = "didMigrateLegacyStateRestorationInfo" static let splitViewPreferredDisplayMode = "splitViewPreferredDisplayMode" static let timelineWidth = "timelineWidth" static let sidebarWidth = "sidebarWidth" @@ -290,15 +289,6 @@ extension AppDefaults { } } - static var didMigrateLegacyStateRestorationInfo: Bool { - get { - UserDefaults.standard.bool(forKey: Key.didMigrateLegacyStateRestorationInfo) - } - set { - UserDefaults.standard.set(newValue, forKey: Key.didMigrateLegacyStateRestorationInfo) - } - } - @MainActor static func registerDefaults() { // Must run before register(defaults:) so registered values aren’t copied as explicit ones. migrateAppGroupDefaultsIfNeeded() @@ -403,95 +393,4 @@ struct StateRestorationInfo { articleWindowScrollY: AppDefaults.articleWindowScrollY, isShowingExtractedArticle: AppDefaults.isShowingExtractedArticle) } - - // TODO: Delete for NetNewsWire 7.1. - init(legacyState: NSUserActivity?) { - if AppDefaults.didMigrateLegacyStateRestorationInfo { - self.init() - return - } - - AppDefaults.didMigrateLegacyStateRestorationInfo = true - - // Extract legacy window state if available - guard let windowState = legacyState?.userInfo?[UserInfoKey.windowState] as? [AnyHashable: Any] else { - self.init() - return - } - - let hideReadFeeds: Bool - if let legacyValue = windowState[UserInfoKey.readFeedsFilterState] as? Bool { - hideReadFeeds = legacyValue - } else { - hideReadFeeds = AppDefaults.hideReadFeeds - } - - let expandedContainers: Set - if let legacyState = windowState[UserInfoKey.containerExpandedWindowState] as? [[AnyHashable: AnyHashable]] { - let convertedState = legacyState.compactMap { dict -> [String: String]? in - var stringDict = [String: String]() - for (key, value) in dict { - if let keyString = key as? String, let valueString = value as? String { - stringDict[keyString] = valueString - } - } - return stringDict.isEmpty ? nil : stringDict - } - let containerIdentifiers = convertedState.compactMap { ContainerIdentifier(userInfo: $0) } - expandedContainers = Set(containerIdentifiers) - } else { - expandedContainers = AppDefaults.expandedContainers - } - - let sidebarItemsHidingReadArticles: Set - if let legacyState = windowState[UserInfoKey.readArticlesFilterState] as? [[AnyHashable: AnyHashable]: Bool] { - let enabledFeeds = legacyState.filter { $0.value == true } - let convertedState = enabledFeeds.keys.compactMap { key -> [String: String]? in - var stringDict = [String: String]() - for (k, v) in key { - if let keyString = k as? String, let valueString = v as? String { - stringDict[keyString] = valueString - } - } - return stringDict.isEmpty ? nil : stringDict - } - let sidebarItemIdentifiers = convertedState.compactMap { SidebarItemIdentifier(userInfo: $0) } - sidebarItemsHidingReadArticles = Set(sidebarItemIdentifiers) - } else { - sidebarItemsHidingReadArticles = Set() - } - - var smartFeedsHidingReadArticles = Set() - var feedsHidingReadArticles = [String: Set]() - for sidebarItem in sidebarItemsHidingReadArticles { - switch sidebarItem { - case .smartFeed(let id): - smartFeedsHidingReadArticles.insert(id) - case .feed(let accountID, let feedID): - var feedIDs = feedsHidingReadArticles[accountID] ?? Set() - feedIDs.insert(feedID) - feedsHidingReadArticles[accountID] = feedIDs - default: - continue - } - } - - let selectedSidebarItem: SidebarItemIdentifier? - if let legacyState = windowState[UserInfoKey.feedIdentifier] as? [String: String], - let sidebarItemIdentifier = SidebarItemIdentifier(userInfo: legacyState) { - selectedSidebarItem = sidebarItemIdentifier - } else { - selectedSidebarItem = AppDefaults.selectedSidebarItem - } - - self.init(hideReadFeeds: hideReadFeeds, - expandedContainers: expandedContainers, - selectedSidebarItem: selectedSidebarItem, - smartFeedsHidingReadArticles: smartFeedsHidingReadArticles, - feedsHidingReadArticles: feedsHidingReadArticles, - foldersShowingReadArticles: AppDefaults.foldersShowingReadArticles, - selectedArticle: AppDefaults.selectedArticle, - articleWindowScrollY: AppDefaults.articleWindowScrollY, - isShowingExtractedArticle: AppDefaults.isShowingExtractedArticle) - } } diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index 71f3df1da..f9432dc25 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -408,14 +408,11 @@ struct SidebarItemNode: Hashable, Sendable { } } - func restoreWindowState(activity: NSUserActivity?, restoreSelection: Bool) { - let stateInfo = StateRestorationInfo(legacyState: activity) - restoreWindowState(stateInfo, restoreSelection: restoreSelection) - } - - private func restoreWindowState(_ stateInfo: StateRestorationInfo, restoreSelection: Bool) { + func restoreWindowState(restoreSelection: Bool) { Self.logger.debug("SceneCoordinator: restoreWindowState") + let stateInfo = StateRestorationInfo() + isRestoringState = true if AppDefaults.isFirstRun { diff --git a/iOS/SceneDelegate.swift b/iOS/SceneDelegate.swift index 127003743..5c1be7e74 100644 --- a/iOS/SceneDelegate.swift +++ b/iOS/SceneDelegate.swift @@ -45,7 +45,7 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate { connectionOptions.shortcutItem != nil || !connectionOptions.userActivities.isEmpty - coordinator.restoreWindowState(activity: session.stateRestorationActivity, restoreSelection: !hasPendingExternalAction) + coordinator.restoreWindowState(restoreSelection: !hasPendingExternalAction) updateUserInterfaceStyle()