2019-04-15 15:03:05 -05:00
|
|
|
|
//
|
2026-10-22 20:55:50 -07:00
|
|
|
|
// AppDefaults+iOS.swift
|
2019-04-15 15:03:05 -05:00
|
|
|
|
// NetNewsWire
|
|
|
|
|
|
//
|
|
|
|
|
|
// Created by Brent Simmons on 9/22/17.
|
|
|
|
|
|
// Copyright © 2017 Ranchero Software. All rights reserved.
|
|
|
|
|
|
//
|
|
|
|
|
|
|
2026-08-02 10:33:23 -07:00
|
|
|
|
import RSCore
|
2019-04-15 15:03:05 -05:00
|
|
|
|
import UIKit
|
2026-03-23 11:23:15 -07:00
|
|
|
|
import os
|
2025-12-04 11:30:53 -08:00
|
|
|
|
import Account
|
|
|
|
|
|
import Articles
|
2026-05-29 10:46:00 -07:00
|
|
|
|
import Images
|
2019-04-15 15:03:05 -05:00
|
|
|
|
|
2020-03-15 04:25:25 -05:00
|
|
|
|
enum UserInterfaceColorPalette: Int, CustomStringConvertible, CaseIterable {
|
|
|
|
|
|
case automatic = 0
|
|
|
|
|
|
case light = 1
|
|
|
|
|
|
case dark = 2
|
|
|
|
|
|
|
|
|
|
|
|
var description: String {
|
|
|
|
|
|
switch self {
|
|
|
|
|
|
case .automatic:
|
2026-10-22 14:02:53 -07:00
|
|
|
|
NSLocalizedString("Automatic", comment: "Automatic")
|
2020-03-15 04:25:25 -05:00
|
|
|
|
case .light:
|
2026-10-22 14:02:53 -07:00
|
|
|
|
NSLocalizedString("Light", comment: "Light")
|
2020-03-15 04:25:25 -05:00
|
|
|
|
case .dark:
|
2026-10-22 14:02:53 -07:00
|
|
|
|
NSLocalizedString("Dark", comment: "Dark")
|
2020-03-15 04:25:25 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-29 10:34:17 -07:00
|
|
|
|
extension Notification.Name {
|
2026-01-28 14:00:46 -08:00
|
|
|
|
public static let userInterfaceColorPaletteDidUpdate = Notification.Name("UserInterfaceColorPaletteDidUpdateNotification")
|
|
|
|
|
|
public static let timelineIconSizeDidChange = Notification.Name("TimelineIconSizeDidChangeNotification")
|
|
|
|
|
|
public static let timelineNumberOfLinesDidChange = Notification.Name("TimelineNumberOfLinesDidChangeNotification")
|
2025-09-29 10:34:17 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-22 14:00:59 -07:00
|
|
|
|
extension AppDefaults.Key {
|
|
|
|
|
|
static let userInterfaceColorPalette = "userInterfaceColorPalette"
|
|
|
|
|
|
static let refreshClearsReadArticles = "refreshClearsReadArticles"
|
|
|
|
|
|
static let timelineNumberOfLines = "timelineNumberOfLines"
|
|
|
|
|
|
static let timelineIconDimension = "timelineIconSize"
|
|
|
|
|
|
static let articleFullscreenAvailable = "articleFullscreenAvailable"
|
|
|
|
|
|
static let articleFullscreenEnabled = "articleFullscreenEnabled"
|
|
|
|
|
|
static let confirmMarkAllAsRead = "confirmMarkAllAsRead"
|
|
|
|
|
|
static let lastRefresh = "lastRefresh"
|
|
|
|
|
|
static let useSystemBrowser = "useSystemBrowser"
|
|
|
|
|
|
static let hideReadFeeds = "hideReadFeeds"
|
|
|
|
|
|
static let isShowingExtractedArticle = "isShowingExtractedArticle"
|
|
|
|
|
|
static let articleWindowScrollY = "articleWindowScrollY"
|
|
|
|
|
|
static let expandedContainers = "expandedContainers"
|
|
|
|
|
|
static let smartFeedsHidingReadArticles = "smartFeedsHidingReadArticles"
|
|
|
|
|
|
static let feedsHidingReadArticles = "feedsHidingReadArticles"
|
|
|
|
|
|
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"
|
|
|
|
|
|
static let didMigrateAppGroupDefaults = "didMigrateAppGroupDefaults"
|
|
|
|
|
|
|
|
|
|
|
|
// Keys that used to be stored in the app-group suite.
|
2026-10-30 21:36:01 -07:00
|
|
|
|
static let appGroupKeys = [userInterfaceColorPalette, firstRunDate, timelineGroupByFeed, refreshClearsReadArticles, timelineNumberOfLines, timelineIconDimension, timelineSortDirection, articleFullscreenAvailable, articleFullscreenEnabled, confirmMarkAllAsRead, articleContentJavascriptEnabled, splitViewPreferredDisplayMode, lastRefresh]
|
2026-10-22 14:00:59 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extension AppDefaults {
|
|
|
|
|
|
|
2026-08-02 10:33:23 -07:00
|
|
|
|
fileprivate static let logger = Logger(subsystem: Logger.nnwSubsystem, category: "AppDefaults")
|
2025-12-04 11:30:53 -08:00
|
|
|
|
|
2020-03-15 04:25:25 -05:00
|
|
|
|
static var userInterfaceColorPalette: UserInterfaceColorPalette {
|
|
|
|
|
|
get {
|
2026-10-22 14:11:46 -07:00
|
|
|
|
if let result = UserInterfaceColorPalette(rawValue: UserDefaults.standard.integer(forKey: Key.userInterfaceColorPalette)) {
|
2020-03-15 04:25:25 -05:00
|
|
|
|
return result
|
|
|
|
|
|
}
|
|
|
|
|
|
return .automatic
|
|
|
|
|
|
}
|
|
|
|
|
|
set {
|
2026-10-22 14:11:46 -07:00
|
|
|
|
UserDefaults.standard.set(newValue.rawValue, forKey: Key.userInterfaceColorPalette)
|
2026-10-26 14:31:16 -07:00
|
|
|
|
NotificationCenter.default.post(name: .userInterfaceColorPaletteDidUpdate, object: nil)
|
2020-03-15 04:25:25 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-11-16 12:02:58 -06:00
|
|
|
|
|
2026-10-22 13:46:32 -07:00
|
|
|
|
static var useSystemBrowser: Bool {
|
2021-08-22 09:42:06 +08:00
|
|
|
|
get {
|
2026-10-22 14:02:53 -07:00
|
|
|
|
UserDefaults.standard.bool(forKey: Key.useSystemBrowser)
|
2021-08-22 09:42:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
set {
|
2021-08-26 10:27:23 +08:00
|
|
|
|
UserDefaults.standard.setValue(newValue, forKey: Key.useSystemBrowser)
|
2021-08-22 09:42:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2026-10-22 13:46:32 -07:00
|
|
|
|
static var timelineGroupByFeed: Bool {
|
2019-09-08 17:41:00 -05:00
|
|
|
|
get {
|
2026-10-22 14:11:46 -07:00
|
|
|
|
UserDefaults.standard.bool(forKey: Key.timelineGroupByFeed)
|
2019-09-08 17:41:00 -05:00
|
|
|
|
}
|
|
|
|
|
|
set {
|
2026-10-22 14:11:46 -07:00
|
|
|
|
UserDefaults.standard.set(newValue, forKey: Key.timelineGroupByFeed)
|
2019-09-08 17:41:00 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-04-15 15:03:05 -05:00
|
|
|
|
|
2026-10-22 13:46:32 -07:00
|
|
|
|
static var refreshClearsReadArticles: Bool {
|
2020-01-10 18:14:21 -07:00
|
|
|
|
get {
|
2026-10-22 14:11:46 -07:00
|
|
|
|
UserDefaults.standard.bool(forKey: Key.refreshClearsReadArticles)
|
2020-01-10 18:14:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
set {
|
2026-10-22 14:11:46 -07:00
|
|
|
|
UserDefaults.standard.set(newValue, forKey: Key.refreshClearsReadArticles)
|
2020-01-10 18:14:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-22 13:46:32 -07:00
|
|
|
|
static var timelineSortDirection: ComparisonResult {
|
2019-04-15 15:03:05 -05:00
|
|
|
|
get {
|
2026-10-22 14:02:53 -07:00
|
|
|
|
AppDefaults.sortDirection(for: Key.timelineSortDirection)
|
2019-04-15 15:03:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
set {
|
2020-07-02 10:47:45 +08:00
|
|
|
|
AppDefaults.setSortDirection(for: Key.timelineSortDirection, newValue)
|
2019-04-15 15:03:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-22 13:46:32 -07:00
|
|
|
|
static var articleFullscreenAvailable: Bool {
|
2020-02-04 11:24:06 -08:00
|
|
|
|
get {
|
2026-10-22 14:11:46 -07:00
|
|
|
|
UserDefaults.standard.bool(forKey: Key.articleFullscreenAvailable)
|
2020-02-04 11:24:06 -08:00
|
|
|
|
}
|
|
|
|
|
|
set {
|
2026-10-22 14:11:46 -07:00
|
|
|
|
UserDefaults.standard.set(newValue, forKey: Key.articleFullscreenAvailable)
|
2020-02-04 11:24:06 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-22 13:46:32 -07:00
|
|
|
|
static var articleFullscreenEnabled: Bool {
|
2019-11-24 14:18:58 -06:00
|
|
|
|
get {
|
2026-10-22 14:11:46 -07:00
|
|
|
|
articleFullscreenAvailable && UserDefaults.standard.bool(forKey: Key.articleFullscreenEnabled)
|
2019-11-24 14:18:58 -06:00
|
|
|
|
}
|
|
|
|
|
|
set {
|
2026-10-22 14:11:46 -07:00
|
|
|
|
UserDefaults.standard.set(newValue, forKey: Key.articleFullscreenEnabled)
|
2019-11-24 14:18:58 -06:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-22 13:46:32 -07:00
|
|
|
|
static var logicalArticleFullscreenEnabled: Bool {
|
2025-01-11 22:01:27 -08:00
|
|
|
|
articleFullscreenAvailable && articleFullscreenEnabled
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-22 13:46:32 -07:00
|
|
|
|
static var confirmMarkAllAsRead: Bool {
|
2019-10-07 19:48:58 -05:00
|
|
|
|
get {
|
2026-10-22 14:11:46 -07:00
|
|
|
|
UserDefaults.standard.bool(forKey: Key.confirmMarkAllAsRead)
|
2019-10-07 19:48:58 -05:00
|
|
|
|
}
|
|
|
|
|
|
set {
|
2026-10-22 14:11:46 -07:00
|
|
|
|
UserDefaults.standard.set(newValue, forKey: Key.confirmMarkAllAsRead)
|
2019-10-07 19:48:58 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2026-10-22 13:46:32 -07:00
|
|
|
|
static var splitViewPreferredDisplayMode: Int {
|
2026-01-10 17:11:48 +08:00
|
|
|
|
get {
|
2026-10-22 14:11:46 -07:00
|
|
|
|
UserDefaults.standard.integer(forKey: Key.splitViewPreferredDisplayMode)
|
2026-01-10 17:11:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
set {
|
2026-10-22 14:11:46 -07:00
|
|
|
|
UserDefaults.standard.set(newValue, forKey: Key.splitViewPreferredDisplayMode)
|
2026-01-10 17:11:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2026-08-25 11:22:35 -07:00
|
|
|
|
// The iPad timeline column width. nil until the user has resized it.
|
2026-10-22 13:46:32 -07:00
|
|
|
|
static var timelineWidth: Int? {
|
2026-07-28 21:24:20 -07:00
|
|
|
|
get {
|
2026-08-25 11:22:35 -07:00
|
|
|
|
UserDefaults.standard.object(forKey: Key.timelineWidth) as? Int
|
2026-07-28 21:24:20 -07:00
|
|
|
|
}
|
|
|
|
|
|
set {
|
|
|
|
|
|
if let newValue {
|
2026-08-25 11:22:35 -07:00
|
|
|
|
UserDefaults.standard.set(newValue, forKey: Key.timelineWidth)
|
2026-07-28 21:24:20 -07:00
|
|
|
|
} else {
|
2026-08-25 11:22:35 -07:00
|
|
|
|
UserDefaults.standard.removeObject(forKey: Key.timelineWidth)
|
2026-07-28 21:24:20 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-08-27 09:31:50 -07:00
|
|
|
|
// The iPad sidebar column width. nil until the user has resized it.
|
2026-10-22 13:46:32 -07:00
|
|
|
|
static var sidebarWidth: Int? {
|
2026-08-27 09:31:50 -07:00
|
|
|
|
get {
|
|
|
|
|
|
UserDefaults.standard.object(forKey: Key.sidebarWidth) as? Int
|
|
|
|
|
|
}
|
|
|
|
|
|
set {
|
|
|
|
|
|
if let newValue {
|
|
|
|
|
|
UserDefaults.standard.set(newValue, forKey: Key.sidebarWidth)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
UserDefaults.standard.removeObject(forKey: Key.sidebarWidth)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-22 13:46:32 -07:00
|
|
|
|
static var lastRefresh: Date? {
|
2019-04-26 15:24:39 -05:00
|
|
|
|
get {
|
2026-10-22 14:02:53 -07:00
|
|
|
|
AppDefaults.date(for: Key.lastRefresh)
|
2019-04-26 15:24:39 -05:00
|
|
|
|
}
|
|
|
|
|
|
set {
|
2020-07-02 10:47:45 +08:00
|
|
|
|
AppDefaults.setDate(for: Key.lastRefresh, newValue)
|
2019-04-26 15:24:39 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2026-10-22 13:46:32 -07:00
|
|
|
|
static var timelineNumberOfLines: Int {
|
2019-04-29 15:29:00 -05:00
|
|
|
|
get {
|
2026-10-22 14:11:46 -07:00
|
|
|
|
UserDefaults.standard.integer(forKey: Key.timelineNumberOfLines)
|
2019-04-29 15:29:00 -05:00
|
|
|
|
}
|
|
|
|
|
|
set {
|
2026-10-22 14:11:46 -07:00
|
|
|
|
UserDefaults.standard.set(newValue, forKey: Key.timelineNumberOfLines)
|
2026-01-28 14:00:46 -08:00
|
|
|
|
NotificationCenter.default.post(name: .timelineNumberOfLinesDidChange, object: nil)
|
2019-04-29 15:29:00 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2026-10-22 13:46:32 -07:00
|
|
|
|
static var timelineIconSize: IconSize {
|
2019-11-08 17:16:09 -06:00
|
|
|
|
get {
|
2026-10-22 13:32:07 -07:00
|
|
|
|
let rawValue = UserDefaults.standard.integer(forKey: Key.timelineIconDimension)
|
2019-11-16 19:44:01 -06:00
|
|
|
|
return IconSize(rawValue: rawValue) ?? IconSize.medium
|
2019-11-08 17:16:09 -06:00
|
|
|
|
}
|
|
|
|
|
|
set {
|
2026-10-22 13:32:07 -07:00
|
|
|
|
UserDefaults.standard.set(newValue.rawValue, forKey: Key.timelineIconDimension)
|
2026-01-28 14:00:46 -08:00
|
|
|
|
NotificationCenter.default.post(name: .timelineIconSizeDidChange, object: nil)
|
2019-11-08 17:16:09 -06:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2026-10-22 13:46:32 -07:00
|
|
|
|
static var hideReadFeeds: Bool {
|
2025-12-04 11:30:53 -08:00
|
|
|
|
get {
|
|
|
|
|
|
UserDefaults.standard.bool(forKey: Key.hideReadFeeds)
|
|
|
|
|
|
}
|
|
|
|
|
|
set {
|
|
|
|
|
|
UserDefaults.standard.set(newValue, forKey: Key.hideReadFeeds)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-22 13:46:32 -07:00
|
|
|
|
static var isShowingExtractedArticle: Bool {
|
2025-12-04 11:30:53 -08:00
|
|
|
|
get {
|
|
|
|
|
|
UserDefaults.standard.bool(forKey: Key.isShowingExtractedArticle)
|
|
|
|
|
|
}
|
|
|
|
|
|
set {
|
|
|
|
|
|
UserDefaults.standard.set(newValue, forKey: Key.isShowingExtractedArticle)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-22 13:46:32 -07:00
|
|
|
|
static var articleWindowScrollY: Int {
|
2025-12-04 11:30:53 -08:00
|
|
|
|
get {
|
|
|
|
|
|
UserDefaults.standard.integer(forKey: Key.articleWindowScrollY)
|
|
|
|
|
|
}
|
|
|
|
|
|
set {
|
|
|
|
|
|
UserDefaults.standard.set(newValue, forKey: Key.articleWindowScrollY)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-22 13:46:32 -07:00
|
|
|
|
static var expandedContainers: Set<ContainerIdentifier> {
|
2025-12-04 11:30:53 -08:00
|
|
|
|
get {
|
|
|
|
|
|
guard let rawIdentifiers = UserDefaults.standard.array(forKey: Key.expandedContainers) as? [[String: String]] else {
|
|
|
|
|
|
return Set<ContainerIdentifier>()
|
|
|
|
|
|
}
|
|
|
|
|
|
let containerIdentifiers = rawIdentifiers.compactMap { ContainerIdentifier(userInfo: $0) }
|
|
|
|
|
|
return Set(containerIdentifiers)
|
|
|
|
|
|
}
|
|
|
|
|
|
set {
|
|
|
|
|
|
Self.logger.debug("AppDefaults: set expandedContainers: \(newValue)")
|
|
|
|
|
|
let containerIdentifierUserInfos = newValue.compactMap { $0.userInfo }
|
|
|
|
|
|
UserDefaults.standard.set(containerIdentifierUserInfos, forKey: Key.expandedContainers)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-22 13:46:32 -07:00
|
|
|
|
static var smartFeedsHidingReadArticles: Set<String> {
|
2025-12-04 11:30:53 -08:00
|
|
|
|
get {
|
2025-12-30 17:16:08 -08:00
|
|
|
|
let smartFeedIDs = UserDefaults.standard.array(forKey: Key.smartFeedsHidingReadArticles) as? [String] ?? []
|
|
|
|
|
|
return Set(smartFeedIDs)
|
2025-12-04 11:30:53 -08:00
|
|
|
|
}
|
|
|
|
|
|
set {
|
2025-12-30 17:16:08 -08:00
|
|
|
|
let array = Array(newValue)
|
|
|
|
|
|
UserDefaults.standard.set(array, forKey: Key.smartFeedsHidingReadArticles)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-22 13:46:32 -07:00
|
|
|
|
static var feedsHidingReadArticles: [String: Set<String>] { // Account id: Set<feed.feedID>
|
2025-12-30 17:16:08 -08:00
|
|
|
|
get {
|
|
|
|
|
|
guard let d = UserDefaults.standard.dictionary(forKey: Key.feedsHidingReadArticles) as? [String: [String]] else {
|
|
|
|
|
|
return [String: Set<String>]()
|
|
|
|
|
|
}
|
|
|
|
|
|
return d.mapValues { Set($0) }
|
|
|
|
|
|
}
|
|
|
|
|
|
set {
|
|
|
|
|
|
let d = newValue.mapValues { Array($0) }
|
|
|
|
|
|
UserDefaults.standard.set(d, forKey: Key.feedsHidingReadArticles)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-22 13:46:32 -07:00
|
|
|
|
static var foldersShowingReadArticles: [String: Set<String>] { // Account id: Set<folder.nameForDisplay>
|
2025-12-30 17:16:08 -08:00
|
|
|
|
get {
|
|
|
|
|
|
guard let d = UserDefaults.standard.dictionary(forKey: Key.foldersShowingReadArticles) as? [String: [String]] else {
|
|
|
|
|
|
return [String: Set<String>]()
|
|
|
|
|
|
}
|
|
|
|
|
|
return d.mapValues { Set($0) }
|
|
|
|
|
|
}
|
|
|
|
|
|
set {
|
|
|
|
|
|
let d = newValue.mapValues { Array($0) }
|
|
|
|
|
|
UserDefaults.standard.set(d, forKey: Key.foldersShowingReadArticles)
|
2025-12-04 11:30:53 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-22 13:46:32 -07:00
|
|
|
|
static var selectedSidebarItem: SidebarItemIdentifier? {
|
2025-12-04 11:30:53 -08:00
|
|
|
|
get {
|
|
|
|
|
|
guard let userInfo = UserDefaults.standard.dictionary(forKey: Key.selectedSidebarItem) as? [String: String] else {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
return SidebarItemIdentifier(userInfo: userInfo)
|
|
|
|
|
|
}
|
|
|
|
|
|
set {
|
|
|
|
|
|
guard let newValue else {
|
|
|
|
|
|
UserDefaults.standard.removeObject(forKey: Key.selectedSidebarItem)
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
UserDefaults.standard.set(newValue.userInfo, forKey: Key.selectedSidebarItem)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-22 13:46:32 -07:00
|
|
|
|
static var selectedArticle: ArticleSpecifier? {
|
2025-12-04 11:30:53 -08:00
|
|
|
|
get {
|
|
|
|
|
|
guard let d = UserDefaults.standard.dictionary(forKey: Key.selectedArticle) as? [String: String] else {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
return ArticleSpecifier(dictionary: d)
|
|
|
|
|
|
}
|
|
|
|
|
|
set {
|
|
|
|
|
|
guard let newValue else {
|
|
|
|
|
|
UserDefaults.standard.removeObject(forKey: Key.selectedArticle)
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
UserDefaults.standard.set(newValue.dictionary, forKey: Key.selectedArticle)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-22 13:46:32 -07:00
|
|
|
|
static var didMigrateLegacyStateRestorationInfo: Bool {
|
2025-12-04 11:30:53 -08:00
|
|
|
|
get {
|
|
|
|
|
|
UserDefaults.standard.bool(forKey: Key.didMigrateLegacyStateRestorationInfo)
|
|
|
|
|
|
}
|
|
|
|
|
|
set {
|
|
|
|
|
|
UserDefaults.standard.set(newValue, forKey: Key.didMigrateLegacyStateRestorationInfo)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-18 19:58:48 -08:00
|
|
|
|
@MainActor static func registerDefaults() {
|
2026-10-22 13:32:07 -07:00
|
|
|
|
// Must run before register(defaults:) so registered values aren’t copied as explicit ones.
|
|
|
|
|
|
migrateAppGroupDefaultsIfNeeded()
|
|
|
|
|
|
|
2026-10-22 14:00:59 -07:00
|
|
|
|
let platformDefaults: [String: Any] = [
|
|
|
|
|
|
Key.userInterfaceColorPalette: UserInterfaceColorPalette.automatic.rawValue,
|
|
|
|
|
|
Key.refreshClearsReadArticles: false,
|
|
|
|
|
|
Key.timelineNumberOfLines: 2,
|
|
|
|
|
|
Key.timelineIconDimension: IconSize.medium.rawValue,
|
|
|
|
|
|
Key.articleFullscreenAvailable: false,
|
|
|
|
|
|
Key.articleFullscreenEnabled: false,
|
|
|
|
|
|
Key.confirmMarkAllAsRead: true,
|
|
|
|
|
|
Key.splitViewPreferredDisplayMode: UISplitViewController.DisplayMode.oneBesideSecondary.rawValue
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
let defaults = commonRegisteredDefaults.merging(platformDefaults) { _, platformValue in platformValue }
|
2026-10-22 13:32:07 -07:00
|
|
|
|
UserDefaults.standard.register(defaults: defaults)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Copies each key’s value from source to destination, unless destination already has a value.
|
|
|
|
|
|
static func migrate(from source: UserDefaults, to destination: UserDefaults, keys: [String]) {
|
|
|
|
|
|
for key in keys {
|
|
|
|
|
|
if let value = source.object(forKey: key), destination.object(forKey: key) == nil {
|
|
|
|
|
|
destination.set(value, forKey: key)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-04-15 15:03:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private extension AppDefaults {
|
|
|
|
|
|
|
2026-10-22 13:32:07 -07:00
|
|
|
|
/// Moves settings from the app-group suite to UserDefaults.standard, then deletes the suite.
|
|
|
|
|
|
/// <https://github.com/Ranchero-Software/NetNewsWire/issues/5466>
|
|
|
|
|
|
static func migrateAppGroupDefaultsIfNeeded() {
|
|
|
|
|
|
guard !UserDefaults.standard.bool(forKey: Key.didMigrateAppGroupDefaults) else {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
UserDefaults.standard.set(true, forKey: Key.didMigrateAppGroupDefaults)
|
|
|
|
|
|
|
|
|
|
|
|
guard let appIdentifierPrefix = Bundle.main.object(forInfoDictionaryKey: "AppIdentifierPrefix") as? String, let bundleIdentifier = Bundle.main.bundleIdentifier else {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
let suiteName = "\(appIdentifierPrefix)group.\(bundleIdentifier)"
|
|
|
|
|
|
guard let appGroupDefaults = UserDefaults(suiteName: suiteName) else {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
migrate(from: appGroupDefaults, to: UserDefaults.standard, keys: Key.appGroupKeys)
|
|
|
|
|
|
appGroupDefaults.removePersistentDomain(forName: suiteName)
|
2019-04-15 15:03:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static func setSortDirection(for key: String, _ value: ComparisonResult) {
|
|
|
|
|
|
if value == .orderedAscending {
|
2026-10-22 14:11:46 -07:00
|
|
|
|
UserDefaults.standard.set(ComparisonResult.orderedAscending.rawValue, forKey: key)
|
2026-01-02 15:58:36 -08:00
|
|
|
|
} else {
|
2026-10-22 14:11:46 -07:00
|
|
|
|
UserDefaults.standard.set(ComparisonResult.orderedDescending.rawValue, forKey: key)
|
2019-04-15 15:03:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-12-04 11:30:53 -08:00
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-12-04 11:30:53 -08:00
|
|
|
|
struct StateRestorationInfo {
|
|
|
|
|
|
let hideReadFeeds: Bool
|
|
|
|
|
|
let expandedContainers: Set<ContainerIdentifier>
|
|
|
|
|
|
let selectedSidebarItem: SidebarItemIdentifier?
|
2025-12-30 17:16:08 -08:00
|
|
|
|
let smartFeedsHidingReadArticles: Set<String>
|
|
|
|
|
|
let feedsHidingReadArticles: [String: Set<String>]
|
|
|
|
|
|
let foldersShowingReadArticles: [String: Set<String>]
|
2025-12-04 11:30:53 -08:00
|
|
|
|
let selectedArticle: ArticleSpecifier?
|
|
|
|
|
|
let articleWindowScrollY: Int
|
|
|
|
|
|
let isShowingExtractedArticle: Bool
|
|
|
|
|
|
|
|
|
|
|
|
init(hideReadFeeds: Bool,
|
2026-01-02 15:58:36 -08:00
|
|
|
|
expandedContainers: Set<ContainerIdentifier>,
|
|
|
|
|
|
selectedSidebarItem: SidebarItemIdentifier?,
|
|
|
|
|
|
smartFeedsHidingReadArticles: Set<String>,
|
|
|
|
|
|
feedsHidingReadArticles: [String: Set<String>],
|
|
|
|
|
|
foldersShowingReadArticles: [String: Set<String>],
|
|
|
|
|
|
selectedArticle: ArticleSpecifier?,
|
|
|
|
|
|
articleWindowScrollY: Int,
|
|
|
|
|
|
isShowingExtractedArticle: Bool) {
|
2025-12-04 11:30:53 -08:00
|
|
|
|
self.hideReadFeeds = hideReadFeeds
|
|
|
|
|
|
self.expandedContainers = expandedContainers
|
|
|
|
|
|
self.selectedSidebarItem = selectedSidebarItem
|
2025-12-30 17:16:08 -08:00
|
|
|
|
self.smartFeedsHidingReadArticles = smartFeedsHidingReadArticles
|
|
|
|
|
|
self.feedsHidingReadArticles = feedsHidingReadArticles
|
|
|
|
|
|
self.foldersShowingReadArticles = foldersShowingReadArticles
|
2025-12-04 11:30:53 -08:00
|
|
|
|
self.selectedArticle = selectedArticle
|
|
|
|
|
|
self.articleWindowScrollY = articleWindowScrollY
|
|
|
|
|
|
self.isShowingExtractedArticle = isShowingExtractedArticle
|
|
|
|
|
|
|
2025-12-30 17:16:08 -08:00
|
|
|
|
AppDefaults.logger.debug("AppDefaults: StateRestorationInfo:\nexpandedContainers: \(expandedContainers)\nselectedSidebarItem: \(selectedSidebarItem?.userInfo ?? [String: String]())\nsmartFeedsHidingReadArticles: \(smartFeedsHidingReadArticles)\nfeedsHidingReadArticles: \(feedsHidingReadArticles)\nfoldersShowingReadArticles: \(foldersShowingReadArticles)\nselectedArticle: \(selectedArticle?.dictionary ?? [String: String]())\narticleWindowScrollY: \(articleWindowScrollY)\nisShowingExtractedArticle: \(isShowingExtractedArticle ? "true" : "false")")
|
2025-12-04 11:30:53 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
init() {
|
2026-10-22 13:46:32 -07:00
|
|
|
|
self.init(hideReadFeeds: AppDefaults.hideReadFeeds,
|
|
|
|
|
|
expandedContainers: AppDefaults.expandedContainers,
|
|
|
|
|
|
selectedSidebarItem: AppDefaults.selectedSidebarItem,
|
|
|
|
|
|
smartFeedsHidingReadArticles: AppDefaults.smartFeedsHidingReadArticles,
|
|
|
|
|
|
feedsHidingReadArticles: AppDefaults.feedsHidingReadArticles,
|
|
|
|
|
|
foldersShowingReadArticles: AppDefaults.foldersShowingReadArticles,
|
|
|
|
|
|
selectedArticle: AppDefaults.selectedArticle,
|
|
|
|
|
|
articleWindowScrollY: AppDefaults.articleWindowScrollY,
|
|
|
|
|
|
isShowingExtractedArticle: AppDefaults.isShowingExtractedArticle)
|
2025-12-04 11:30:53 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Delete for NetNewsWire 7.1.
|
|
|
|
|
|
init(legacyState: NSUserActivity?) {
|
2026-10-22 13:46:32 -07:00
|
|
|
|
if AppDefaults.didMigrateLegacyStateRestorationInfo {
|
2025-12-04 11:30:53 -08:00
|
|
|
|
self.init()
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-22 13:46:32 -07:00
|
|
|
|
AppDefaults.didMigrateLegacyStateRestorationInfo = true
|
2025-12-04 11:30:53 -08:00
|
|
|
|
|
|
|
|
|
|
// 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 {
|
2026-10-22 13:46:32 -07:00
|
|
|
|
hideReadFeeds = AppDefaults.hideReadFeeds
|
2025-12-04 11:30:53 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let expandedContainers: Set<ContainerIdentifier>
|
|
|
|
|
|
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 {
|
2026-10-22 13:46:32 -07:00
|
|
|
|
expandedContainers = AppDefaults.expandedContainers
|
2025-12-04 11:30:53 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let sidebarItemsHidingReadArticles: Set<SidebarItemIdentifier>
|
|
|
|
|
|
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
|
|
|
|
|
|
}
|
2025-12-30 17:16:08 -08:00
|
|
|
|
let sidebarItemIdentifiers = convertedState.compactMap { SidebarItemIdentifier(userInfo: $0) }
|
|
|
|
|
|
sidebarItemsHidingReadArticles = Set(sidebarItemIdentifiers)
|
2025-12-04 11:30:53 -08:00
|
|
|
|
} else {
|
2025-12-30 21:20:33 -08:00
|
|
|
|
sidebarItemsHidingReadArticles = Set<SidebarItemIdentifier>()
|
2025-12-30 17:16:08 -08:00
|
|
|
|
}
|
2025-12-30 21:20:33 -08:00
|
|
|
|
|
2025-12-30 17:16:08 -08:00
|
|
|
|
var smartFeedsHidingReadArticles = Set<String>()
|
|
|
|
|
|
var feedsHidingReadArticles = [String: Set<String>]()
|
|
|
|
|
|
for sidebarItem in sidebarItemsHidingReadArticles {
|
|
|
|
|
|
switch sidebarItem {
|
|
|
|
|
|
case .smartFeed(let id):
|
|
|
|
|
|
smartFeedsHidingReadArticles.insert(id)
|
2025-12-30 21:20:33 -08:00
|
|
|
|
case .feed(let accountID, let feedID):
|
2025-12-30 17:16:08 -08:00
|
|
|
|
var feedIDs = feedsHidingReadArticles[accountID] ?? Set<String>()
|
|
|
|
|
|
feedIDs.insert(feedID)
|
|
|
|
|
|
feedsHidingReadArticles[accountID] = feedIDs
|
|
|
|
|
|
default:
|
|
|
|
|
|
continue
|
|
|
|
|
|
}
|
2025-12-04 11:30:53 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let selectedSidebarItem: SidebarItemIdentifier?
|
2025-12-30 17:16:08 -08:00
|
|
|
|
if let legacyState = windowState[UserInfoKey.feedIdentifier] as? [String: String],
|
|
|
|
|
|
let sidebarItemIdentifier = SidebarItemIdentifier(userInfo: legacyState) {
|
|
|
|
|
|
selectedSidebarItem = sidebarItemIdentifier
|
2025-12-04 11:30:53 -08:00
|
|
|
|
} else {
|
2026-10-22 13:46:32 -07:00
|
|
|
|
selectedSidebarItem = AppDefaults.selectedSidebarItem
|
2025-12-04 11:30:53 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
self.init(hideReadFeeds: hideReadFeeds,
|
|
|
|
|
|
expandedContainers: expandedContainers,
|
|
|
|
|
|
selectedSidebarItem: selectedSidebarItem,
|
2025-12-30 17:16:08 -08:00
|
|
|
|
smartFeedsHidingReadArticles: smartFeedsHidingReadArticles,
|
|
|
|
|
|
feedsHidingReadArticles: feedsHidingReadArticles,
|
2026-10-22 13:46:32 -07:00
|
|
|
|
foldersShowingReadArticles: AppDefaults.foldersShowingReadArticles,
|
|
|
|
|
|
selectedArticle: AppDefaults.selectedArticle,
|
|
|
|
|
|
articleWindowScrollY: AppDefaults.articleWindowScrollY,
|
|
|
|
|
|
isShowingExtractedArticle: AppDefaults.isShowingExtractedArticle)
|
2025-12-04 11:30:53 -08:00
|
|
|
|
}
|
2019-04-15 15:03:05 -05:00
|
|
|
|
}
|