2026-10-22 14:00:59 -07:00
|
|
|
|
//
|
|
|
|
|
|
// AppDefaults.swift
|
|
|
|
|
|
// NetNewsWire
|
|
|
|
|
|
//
|
|
|
|
|
|
// Created by Brent Simmons on 10/22/26.
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
|
2026-10-22 20:55:50 -07:00
|
|
|
|
/// Settings common to Mac and iOS. Platform-specific settings are in extensions in AppDefaults+Mac.swift and AppDefaults+iOS.swift.
|
2026-10-22 14:00:59 -07:00
|
|
|
|
enum AppDefaults {
|
|
|
|
|
|
|
|
|
|
|
|
static let defaultThemeName = "Default"
|
|
|
|
|
|
|
|
|
|
|
|
struct Key {
|
|
|
|
|
|
static let firstRunDate = "firstRunDate"
|
|
|
|
|
|
static let timelineSortDirection = "timelineSortDirection"
|
|
|
|
|
|
static let timelineGroupByFeed = "timelineGroupByFeed"
|
|
|
|
|
|
static let addFeedAccountID = "addFeedAccountID"
|
|
|
|
|
|
static let addFeedFolderName = "addFeedFolderName"
|
|
|
|
|
|
static let addFolderAccountID = "addFolderAccountID"
|
|
|
|
|
|
static let currentThemeName = "currentThemeName"
|
|
|
|
|
|
static let articleContentJavascriptEnabled = "articleContentJavascriptEnabled"
|
|
|
|
|
|
static let unreadCountDisplay = "unreadCountDisplay"
|
2026-10-26 10:11:55 -07:00
|
|
|
|
static let timelineThumbnailsDisplay = "timelineThumbnailsDisplay"
|
2026-10-26 11:36:44 -07:00
|
|
|
|
static let timelineFeedIconsDisplay = "timelineFeedIconsDisplay"
|
2026-10-22 14:00:59 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Registered by both platforms. Each platform’s registerDefaults adds its own.
|
2026-10-22 20:55:50 -07:00
|
|
|
|
static var commonRegisteredDefaults: [String: Any] {
|
|
|
|
|
|
[
|
|
|
|
|
|
Key.timelineSortDirection: ComparisonResult.orderedDescending.rawValue,
|
|
|
|
|
|
Key.timelineGroupByFeed: false,
|
|
|
|
|
|
Key.currentThemeName: defaultThemeName,
|
2026-10-26 10:11:55 -07:00
|
|
|
|
Key.articleContentJavascriptEnabled: true,
|
2026-10-26 11:36:44 -07:00
|
|
|
|
Key.timelineThumbnailsDisplay: TimelineThumbnailsDisplay.small.rawValue,
|
|
|
|
|
|
Key.timelineFeedIconsDisplay: TimelineFeedIconsDisplay.automatic.rawValue
|
2026-10-22 20:55:50 -07:00
|
|
|
|
]
|
|
|
|
|
|
}
|
2026-10-22 14:00:59 -07:00
|
|
|
|
|
|
|
|
|
|
static let isDeveloperBuild: Bool = {
|
|
|
|
|
|
if let dev = Bundle.main.object(forInfoDictionaryKey: "DeveloperEntitlements") as? String, dev == "-dev" {
|
|
|
|
|
|
return true
|
|
|
|
|
|
}
|
|
|
|
|
|
return false
|
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
|
|
static let isFirstRun: Bool = {
|
|
|
|
|
|
if UserDefaults.standard.object(forKey: Key.firstRunDate) is Date {
|
|
|
|
|
|
return false
|
|
|
|
|
|
}
|
|
|
|
|
|
firstRunDate = Date()
|
|
|
|
|
|
return true
|
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
|
|
static var addFeedAccountID: String? {
|
|
|
|
|
|
get {
|
2026-10-22 14:11:46 -07:00
|
|
|
|
UserDefaults.standard.string(forKey: Key.addFeedAccountID)
|
2026-10-22 14:00:59 -07:00
|
|
|
|
}
|
|
|
|
|
|
set {
|
2026-10-22 14:11:46 -07:00
|
|
|
|
UserDefaults.standard.set(newValue, forKey: Key.addFeedAccountID)
|
2026-10-22 14:00:59 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static var addFeedFolderName: String? {
|
|
|
|
|
|
get {
|
2026-10-22 14:11:46 -07:00
|
|
|
|
UserDefaults.standard.string(forKey: Key.addFeedFolderName)
|
2026-10-22 14:00:59 -07:00
|
|
|
|
}
|
|
|
|
|
|
set {
|
2026-10-22 14:11:46 -07:00
|
|
|
|
UserDefaults.standard.set(newValue, forKey: Key.addFeedFolderName)
|
2026-10-22 14:00:59 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static var addFolderAccountID: String? {
|
|
|
|
|
|
get {
|
2026-10-22 14:11:46 -07:00
|
|
|
|
UserDefaults.standard.string(forKey: Key.addFolderAccountID)
|
2026-10-22 14:00:59 -07:00
|
|
|
|
}
|
|
|
|
|
|
set {
|
2026-10-22 14:11:46 -07:00
|
|
|
|
UserDefaults.standard.set(newValue, forKey: Key.addFolderAccountID)
|
2026-10-22 14:00:59 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static var currentThemeName: String? {
|
|
|
|
|
|
get {
|
2026-10-22 14:11:46 -07:00
|
|
|
|
UserDefaults.standard.string(forKey: Key.currentThemeName)
|
2026-10-22 14:00:59 -07:00
|
|
|
|
}
|
|
|
|
|
|
set {
|
2026-10-22 14:11:46 -07:00
|
|
|
|
UserDefaults.standard.set(newValue, forKey: Key.currentThemeName)
|
2026-10-22 14:00:59 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static var isArticleContentJavascriptEnabled: Bool {
|
|
|
|
|
|
get {
|
2026-10-22 14:11:46 -07:00
|
|
|
|
UserDefaults.standard.bool(forKey: Key.articleContentJavascriptEnabled)
|
2026-10-22 14:00:59 -07:00
|
|
|
|
}
|
|
|
|
|
|
set {
|
2026-10-22 14:11:46 -07:00
|
|
|
|
UserDefaults.standard.set(newValue, forKey: Key.articleContentJavascriptEnabled)
|
2026-10-22 14:00:59 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static var unreadCountDisplay: UnreadCountDisplay {
|
|
|
|
|
|
get {
|
2026-10-22 14:11:46 -07:00
|
|
|
|
UnreadCountDisplay(rawValue: UserDefaults.standard.integer(forKey: Key.unreadCountDisplay)) ?? .count
|
2026-10-22 14:00:59 -07:00
|
|
|
|
}
|
|
|
|
|
|
set {
|
2026-10-22 14:11:46 -07:00
|
|
|
|
UserDefaults.standard.set(newValue.rawValue, forKey: Key.unreadCountDisplay)
|
2026-10-26 14:31:16 -07:00
|
|
|
|
NotificationCenter.default.post(name: .unreadCountDisplaySettingDidChange, object: nil)
|
2026-10-22 14:00:59 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-10-26 10:11:55 -07:00
|
|
|
|
|
|
|
|
|
|
static var timelineThumbnailsDisplay: TimelineThumbnailsDisplay {
|
|
|
|
|
|
get {
|
|
|
|
|
|
TimelineThumbnailsDisplay(rawValue: UserDefaults.standard.integer(forKey: Key.timelineThumbnailsDisplay)) ?? .small
|
|
|
|
|
|
}
|
|
|
|
|
|
set {
|
|
|
|
|
|
UserDefaults.standard.set(newValue.rawValue, forKey: Key.timelineThumbnailsDisplay)
|
|
|
|
|
|
NotificationCenter.default.post(name: .timelineThumbnailsDisplayDidChange, object: nil)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-10-26 11:36:44 -07:00
|
|
|
|
|
|
|
|
|
|
static var timelineFeedIconsDisplay: TimelineFeedIconsDisplay {
|
|
|
|
|
|
get {
|
|
|
|
|
|
TimelineFeedIconsDisplay(rawValue: UserDefaults.standard.integer(forKey: Key.timelineFeedIconsDisplay)) ?? .automatic
|
|
|
|
|
|
}
|
|
|
|
|
|
set {
|
|
|
|
|
|
UserDefaults.standard.set(newValue.rawValue, forKey: Key.timelineFeedIconsDisplay)
|
|
|
|
|
|
NotificationCenter.default.post(name: .timelineFeedIconsDisplayDidChange, object: nil)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-10-22 14:00:59 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// MARK: - Helpers
|
|
|
|
|
|
|
|
|
|
|
|
extension AppDefaults {
|
|
|
|
|
|
|
|
|
|
|
|
static func date(for key: String) -> Date? {
|
2026-10-22 14:02:53 -07:00
|
|
|
|
UserDefaults.standard.object(forKey: key) as? Date
|
2026-10-22 14:00:59 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static func setDate(for key: String, _ date: Date?) {
|
|
|
|
|
|
UserDefaults.standard.set(date, forKey: key)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static func sortDirection(for key: String) -> ComparisonResult {
|
2026-10-22 14:11:46 -07:00
|
|
|
|
let rawInt = UserDefaults.standard.integer(forKey: key)
|
2026-10-22 14:00:59 -07:00
|
|
|
|
if rawInt == ComparisonResult.orderedAscending.rawValue {
|
|
|
|
|
|
return .orderedAscending
|
|
|
|
|
|
}
|
|
|
|
|
|
return .orderedDescending
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private extension AppDefaults {
|
|
|
|
|
|
|
|
|
|
|
|
static var firstRunDate: Date? {
|
|
|
|
|
|
get {
|
2026-10-22 14:02:53 -07:00
|
|
|
|
date(for: Key.firstRunDate)
|
2026-10-22 14:00:59 -07:00
|
|
|
|
}
|
|
|
|
|
|
set {
|
|
|
|
|
|
setDate(for: Key.firstRunDate, newValue)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|