From 2ce850441b27a2eb5e5b2090c94f7b7615a3264e Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Thu, 22 Oct 2026 13:46:32 -0700 Subject: [PATCH] Make AppDefaults an enum instead of singleton class. --- Mac/AppDefaults.swift | 82 +++++++------- Mac/AppDelegate.swift | 38 +++---- Mac/Browser.swift | 6 +- .../AddFolder/AddFolderWindowController.swift | 4 +- .../Detail/DetailWebViewController.swift | 14 +-- Mac/MainWindow/MainWindowController.swift | 24 ++-- .../NNW3/NNW3ImportController.swift | 2 +- ...NNW3OpenPanelAccessoryViewController.swift | 2 +- .../OPML/ExportOPMLWindowController.swift | 4 +- .../OPML/ImportOPMLWindowController.swift | 4 +- Mac/MainWindow/Sidebar/Cell/SidebarCell.swift | 2 +- .../Sidebar/SidebarViewController.swift | 2 +- Mac/MainWindow/Sidebar/UnreadCountView.swift | 4 +- .../StatusBar/MainWindowStatusBarView.swift | 8 +- .../Cell/TimelineCellAppearance.swift | 2 +- .../TimelineContainerViewController.swift | 8 +- Mac/MainWindow/Timeline/TimelineLayout.swift | 2 +- .../Timeline/TimelineTableRowView.swift | 2 +- .../TimelineViewController+ColumnLayout.swift | 4 +- .../Timeline/TimelineViewController.swift | 4 +- .../Accounts/AddAccountHelpView.swift | 2 +- .../Accounts/AddAccountsView.swift | 4 +- .../GeneralPrefencesViewController.swift | 12 +- Shared/AppDefaults+Shared.swift | 2 +- .../Article Rendering/ArticleRenderer.swift | 2 +- .../WebViewConfiguration.swift | 2 +- .../ArticleStyles/ArticleThemesManager.swift | 4 +- .../Extensions/AddFeedDefaultContainer.swift | 10 +- Shared/Extensions/CacheCleaner.swift | 6 +- .../ShareDefaultContainer.swift | 10 +- Shared/Timer/AccountRefreshTimer.swift | 4 +- Shared/Widget/WidgetDataEncoder.swift | 2 +- iOS/Add/AddFolderView.swift | 4 +- iOS/AppDefaults.swift | 105 +++++++++--------- iOS/AppDelegate.swift | 8 +- iOS/Article/ArticleViewController.swift | 8 +- iOS/Article/WebViewController.swift | 30 ++--- iOS/HidingReadArticlesState.swift | 6 +- ...MainFeedCollectionHeaderReusableView.swift | 4 +- .../MainFeedCollectionViewCell.swift | 4 +- .../MainFeedCollectionViewFolderCell.swift | 4 +- .../UILabel+UnreadCount.swift | 2 +- .../MainTimelineViewController.swift | 12 +- .../MarkAsReadAlertController.swift | 2 +- iOS/SceneCoordinator.swift | 36 +++--- iOS/SceneDelegate.swift | 4 +- iOS/Settings/AddAccountView.swift | 2 +- iOS/Settings/SettingsViewController.swift | 44 ++++---- iOS/Settings/TimelineCustomizerCell.swift | 8 +- ...neCustomizerCollectionViewController.swift | 20 ++-- 50 files changed, 287 insertions(+), 294 deletions(-) diff --git a/Mac/AppDefaults.swift b/Mac/AppDefaults.swift index fd5ee3e85..015d5b839 100644 --- a/Mac/AppDefaults.swift +++ b/Mac/AppDefaults.swift @@ -34,12 +34,10 @@ enum StatusBarCountMode: Int { } } -final class AppDefaults: Sendable { +enum AppDefaults { static let defaultThemeName = "Default" - static let shared = AppDefaults() - struct Key { static let firstRunDate = "firstRunDate" static let legacyWindowState = "windowState" @@ -80,14 +78,14 @@ final class AppDefaults: Sendable { private static let smallestFontSizeRawValue = FontSize.small.rawValue private static let largestFontSizeRawValue = FontSize.veryLarge.rawValue - let isDeveloperBuild: Bool = { + static let isDeveloperBuild: Bool = { if let dev = Bundle.main.object(forInfoDictionaryKey: "DeveloperEntitlements") as? String, dev == "-dev" { return true } return false }() - let isFirstRun: Bool = { + static let isFirstRun: Bool = { if UserDefaults.standard.object(forKey: Key.firstRunDate) is Date { return false } @@ -99,15 +97,15 @@ final class AppDefaults: Sendable { /// /// This is referenced temporarily, only to be able to provide migration from legacy to secure window state. /// TODO: delete for NetNewsWire 7. - var legacyWindowState: [AnyHashable: Any]? { + static var legacyWindowState: [AnyHashable: Any]? { UserDefaults.standard.object(forKey: Key.legacyWindowState) as? [AnyHashable: Any] } - func deleteLegacyWindowState() { + static func deleteLegacyWindowState() { UserDefaults.standard.removeObject(forKey: Key.legacyWindowState) } - var secureWindowState: Data? { + static var secureWindowState: Data? { get { UserDefaults.standard.object(forKey: Key.secureWindowState) as? Data } @@ -116,7 +114,7 @@ final class AppDefaults: Sendable { } } - var lastImageCacheFlushDate: Date? { + static var lastImageCacheFlushDate: Date? { get { return AppDefaults.date(for: Key.lastImageCacheFlushDate) } @@ -125,7 +123,7 @@ final class AppDefaults: Sendable { } } - var openInBrowserInBackground: Bool { + static var openInBrowserInBackground: Bool { get { return AppDefaults.bool(for: Key.openInBrowserInBackground) } @@ -136,7 +134,7 @@ final class AppDefaults: Sendable { // Special case for this default: store/retrieve it from the shared app group // defaults, so that it can be resolved by the Safari App Extension. - var subscribeToFeedDefaults: UserDefaults { + static var subscribeToFeedDefaults: UserDefaults { if let appGroupID = Bundle.main.object(forInfoDictionaryKey: "AppGroup") as? String, let appGroupDefaults = UserDefaults(suiteName: appGroupID) { return appGroupDefaults @@ -145,7 +143,7 @@ final class AppDefaults: Sendable { } } - var subscribeToFeedsInDefaultBrowser: Bool { + static var subscribeToFeedsInDefaultBrowser: Bool { get { return subscribeToFeedDefaults.bool(forKey: Key.subscribeToFeedsInDefaultBrowser) } @@ -154,7 +152,7 @@ final class AppDefaults: Sendable { } } - var sidebarFontSize: FontSize { + static var sidebarFontSize: FontSize { get { return fontSize(for: Key.sidebarFontSize) } @@ -163,7 +161,7 @@ final class AppDefaults: Sendable { } } - var timelineFontSize: FontSize { + static var timelineFontSize: FontSize { get { return fontSize(for: Key.timelineFontSize) } @@ -172,7 +170,7 @@ final class AppDefaults: Sendable { } } - var detailFontSize: FontSize { + static var detailFontSize: FontSize { get { return fontSize(for: Key.detailFontSize) } @@ -181,7 +179,7 @@ final class AppDefaults: Sendable { } } - var addFeedAccountID: String? { + static var addFeedAccountID: String? { get { return AppDefaults.string(for: Key.addFeedAccountID) } @@ -190,7 +188,7 @@ final class AppDefaults: Sendable { } } - var addFeedFolderName: String? { + static var addFeedFolderName: String? { get { return AppDefaults.string(for: Key.addFeedFolderName) } @@ -199,7 +197,7 @@ final class AppDefaults: Sendable { } } - var addFolderAccountID: String? { + static var addFolderAccountID: String? { get { return AppDefaults.string(for: Key.addFolderAccountID) } @@ -208,7 +206,7 @@ final class AppDefaults: Sendable { } } - var importOPMLAccountID: String? { + static var importOPMLAccountID: String? { get { return AppDefaults.string(for: Key.importOPMLAccountID) } @@ -217,7 +215,7 @@ final class AppDefaults: Sendable { } } - var exportOPMLAccountID: String? { + static var exportOPMLAccountID: String? { get { return AppDefaults.string(for: Key.exportOPMLAccountID) } @@ -226,7 +224,7 @@ final class AppDefaults: Sendable { } } - var defaultBrowserID: String? { + static var defaultBrowserID: String? { get { return AppDefaults.string(for: Key.defaultBrowserID) } @@ -235,7 +233,7 @@ final class AppDefaults: Sendable { } } - var currentThemeName: String? { + static var currentThemeName: String? { get { return AppDefaults.string(for: Key.currentThemeName) } @@ -244,15 +242,15 @@ final class AppDefaults: Sendable { } } - var showTitleOnMainWindow: Bool { + static var showTitleOnMainWindow: Bool { return AppDefaults.bool(for: Key.showTitleOnMainWindow) } - var showDebugMenu: Bool { + static var showDebugMenu: Bool { return AppDefaults.bool(for: Key.showDebugMenu) } - var feedDoubleClickMarkAsRead: Bool { + static var feedDoubleClickMarkAsRead: Bool { get { return AppDefaults.bool(for: Key.feedDoubleClickMarkAsRead) } @@ -261,7 +259,7 @@ final class AppDefaults: Sendable { } } - var suppressSyncOnLaunch: Bool { + static var suppressSyncOnLaunch: Bool { get { return AppDefaults.bool(for: Key.suppressSyncOnLaunch) } @@ -270,7 +268,7 @@ final class AppDefaults: Sendable { } } - var webInspectorEnabled: Bool { + static var webInspectorEnabled: Bool { get { return AppDefaults.bool(for: Key.webInspectorEnabled) } @@ -279,7 +277,7 @@ final class AppDefaults: Sendable { } } - var webInspectorStartsAttached: Bool { + static var webInspectorStartsAttached: Bool { get { return AppDefaults.bool(for: Key.webInspectorStartsAttached) } @@ -290,16 +288,16 @@ final class AppDefaults: Sendable { // Sorting is per window and lives in TimelineWindowState. These two are read-only seeds // for a window that has no saved sort, so a setting from before per-window sorting carries over. - var timelineSortDirection: ComparisonResult { + static var timelineSortDirection: ComparisonResult { AppDefaults.sortDirection(for: Key.timelineSortDirection) } - var timelineGroupByFeed: Bool { + static var timelineGroupByFeed: Bool { AppDefaults.bool(for: Key.timelineGroupByFeed) } /// Column layout: multi-column timeline table with the article view below it, like Mail’s View > Use Column Layout. Applies to all windows. - var useColumnLayout: Bool { + static var useColumnLayout: Bool { get { AppDefaults.bool(for: Key.useColumnLayout) } @@ -309,7 +307,7 @@ final class AppDefaults: Sendable { } /// The main window status bar. Applies to all windows. - var showStatusBar: Bool { + static var showStatusBar: Bool { get { AppDefaults.bool(for: Key.showStatusBar) } @@ -329,7 +327,7 @@ final class AppDefaults: Sendable { return true } - var showStatusBarThemeMenu: Bool { + static var showStatusBarThemeMenu: Bool { get { AppDefaults.bool(for: Key.showStatusBarThemeMenu) } @@ -338,7 +336,7 @@ final class AppDefaults: Sendable { } } - var statusBarCountMode: StatusBarCountMode { + static var statusBarCountMode: StatusBarCountMode { get { StatusBarCountMode(rawValue: AppDefaults.int(for: Key.statusBarCountMode)) ?? .lastRefresh } @@ -347,11 +345,11 @@ final class AppDefaults: Sendable { } } - var timelineShowsSeparators: Bool { + static var timelineShowsSeparators: Bool { return AppDefaults.bool(for: Key.timelineShowsSeparators) } - var articleTextSize: ArticleTextSize { + static var articleTextSize: ArticleTextSize { get { let rawValue = UserDefaults.standard.integer(forKey: Key.articleTextSize) return ArticleTextSize(rawValue: rawValue) ?? ArticleTextSize.large @@ -361,7 +359,7 @@ final class AppDefaults: Sendable { } } - var refreshInterval: RefreshInterval { + static var refreshInterval: RefreshInterval { get { let rawValue = UserDefaults.standard.integer(forKey: Key.refreshInterval) if rawValue == 2 { // Old every-10-minutes setting — now using 30 minutes as minimum. @@ -374,7 +372,7 @@ final class AppDefaults: Sendable { } } - var isArticleContentJavascriptEnabled: Bool { + static var isArticleContentJavascriptEnabled: Bool { get { UserDefaults.standard.bool(forKey: Key.articleContentJavascriptEnabled) } @@ -383,15 +381,13 @@ final class AppDefaults: Sendable { } } - init() { + @MainActor static func registerDefaults() { // Migrate every-10-minute refresh interval to 30 minutes. let rawValue = UserDefaults.standard.integer(forKey: Key.refreshInterval) if rawValue == 2 { UserDefaults.standard.set(RefreshInterval.every30Minutes.rawValue, forKey: Key.refreshInterval) } - } - @MainActor func registerDefaults() { #if DEBUG let showDebugMenu = true #else @@ -418,7 +414,7 @@ final class AppDefaults: Sendable { UserDefaults.standard.register(defaults: defaults) } - func actualFontSize(for fontSize: FontSize) -> CGFloat { + static func actualFontSize(for fontSize: FontSize) -> CGFloat { switch fontSize { case .small: return NSFont.systemFontSize @@ -443,7 +439,7 @@ private extension AppDefaults { } } - func fontSize(for key: String) -> FontSize { + static func fontSize(for key: String) -> FontSize { // Punted till after 1.0. return .medium diff --git a/Mac/AppDelegate.swift b/Mac/AppDelegate.swift index 1873f817d..3e8f99930 100644 --- a/Mac/AppDelegate.swift +++ b/Mac/AppDelegate.swift @@ -37,7 +37,7 @@ let appName = "NetNewsWire" } private var refreshTimer: AccountRefreshTimer? - private var lastRefreshInterval = AppDefaults.shared.refreshInterval + private var lastRefreshInterval = AppDefaults.refreshInterval private var shuttingDown = false { didSet { @@ -194,8 +194,8 @@ let appName = "NetNewsWire" Self.logger.error("Failed to start software updater with error: \(error.localizedDescription)") } - AppDefaults.shared.registerDefaults() - let isFirstRun = AppDefaults.shared.isFirstRun + AppDefaults.registerDefaults() + let isFirstRun = AppDefaults.isFirstRun if isFirstRun { Self.logger.debug("Is first run.") } @@ -274,7 +274,7 @@ let appName = "NetNewsWire" refreshTimer!.update() ArticleStatusSyncTimer.shared.update() #else - if AppDefaults.shared.suppressSyncOnLaunch { + if AppDefaults.suppressSyncOnLaunch { refreshTimer!.update() ArticleStatusSyncTimer.shared.update() } else { @@ -285,7 +285,7 @@ let appName = "NetNewsWire" } #endif - if !AppDefaults.shared.showDebugMenu { + if !AppDefaults.showDebugMenu { debugMenuItem.menu?.removeItem(debugMenuItem) } @@ -404,9 +404,9 @@ let appName = "NetNewsWire" updateColumnLayoutMenuItem() updateStatusBarMenuItems() - if lastRefreshInterval != AppDefaults.shared.refreshInterval { + if lastRefreshInterval != AppDefaults.refreshInterval { refreshTimer?.update() - lastRefreshInterval = AppDefaults.shared.refreshInterval + lastRefreshInterval = AppDefaults.refreshInterval } updateDockBadge() @@ -506,11 +506,11 @@ let appName = "NetNewsWire" } if item.action == #selector(toggleStatusBarThemeMenu(_:)) { - return AppDefaults.shared.showStatusBar + return AppDefaults.showStatusBar } if item.action == #selector(toggleWebInspectorEnabled(_:)) { - (item as! NSMenuItem).state = AppDefaults.shared.webInspectorEnabled ? .on : .off + (item as! NSMenuItem).state = AppDefaults.webInspectorEnabled ? .on : .off } return true @@ -571,7 +571,7 @@ let appName = "NetNewsWire" // MARK: - Dock Badge @objc func updateDockBadge() { Task { @MainActor in - NSApplication.shared.dockTile.badgeLabel = AppDefaults.shared.unreadCountDisplay.text(for: unreadCount) ?? "" + NSApplication.shared.dockTile.badgeLabel = AppDefaults.unreadCountDisplay.text(for: unreadCount) ?? "" } } @@ -770,15 +770,15 @@ let appName = "NetNewsWire" } @IBAction func toggleColumnLayout(_ sender: Any?) { - AppDefaults.shared.useColumnLayout.toggle() + AppDefaults.useColumnLayout.toggle() } @IBAction func toggleStatusBar(_ sender: Any?) { - AppDefaults.shared.showStatusBar.toggle() + AppDefaults.showStatusBar.toggle() } @IBAction func toggleStatusBarThemeMenu(_ sender: Any?) { - AppDefaults.shared.showStatusBarThemeMenu.toggle() + AppDefaults.showStatusBarThemeMenu.toggle() } @IBAction func checkForUpdates(_ sender: Any?) { @@ -827,13 +827,13 @@ extension AppDelegate { } @IBAction func toggleWebInspectorEnabled(_ sender: Any?) { - let newValue = !AppDefaults.shared.webInspectorEnabled - AppDefaults.shared.webInspectorEnabled = newValue + let newValue = !AppDefaults.webInspectorEnabled + AppDefaults.webInspectorEnabled = newValue // An attached inspector can display incorrectly on certain setups (like mine); default to displaying in a separate window, // and reset the default to a separate window when the preference is toggled off and on again in case the inspector is // accidentally reattached. - AppDefaults.shared.webInspectorStartsAttached = false + AppDefaults.webInspectorStartsAttached = false NotificationCenter.default.post(name: .WebInspectorEnabledDidChange, object: newValue) } @@ -897,16 +897,16 @@ extension AppDelegate { } @MainActor func updateColumnLayoutMenuItem() { - useColumnLayoutMenuItem?.state = AppDefaults.shared.useColumnLayout ? .on : .off + useColumnLayoutMenuItem?.state = AppDefaults.useColumnLayout ? .on : .off } @MainActor func updateStatusBarMenuItems() { - if AppDefaults.shared.showStatusBar { + if AppDefaults.showStatusBar { showStatusBarMenuItem?.title = NSLocalizedString("Hide Status Bar", comment: "Command") } else { showStatusBarMenuItem?.title = NSLocalizedString("Show Status Bar", comment: "Command") } - if AppDefaults.shared.showStatusBarThemeMenu { + if AppDefaults.showStatusBarThemeMenu { showStatusBarThemeMenuMenuItem?.title = NSLocalizedString("Hide Theme Menu in Status Bar", comment: "Command") } else { showStatusBarThemeMenuMenuItem?.title = NSLocalizedString("Show Theme Menu in Status Bar", comment: "Command") diff --git a/Mac/Browser.swift b/Mac/Browser.swift index 66f3c721a..862b15e2a 100644 --- a/Mac/Browser.swift +++ b/Mac/Browser.swift @@ -15,7 +15,7 @@ import RSWeb /// The user-assigned default browser, or `nil` if none was assigned /// (i.e., the system default should be used). static var defaultBrowser: MacWebBrowser? { - guard let browserID = AppDefaults.shared.defaultBrowserID else { + guard let browserID = AppDefaults.defaultBrowserID else { return nil } // Older versions stored a bundle ID rather than a path. @@ -33,7 +33,7 @@ import RSWeb /// - invert: Whether to invert the "open in background in browser" preference static func open(_ urlString: String, invertPreference invert: Bool = false) { // Opens according to prefs. - open(urlString, inBackground: invert ? !AppDefaults.shared.openInBrowserInBackground : AppDefaults.shared.openInBrowserInBackground) + open(urlString, inBackground: invert ? !AppDefaults.openInBrowserInBackground : AppDefaults.openInBrowserInBackground) } /// Opens a URL in the default browser. @@ -77,7 +77,7 @@ import RSWeb extension Browser { static var titleForOpenInBrowserInverted: String { - let openInBackgroundPref = AppDefaults.shared.openInBrowserInBackground + let openInBackgroundPref = AppDefaults.openInBrowserInBackground return openInBackgroundPref ? NSLocalizedString("Open in Browser in Foreground", comment: "Open in Browser in Foreground menu item title") : diff --git a/Mac/MainWindow/AddFolder/AddFolderWindowController.swift b/Mac/MainWindow/AddFolder/AddFolderWindowController.swift index 0e9c1626d..c6c1be926 100644 --- a/Mac/MainWindow/AddFolder/AddFolderWindowController.swift +++ b/Mac/MainWindow/AddFolder/AddFolderWindowController.swift @@ -40,7 +40,7 @@ final class AddFolderWindowController: NSWindowController { // MARK: - NSViewController override func windowDidLoad() { - let preferredAccountID = AppDefaults.shared.addFolderAccountID + let preferredAccountID = AppDefaults.addFolderAccountID accountPopupButton.removeAllItems() let menu = NSMenu() @@ -104,7 +104,7 @@ private extension AddFolderWindowController { } let account = menuItem.representedObject as! Account - AppDefaults.shared.addFolderAccountID = account.accountID + AppDefaults.addFolderAccountID = account.accountID let folderName = self.folderNameTextField.stringValue if folderName.isEmpty { diff --git a/Mac/MainWindow/Detail/DetailWebViewController.swift b/Mac/MainWindow/Detail/DetailWebViewController.swift index 8c20ff318..83c1d9bf1 100644 --- a/Mac/MainWindow/Detail/DetailWebViewController.swift +++ b/Mac/MainWindow/Detail/DetailWebViewController.swift @@ -54,8 +54,8 @@ final class DetailWebViewController: NSViewController { } } - private var articleTextSize = AppDefaults.shared.articleTextSize - private var isArticleContentJavascriptEnabled = AppDefaults.shared.isArticleContentJavascriptEnabled + private var articleTextSize = AppDefaults.articleTextSize + private var isArticleContentJavascriptEnabled = AppDefaults.isArticleContentJavascriptEnabled private var webInspectorEnabled: Bool { get { @@ -144,12 +144,12 @@ final class DetailWebViewController: NSViewController { } func userDefaultsDidChange() { - if articleTextSize != AppDefaults.shared.articleTextSize { - articleTextSize = AppDefaults.shared.articleTextSize + if articleTextSize != AppDefaults.articleTextSize { + articleTextSize = AppDefaults.articleTextSize reloadHTMLMaintainingScrollPosition() } - if isArticleContentJavascriptEnabled != AppDefaults.shared.isArticleContentJavascriptEnabled { - isArticleContentJavascriptEnabled = AppDefaults.shared.isArticleContentJavascriptEnabled + if isArticleContentJavascriptEnabled != AppDefaults.isArticleContentJavascriptEnabled { + isArticleContentJavascriptEnabled = AppDefaults.isArticleContentJavascriptEnabled reloadHTMLMaintainingScrollPosition() } } @@ -329,7 +329,7 @@ private extension DetailWebViewController { webView.navigationDelegate = self webView.keyboardDelegate = keyboardDelegate webView.autoresizingMask = [.width, .height] - webView.configuration.preferences._developerExtrasEnabled = AppDefaults.shared.webInspectorEnabled + webView.configuration.preferences._developerExtrasEnabled = AppDefaults.webInspectorEnabled return webView } diff --git a/Mac/MainWindow/MainWindowController.swift b/Mac/MainWindow/MainWindowController.swift index 37c19daca..24604b350 100644 --- a/Mac/MainWindow/MainWindowController.swift +++ b/Mac/MainWindow/MainWindowController.swift @@ -53,7 +53,7 @@ final class MainWindowController: NSWindowController, NSUserInterfaceValidations private var splitViewController: NSSplitViewController? // Column layout only: the vertical split holding the timeline above the article view. private var contentSplitViewController: NSSplitViewController? - private var timelineLayout = AppDefaults.shared.timelineLayout + private var timelineLayout = AppDefaults.timelineLayout // Geometry for the layout that isn’t showing, so a round trip through the other layout keeps it. private var rememberedStandardLayoutWidths = [Int]() private var rememberedColumnLayoutTimelineHeight = 0 @@ -168,7 +168,7 @@ final class MainWindowController: NSWindowController, NSUserInterfaceValidations let state = savableState() Self.logger.debug("MainWindowController: Saving state to UserDefaults: \(state)") let data = try? NSKeyedArchiver.archivedData(withRootObject: state, requiringSecureCoding: true) - AppDefaults.shared.secureWindowState = data + AppDefaults.secureWindowState = data // Don't save the frame in full screen — it would replace the saved windowed frame with the screen's frame. if let window, !window.styleMask.contains(.fullScreen) { window.saveFrame(usingName: windowAutosaveName) @@ -176,16 +176,16 @@ final class MainWindowController: NSWindowController, NSUserInterfaceValidations } func restoreStateFromUserDefaults() { - if let data = AppDefaults.shared.secureWindowState, + if let data = AppDefaults.secureWindowState, let state = try? NSKeyedUnarchiver.unarchivedObject(ofClass: MainWindowState.self, from: data) { Self.logger.debug("MainWindowController: restoring state from UserDefaults: \(state)") window?.setFrameUsingName(windowAutosaveName, force: true) restoreState(from: state) - } else if let state = AppDefaults.shared.legacyWindowState { + } else if let state = AppDefaults.legacyWindowState { // Migrate from previous window state data. Delete data when finished. window?.setFrameUsingName(windowAutosaveName, force: true) restoreLegacyState(from: state) - AppDefaults.shared.deleteLegacyWindowState() + AppDefaults.deleteLegacyWindowState() } } @@ -198,7 +198,7 @@ final class MainWindowController: NSWindowController, NSUserInterfaceValidations } private func userDefaultsDidChange() { - let layout = AppDefaults.shared.timelineLayout + let layout = AppDefaults.timelineLayout if layout != timelineLayout { installSplitViewController(for: layout) } @@ -415,7 +415,7 @@ final class MainWindowController: NSWindowController, NSUserInterfaceValidations } @IBAction func openInBrowser(_ sender: Any?) { - if AppDefaults.shared.openInBrowserInBackground { + if AppDefaults.openInBrowserInBackground { window?.makeKeyAndOrderFront(self) } openArticleInBrowser(sender) @@ -427,11 +427,11 @@ final class MainWindowController: NSWindowController, NSUserInterfaceValidations } @IBAction func openInBrowserUsingOppositeOfSettings(_ sender: Any?) { - if !AppDefaults.shared.openInBrowserInBackground { + if !AppDefaults.openInBrowserInBackground { window?.makeKeyAndOrderFront(self) } if let link = currentLink { - Browser.open(link, inBackground: !AppDefaults.shared.openInBrowserInBackground) + Browser.open(link, inBackground: !AppDefaults.openInBrowserInBackground) } } @@ -1547,7 +1547,7 @@ private extension MainWindowController { } func validateToggleArticleExtractor(_ item: NSValidatedUserInterfaceItem) -> Bool { - guard !AppDefaults.shared.isDeveloperBuild else { + guard !AppDefaults.isDeveloperBuild else { return false } @@ -1726,7 +1726,7 @@ private extension MainWindowController { } func setSubtitle(_ count: Int) { - guard AppDefaults.shared.unreadCountDisplay == .count else { + guard AppDefaults.unreadCountDisplay == .count else { window?.subtitle = "" return } @@ -1855,7 +1855,7 @@ private extension MainWindowController { /// The status bar, when showing, takes the place of the detail view’s floating link overlay and the sidebar’s progress view. func updateStatusBarVisibility() { - let showStatusBar = AppDefaults.shared.showStatusBar + let showStatusBar = AppDefaults.showStatusBar mainWindowContentViewController.isStatusBarHidden = !showStatusBar detailViewController?.showsMouseoverLinkOverlay = !showStatusBar sidebarViewController?.showsProgressView = !showStatusBar diff --git a/Mac/MainWindow/NNW3/NNW3ImportController.swift b/Mac/MainWindow/NNW3/NNW3ImportController.swift index 3e51eabb0..0d94f8625 100644 --- a/Mac/MainWindow/NNW3/NNW3ImportController.swift +++ b/Mac/MainWindow/NNW3/NNW3ImportController.swift @@ -82,7 +82,7 @@ private extension NNW3ImportController { guard let account = accessoryViewController.selectedAccount else { return } - AppDefaults.shared.importOPMLAccountID = account.accountID + AppDefaults.importOPMLAccountID = account.accountID NNW3ImportController.importSubscriptionsPlist(subscriptionsPlistURL, into: account) } diff --git a/Mac/MainWindow/NNW3/NNW3OpenPanelAccessoryViewController.swift b/Mac/MainWindow/NNW3/NNW3OpenPanelAccessoryViewController.swift index c62c6f1b4..73f681b84 100644 --- a/Mac/MainWindow/NNW3/NNW3OpenPanelAccessoryViewController.swift +++ b/Mac/MainWindow/NNW3/NNW3OpenPanelAccessoryViewController.swift @@ -43,7 +43,7 @@ final class NNW3OpenPanelAccessoryViewController: NSViewController { menuItem.representedObject = account menu.addItem(menuItem) - if account.accountID == AppDefaults.shared.importOPMLAccountID { + if account.accountID == AppDefaults.importOPMLAccountID { accountPopUpButton.select(menuItem) } } diff --git a/Mac/MainWindow/OPML/ExportOPMLWindowController.swift b/Mac/MainWindow/OPML/ExportOPMLWindowController.swift index e6a54407b..4f0b27d70 100644 --- a/Mac/MainWindow/OPML/ExportOPMLWindowController.swift +++ b/Mac/MainWindow/OPML/ExportOPMLWindowController.swift @@ -27,7 +27,7 @@ final class ExportOPMLWindowController: NSWindowController { accountPopUpButton.menu = menu let accounts: [Account] = AccountManager.shared.sortedAccounts - let savedAccountID: String? = AppDefaults.shared.exportOPMLAccountID + let savedAccountID: String? = AppDefaults.exportOPMLAccountID for oneAccount in accounts { addMenuItem(to: menu, for: oneAccount, savedAccountID: savedAccountID) @@ -75,7 +75,7 @@ final class ExportOPMLWindowController: NSWindowController { } let account = menuItem.representedObject as! Account - AppDefaults.shared.exportOPMLAccountID = account.accountID + AppDefaults.exportOPMLAccountID = account.accountID hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.OK) exportOPML(account: account) diff --git a/Mac/MainWindow/OPML/ImportOPMLWindowController.swift b/Mac/MainWindow/OPML/ImportOPMLWindowController.swift index 7f68d6ab3..e323f9eab 100644 --- a/Mac/MainWindow/OPML/ImportOPMLWindowController.swift +++ b/Mac/MainWindow/OPML/ImportOPMLWindowController.swift @@ -26,7 +26,7 @@ final class ImportOPMLWindowController: NSWindowController { accountPopUpButton.menu = menu let accounts: [Account] = AccountManager.shared.sortedActiveAccounts - let savedAccountID: String? = AppDefaults.shared.importOPMLAccountID + let savedAccountID: String? = AppDefaults.importOPMLAccountID for oneAccount in accounts { if oneAccount.behaviors.contains(.disallowOPMLImports) { @@ -77,7 +77,7 @@ final class ImportOPMLWindowController: NSWindowController { } let account = menuItem.representedObject as! Account - AppDefaults.shared.importOPMLAccountID = account.accountID + AppDefaults.importOPMLAccountID = account.accountID hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.OK) importOPML(account: account) diff --git a/Mac/MainWindow/Sidebar/Cell/SidebarCell.swift b/Mac/MainWindow/Sidebar/Cell/SidebarCell.swift index 391a4d5cf..0f4590184 100644 --- a/Mac/MainWindow/Sidebar/Cell/SidebarCell.swift +++ b/Mac/MainWindow/Sidebar/Cell/SidebarCell.swift @@ -119,7 +119,7 @@ final class SidebarCell: NSTableCellView { } override func accessibilityLabel() -> String? { - guard let unreadText = AppDefaults.shared.unreadCountDisplay.accessibilityText(for: unreadCount) else { + guard let unreadText = AppDefaults.unreadCountDisplay.accessibilityText(for: unreadCount) else { return name } return "\(name) \(unreadText)" diff --git a/Mac/MainWindow/Sidebar/SidebarViewController.swift b/Mac/MainWindow/Sidebar/SidebarViewController.swift index 0b86f144d..0d65a2ec2 100644 --- a/Mac/MainWindow/Sidebar/SidebarViewController.swift +++ b/Mac/MainWindow/Sidebar/SidebarViewController.swift @@ -339,7 +339,7 @@ extension Notification.Name { guard outlineView.clickedRow == outlineView.selectedRow else { return } - if AppDefaults.shared.feedDoubleClickMarkAsRead, let articles = singleSelectedFeed?.fetchUnreadArticles() { + if AppDefaults.feedDoubleClickMarkAsRead, let articles = singleSelectedFeed?.fetchUnreadArticles() { if let undoManager = undoManager, let markReadCommand = MarkStatusCommand(initialArticles: Array(articles), markingRead: true, undoManager: undoManager) { runCommand(markReadCommand) } diff --git a/Mac/MainWindow/Sidebar/UnreadCountView.swift b/Mac/MainWindow/Sidebar/UnreadCountView.swift index 9e19f30b4..28ff295e3 100644 --- a/Mac/MainWindow/Sidebar/UnreadCountView.swift +++ b/Mac/MainWindow/Sidebar/UnreadCountView.swift @@ -54,11 +54,11 @@ final class UnreadCountView: NSView { } /// Text for the unread count, or nil when nothing should be drawn. var unreadCountText: String? { - AppDefaults.shared.unreadCountDisplay.text(for: unreadCount) + AppDefaults.unreadCountDisplay.text(for: unreadCount) } private var showsDot: Bool { - AppDefaults.shared.unreadCountDisplay.showsDot(for: unreadCount) + AppDefaults.unreadCountDisplay.showsDot(for: unreadCount) } var isSelected: Bool = false { diff --git a/Mac/MainWindow/StatusBar/MainWindowStatusBarView.swift b/Mac/MainWindow/StatusBar/MainWindowStatusBarView.swift index 4536f99fa..ffa4139ed 100644 --- a/Mac/MainWindow/StatusBar/MainWindowStatusBarView.swift +++ b/Mac/MainWindow/StatusBar/MainWindowStatusBarView.swift @@ -261,7 +261,7 @@ final class MainWindowStatusBarView: NSView { /// While refreshing, the label shows progress, and a click opens the Current Activity window. Otherwise a click toggles the count mode. @objc func countLabelClicked(_ sender: Any?) { if CombinedRefreshProgress.shared.progressInfo.isComplete { - AppDefaults.shared.statusBarCountMode = effectiveCountMode.next(includingUnreadCount: Self.showsUnreadCounts) + AppDefaults.statusBarCountMode = effectiveCountMode.next(includingUnreadCount: Self.showsUnreadCounts) } else { showActivityWindow(sender) } @@ -435,12 +435,12 @@ private extension MainWindowStatusBarView { } static var showsUnreadCounts: Bool { - AppDefaults.shared.unreadCountDisplay == .count + AppDefaults.unreadCountDisplay == .count } /// The saved mode, except that the unread count becomes the last refresh time when unread counts are hidden (hidden or a dot). var effectiveCountMode: StatusBarCountMode { - let mode = AppDefaults.shared.statusBarCountMode + let mode = AppDefaults.statusBarCountMode if mode == .unreadCount && !Self.showsUnreadCounts { return .lastRefresh } @@ -523,7 +523,7 @@ private extension MainWindowStatusBarView { } func updateThemePopUpButtonVisibility() { - let isHidden = !AppDefaults.shared.showStatusBarThemeMenu + let isHidden = !AppDefaults.showStatusBarThemeMenu guard themePopUpButton.isHidden != isHidden else { return } diff --git a/Mac/MainWindow/Timeline/Cell/TimelineCellAppearance.swift b/Mac/MainWindow/Timeline/Cell/TimelineCellAppearance.swift index 457919e6c..5792a9222 100644 --- a/Mac/MainWindow/Timeline/Cell/TimelineCellAppearance.swift +++ b/Mac/MainWindow/Timeline/Cell/TimelineCellAppearance.swift @@ -44,7 +44,7 @@ struct TimelineCellAppearance: Equatable { init(showIcon: Bool, fontSize: FontSize) { - let actualFontSize = AppDefaults.shared.actualFontSize(for: fontSize) + let actualFontSize = AppDefaults.actualFontSize(for: fontSize) let smallItemFontSize = floor(actualFontSize * 0.90) let largeItemFontSize = actualFontSize diff --git a/Mac/MainWindow/Timeline/TimelineContainerViewController.swift b/Mac/MainWindow/Timeline/TimelineContainerViewController.swift index eba9c5991..0fd082318 100644 --- a/Mac/MainWindow/Timeline/TimelineContainerViewController.swift +++ b/Mac/MainWindow/Timeline/TimelineContainerViewController.swift @@ -24,7 +24,7 @@ final class TimelineContainerViewController: NSViewController { @IBOutlet var containerViewTopToHeaderConstraint: NSLayoutConstraint? @IBOutlet var containerView: TimelineContainerView! - private var layout = AppDefaults.shared.timelineLayout { + private var layout = AppDefaults.timelineLayout { didSet { if layout != oldValue { layoutDidChange() @@ -116,7 +116,7 @@ final class TimelineContainerViewController: NSViewController { } private func userDefaultsDidChange() { - layout = AppDefaults.shared.timelineLayout + layout = AppDefaults.timelineLayout } // MARK: - API @@ -254,10 +254,10 @@ private extension TimelineContainerViewController { /// For a window with no saved sort. Group By Feed, from before sorting was per window, became sorting by feed. static var seedSortParameters: ArticleSortParameters { - if AppDefaults.shared.timelineGroupByFeed { + if AppDefaults.timelineGroupByFeed { return ArticleSortParameters(key: .feed, direction: .orderedAscending) } - return ArticleSortParameters(key: .date, direction: AppDefaults.shared.timelineSortDirection) + return ArticleSortParameters(key: .date, direction: AppDefaults.timelineSortDirection) } func layoutDidChange() { diff --git a/Mac/MainWindow/Timeline/TimelineLayout.swift b/Mac/MainWindow/Timeline/TimelineLayout.swift index e8eafeb11..ac4c90860 100644 --- a/Mac/MainWindow/Timeline/TimelineLayout.swift +++ b/Mac/MainWindow/Timeline/TimelineLayout.swift @@ -17,7 +17,7 @@ enum TimelineLayout { extension AppDefaults { - var timelineLayout: TimelineLayout { + static var timelineLayout: TimelineLayout { useColumnLayout ? .column : .standard } } diff --git a/Mac/MainWindow/Timeline/TimelineTableRowView.swift b/Mac/MainWindow/Timeline/TimelineTableRowView.swift index 3f7fb8cfa..8421ab8b4 100644 --- a/Mac/MainWindow/Timeline/TimelineTableRowView.swift +++ b/Mac/MainWindow/Timeline/TimelineTableRowView.swift @@ -47,7 +47,7 @@ final class TimelineTableRowView: NSTableRowView { } override func viewDidMoveToSuperview() { - if AppDefaults.shared.timelineShowsSeparators { + if AppDefaults.timelineShowsSeparators { addSeparatorView() } } diff --git a/Mac/MainWindow/Timeline/TimelineViewController+ColumnLayout.swift b/Mac/MainWindow/Timeline/TimelineViewController+ColumnLayout.swift index f7ef2326c..7f5c5dec6 100644 --- a/Mac/MainWindow/Timeline/TimelineViewController+ColumnLayout.swift +++ b/Mac/MainWindow/Timeline/TimelineViewController+ColumnLayout.swift @@ -27,12 +27,12 @@ extension TimelineViewController { } var columnFont: NSFont { - NSFont.systemFont(ofSize: AppDefaults.shared.actualFontSize(for: AppDefaults.shared.timelineFontSize)) + NSFont.systemFont(ofSize: AppDefaults.actualFontSize(for: AppDefaults.timelineFontSize)) } // Unread rows are bold, like Mail. var boldColumnFont: NSFont { - NSFont.boldSystemFont(ofSize: AppDefaults.shared.actualFontSize(for: AppDefaults.shared.timelineFontSize)) + NSFont.boldSystemFont(ofSize: AppDefaults.actualFontSize(for: AppDefaults.timelineFontSize)) } func columnRowHeight() -> CGFloat { diff --git a/Mac/MainWindow/Timeline/TimelineViewController.swift b/Mac/MainWindow/Timeline/TimelineViewController.swift index 8d2b6db12..10fff440e 100644 --- a/Mac/MainWindow/Timeline/TimelineViewController.swift +++ b/Mac/MainWindow/Timeline/TimelineViewController.swift @@ -209,7 +209,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr var standardColumn: NSTableColumn? // Set while columns are added and autosaved state is restored, which fires sortDescriptorsDidChange. var isConfiguringTableColumns = false - private var fontSize: FontSize = AppDefaults.shared.timelineFontSize { + private var fontSize: FontSize = AppDefaults.timelineFontSize { didSet { if fontSize != oldValue { fontSizeDidChange() @@ -776,7 +776,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr } @MainActor func userDefaultsDidChange() { - fontSize = AppDefaults.shared.timelineFontSize + fontSize = AppDefaults.timelineFontSize } /// The one place the row height is set — it depends on the layout and the font size. diff --git a/Mac/Preferences/Accounts/AddAccountHelpView.swift b/Mac/Preferences/Accounts/AddAccountHelpView.swift index 8ef5517cf..d729eeccf 100644 --- a/Mac/Preferences/Accounts/AddAccountHelpView.swift +++ b/Mac/Preferences/Accounts/AddAccountHelpView.swift @@ -25,7 +25,7 @@ struct AddAccountHelpView: View { ForEach(accountTypes, id: \.self) { accountType in if accountType == .cloudKit && hasiCloudAccount { EmptyView() - } else if !(AppDefaults.shared.isDeveloperBuild && accountType.isDeveloperRestricted) { + } else if !(AppDefaults.isDeveloperBuild && accountType.isDeveloperRestricted) { Button(action: { delegate?.presentSheetForAccount(accountType) }, label: { diff --git a/Mac/Preferences/Accounts/AddAccountsView.swift b/Mac/Preferences/Accounts/AddAccountsView.swift index 4dd1fff6e..3831fa107 100644 --- a/Mac/Preferences/Accounts/AddAccountsView.swift +++ b/Mac/Preferences/Accounts/AddAccountsView.swift @@ -54,7 +54,7 @@ enum AddAccountSections: Int, CaseIterable { case .icloud: return [.cloudKit] case .web: - if AppDefaults.shared.isDeveloperBuild { + if AppDefaults.isDeveloperBuild { return [.bazQux, .feedbin, .feedly, .inoreader, .newsBlur, .theOldReader].filter({ $0.isDeveloperRestricted == false }) } else { return [.bazQux, .feedbin, .feedly, .inoreader, .newsBlur, .theOldReader] @@ -89,7 +89,7 @@ struct AddAccountsView: View { localAccount - if !AppDefaults.shared.isDeveloperBuild { + if !AppDefaults.isDeveloperBuild { icloudAccount } diff --git a/Mac/Preferences/General/GeneralPrefencesViewController.swift b/Mac/Preferences/General/GeneralPrefencesViewController.swift index 9da98e2cf..65d89cbbd 100644 --- a/Mac/Preferences/General/GeneralPrefencesViewController.swift +++ b/Mac/Preferences/General/GeneralPrefencesViewController.swift @@ -80,7 +80,7 @@ final class GeneralPreferencesViewController: NSViewController { guard let unreadCountDisplay = UnreadCountDisplay(rawValue: sender.tag) else { return } - AppDefaults.shared.unreadCountDisplay = unreadCountDisplay + AppDefaults.unreadCountDisplay = unreadCountDisplay } @IBAction func browserPopUpDidChangeValue(_ sender: Any?) { @@ -89,7 +89,7 @@ final class GeneralPreferencesViewController: NSViewController { } let bundleID = menuItem.representedObject as? String - AppDefaults.shared.defaultBrowserID = bundleID + AppDefaults.defaultBrowserID = bundleID updateBrowserPopup() } @@ -143,7 +143,7 @@ private extension GeneralPreferencesViewController { } func updateUnreadCountDisplayButtons() { - let selectedTag = AppDefaults.shared.unreadCountDisplay.rawValue + let selectedTag = AppDefaults.unreadCountDisplay.rawValue for case let button? in [showUnreadCountsButton, showUnreadCountDotButton, hideUnreadCountsButton] { button.state = button.tag == selectedTag ? .on : .off } @@ -221,7 +221,7 @@ private extension GeneralPreferencesViewController { menu.addItem(item) } - defaultBrowserPopup.selectItem(at: defaultBrowserPopup.indexOfItem(withRepresentedObject: AppDefaults.shared.defaultBrowserID)) + defaultBrowserPopup.selectItem(at: defaultBrowserPopup.indexOfItem(withRepresentedObject: AppDefaults.defaultBrowserID)) } func updateNotificationSettings() { @@ -236,10 +236,10 @@ private extension GeneralPreferencesViewController { @objc var openFeedsInDefaultNewsReader: Bool { get { - return AppDefaults.shared.subscribeToFeedsInDefaultBrowser + return AppDefaults.subscribeToFeedsInDefaultBrowser } set { - AppDefaults.shared.subscribeToFeedsInDefaultBrowser = newValue + AppDefaults.subscribeToFeedsInDefaultBrowser = newValue } } } diff --git a/Shared/AppDefaults+Shared.swift b/Shared/AppDefaults+Shared.swift index e4823790d..316883fa7 100644 --- a/Shared/AppDefaults+Shared.swift +++ b/Shared/AppDefaults+Shared.swift @@ -13,7 +13,7 @@ private extension AppDefaults.Key { extension AppDefaults { - var unreadCountDisplay: UnreadCountDisplay { + static var unreadCountDisplay: UnreadCountDisplay { get { UnreadCountDisplay(rawValue: UserDefaults.standard.integer(forKey: Key.unreadCountDisplay)) ?? .count } diff --git a/Shared/Article Rendering/ArticleRenderer.swift b/Shared/Article Rendering/ArticleRenderer.swift index 27246fd1b..907a1ab18 100644 --- a/Shared/Article Rendering/ArticleRenderer.swift +++ b/Shared/Article Rendering/ArticleRenderer.swift @@ -251,7 +251,7 @@ private extension ArticleRenderer { d["body"] = body #if os(macOS) - d["text_size_class"] = AppDefaults.shared.articleTextSize.cssClass + d["text_size_class"] = AppDefaults.articleTextSize.cssClass #endif var components = URLComponents() diff --git a/Shared/Article Rendering/WebViewConfiguration.swift b/Shared/Article Rendering/WebViewConfiguration.swift index 2ca27ed2c..3d2a99978 100644 --- a/Shared/Article Rendering/WebViewConfiguration.swift +++ b/Shared/Article Rendering/WebViewConfiguration.swift @@ -51,7 +51,7 @@ import Articles /// Whether the article view should run content JavaScript for this article. /// Called from the navigation delegate on every navigation, so a change to the user setting takes effect on the next load. static func allowsContentJavaScript(for article: Article?) -> Bool { - guard AppDefaults.shared.isArticleContentJavascriptEnabled else { + guard AppDefaults.isArticleContentJavascriptEnabled else { return false } guard let article else { diff --git a/Shared/ArticleStyles/ArticleThemesManager.swift b/Shared/ArticleStyles/ArticleThemesManager.swift index 2f918b702..8e0f8eab0 100644 --- a/Shared/ArticleStyles/ArticleThemesManager.swift +++ b/Shared/ArticleStyles/ArticleThemesManager.swift @@ -52,11 +52,11 @@ final class ArticleThemesManager: NSObject, NSFilePresenter, Sendable { var currentThemeName: String { get { - AppDefaults.shared.currentThemeName ?? AppDefaults.defaultThemeName + AppDefaults.currentThemeName ?? AppDefaults.defaultThemeName } set { if newValue != currentThemeName { - AppDefaults.shared.currentThemeName = newValue + AppDefaults.currentThemeName = newValue updateThemeNames() updateCurrentTheme() } diff --git a/Shared/Extensions/AddFeedDefaultContainer.swift b/Shared/Extensions/AddFeedDefaultContainer.swift index 43a0cd8f6..95cf29e8a 100644 --- a/Shared/Extensions/AddFeedDefaultContainer.swift +++ b/Shared/Extensions/AddFeedDefaultContainer.swift @@ -13,8 +13,8 @@ import Account static var defaultContainer: Container? { - if let accountID = AppDefaults.shared.addFeedAccountID, let account = AccountManager.shared.activeAccounts.first(where: { $0.accountID == accountID }) { - if let folderName = AppDefaults.shared.addFeedFolderName, let folder = account.existingFolder(withDisplayName: folderName) { + if let accountID = AppDefaults.addFeedAccountID, let account = AccountManager.shared.activeAccounts.first(where: { $0.accountID == accountID }) { + if let folderName = AppDefaults.addFeedFolderName, let folder = account.existingFolder(withDisplayName: folderName) { return folder } else { return substituteContainerIfNeeded(account: account) @@ -28,11 +28,11 @@ import Account } static func saveDefaultContainer(_ container: Container) { - AppDefaults.shared.addFeedAccountID = container.account?.accountID + AppDefaults.addFeedAccountID = container.account?.accountID if let folder = container as? Folder { - AppDefaults.shared.addFeedFolderName = folder.nameForDisplay + AppDefaults.addFeedFolderName = folder.nameForDisplay } else { - AppDefaults.shared.addFeedFolderName = nil + AppDefaults.addFeedFolderName = nil } } diff --git a/Shared/Extensions/CacheCleaner.swift b/Shared/Extensions/CacheCleaner.swift index a553e040e..29de15cb3 100644 --- a/Shared/Extensions/CacheCleaner.swift +++ b/Shared/Extensions/CacheCleaner.swift @@ -20,8 +20,8 @@ struct CacheCleaner { purgeImageCachesForResizingIfNeeded() - guard let flushDate = AppDefaults.shared.lastImageCacheFlushDate else { - AppDefaults.shared.lastImageCacheFlushDate = Date() + guard let flushDate = AppDefaults.lastImageCacheFlushDate else { + AppDefaults.lastImageCacheFlushDate = Date() return } @@ -43,7 +43,7 @@ struct CacheCleaner { } } - AppDefaults.shared.lastImageCacheFlushDate = Date() + AppDefaults.lastImageCacheFlushDate = Date() } } } diff --git a/Shared/ShareExtension/ShareDefaultContainer.swift b/Shared/ShareExtension/ShareDefaultContainer.swift index 3965b3f60..2ee55c977 100644 --- a/Shared/ShareExtension/ShareDefaultContainer.swift +++ b/Shared/ShareExtension/ShareDefaultContainer.swift @@ -12,8 +12,8 @@ import Foundation static func defaultContainer(containers: ExtensionContainers) -> ExtensionContainer? { - if let accountID = AppDefaults.shared.addFeedAccountID, let account = containers.accounts.first(where: { $0.accountID == accountID }) { - if let folderName = AppDefaults.shared.addFeedFolderName, let folder = account.folders.first(where: { $0.name == folderName }) { + if let accountID = AppDefaults.addFeedAccountID, let account = containers.accounts.first(where: { $0.accountID == accountID }) { + if let folderName = AppDefaults.addFeedFolderName, let folder = account.folders.first(where: { $0.name == folderName }) { return folder } else { return substituteContainerIfNeeded(account: account) @@ -27,11 +27,11 @@ import Foundation } static func saveDefaultContainer(_ container: ExtensionContainer) { - AppDefaults.shared.addFeedAccountID = container.accountID + AppDefaults.addFeedAccountID = container.accountID if let folder = container as? ExtensionFolder { - AppDefaults.shared.addFeedFolderName = folder.name + AppDefaults.addFeedFolderName = folder.name } else { - AppDefaults.shared.addFeedFolderName = nil + AppDefaults.addFeedFolderName = nil } } diff --git a/Shared/Timer/AccountRefreshTimer.swift b/Shared/Timer/AccountRefreshTimer.swift index 457146d6f..22c189341 100644 --- a/Shared/Timer/AccountRefreshTimer.swift +++ b/Shared/Timer/AccountRefreshTimer.swift @@ -23,7 +23,7 @@ import ActivityLog func fireOldTimer() { if let timer = internalTimer { if timer.fireDate < Date() { - if AppDefaults.shared.refreshInterval != .manually { + if AppDefaults.refreshInterval != .manually { timedRefresh(nil) } } @@ -63,7 +63,7 @@ import ActivityLog return } - let refreshInterval = AppDefaults.shared.refreshInterval + let refreshInterval = AppDefaults.refreshInterval if refreshInterval == .manually { invalidate() return diff --git a/Shared/Widget/WidgetDataEncoder.swift b/Shared/Widget/WidgetDataEncoder.swift index f48ae575d..f62828ce0 100644 --- a/Shared/Widget/WidgetDataEncoder.swift +++ b/Shared/Widget/WidgetDataEncoder.swift @@ -161,7 +161,7 @@ import Account starredArticles: starredArticles, todayArticles: todayArticles, lastUpdateTime: Date.now, - unreadCountDisplay: AppDefaults.shared.unreadCountDisplay) + unreadCountDisplay: AppDefaults.unreadCountDisplay) return latestData } diff --git a/iOS/Add/AddFolderView.swift b/iOS/Add/AddFolderView.swift index c49ad99d5..61fcd8864 100644 --- a/iOS/Add/AddFolderView.swift +++ b/iOS/Add/AddFolderView.swift @@ -26,7 +26,7 @@ struct AddFolderView: View { let accounts = AccountManager.shared.sortedActiveAccounts.filter { !$0.behaviors.contains(.disallowFolderManagement) } self.accounts = accounts - let rememberedAccount = accounts.first { $0.accountID == AppDefaults.shared.addFolderAccountID } + let rememberedAccount = accounts.first { $0.accountID == AppDefaults.addFolderAccountID } self._selectedAccountID = State(initialValue: (rememberedAccount ?? accounts.first)?.accountID ?? "") } @@ -100,7 +100,7 @@ struct AddFolderView: View { guard let selectedAccount else { return } - AppDefaults.shared.addFolderAccountID = selectedAccount.accountID + AppDefaults.addFolderAccountID = selectedAccount.accountID isAdding = true defer { diff --git a/iOS/AppDefaults.swift b/iOS/AppDefaults.swift index 9e15223b7..751c0015d 100644 --- a/iOS/AppDefaults.swift +++ b/iOS/AppDefaults.swift @@ -36,13 +36,10 @@ extension Notification.Name { public static let timelineNumberOfLinesDidChange = Notification.Name("TimelineNumberOfLinesDidChangeNotification") } -final class AppDefaults: Sendable { - static let shared = AppDefaults() +enum AppDefaults { static let defaultThemeName = "Default" fileprivate static let logger = Logger(subsystem: Logger.nnwSubsystem, category: "AppDefaults") - private init() {} - struct Key { static let userInterfaceColorPalette = "userInterfaceColorPalette" static let lastImageCacheFlushDate = "lastImageCacheFlushDate" @@ -81,14 +78,14 @@ final class AppDefaults: Sendable { static let appGroupKeys = [userInterfaceColorPalette, lastImageCacheFlushDate, firstRunDate, timelineGroupByFeed, refreshClearsReadArticles, timelineNumberOfLines, timelineIconDimension, timelineSortDirection, articleFullscreenAvailable, articleFullscreenEnabled, confirmMarkAllAsRead, articleContentJavascriptEnabled, splitViewPreferredDisplayMode, lastRefresh] } - let isDeveloperBuild: Bool = { + static let isDeveloperBuild: Bool = { if let dev = Bundle.main.object(forInfoDictionaryKey: "DeveloperEntitlements") as? String, dev == "-dev" { return true } return false }() - let isFirstRun: Bool = { + static let isFirstRun: Bool = { if UserDefaults.standard.object(forKey: Key.firstRunDate) is Date { return false } @@ -109,7 +106,7 @@ final class AppDefaults: Sendable { } } - var addFeedAccountID: String? { + static var addFeedAccountID: String? { get { return AppDefaults.string(for: Key.addFeedAccountID) } @@ -118,7 +115,7 @@ final class AppDefaults: Sendable { } } - var addFeedFolderName: String? { + static var addFeedFolderName: String? { get { return AppDefaults.string(for: Key.addFeedFolderName) } @@ -127,7 +124,7 @@ final class AppDefaults: Sendable { } } - var addFolderAccountID: String? { + static var addFolderAccountID: String? { get { return AppDefaults.string(for: Key.addFolderAccountID) } @@ -136,7 +133,7 @@ final class AppDefaults: Sendable { } } - var useSystemBrowser: Bool { + static var useSystemBrowser: Bool { get { return UserDefaults.standard.bool(forKey: Key.useSystemBrowser) } @@ -145,7 +142,7 @@ final class AppDefaults: Sendable { } } - var lastImageCacheFlushDate: Date? { + static var lastImageCacheFlushDate: Date? { get { return AppDefaults.date(for: Key.lastImageCacheFlushDate) } @@ -154,7 +151,7 @@ final class AppDefaults: Sendable { } } - var timelineGroupByFeed: Bool { + static var timelineGroupByFeed: Bool { get { return AppDefaults.bool(for: Key.timelineGroupByFeed) } @@ -163,7 +160,7 @@ final class AppDefaults: Sendable { } } - var refreshClearsReadArticles: Bool { + static var refreshClearsReadArticles: Bool { get { return AppDefaults.bool(for: Key.refreshClearsReadArticles) } @@ -172,7 +169,7 @@ final class AppDefaults: Sendable { } } - var timelineSortDirection: ComparisonResult { + static var timelineSortDirection: ComparisonResult { get { return AppDefaults.sortDirection(for: Key.timelineSortDirection) } @@ -181,7 +178,7 @@ final class AppDefaults: Sendable { } } - var articleFullscreenAvailable: Bool { + static var articleFullscreenAvailable: Bool { get { return AppDefaults.bool(for: Key.articleFullscreenAvailable) } @@ -190,7 +187,7 @@ final class AppDefaults: Sendable { } } - var articleFullscreenEnabled: Bool { + static var articleFullscreenEnabled: Bool { get { return articleFullscreenAvailable && AppDefaults.bool(for: Key.articleFullscreenEnabled) } @@ -199,11 +196,11 @@ final class AppDefaults: Sendable { } } - var logicalArticleFullscreenEnabled: Bool { + static var logicalArticleFullscreenEnabled: Bool { articleFullscreenAvailable && articleFullscreenEnabled } - var confirmMarkAllAsRead: Bool { + static var confirmMarkAllAsRead: Bool { get { return AppDefaults.bool(for: Key.confirmMarkAllAsRead) } @@ -212,7 +209,7 @@ final class AppDefaults: Sendable { } } - var isArticleContentJavascriptEnabled: Bool { + static var isArticleContentJavascriptEnabled: Bool { get { return AppDefaults.bool(for: Key.articleContentJavascriptEnabled) } @@ -221,7 +218,7 @@ final class AppDefaults: Sendable { } } - var splitViewPreferredDisplayMode: Int { + static var splitViewPreferredDisplayMode: Int { get { return AppDefaults.int(for: Key.splitViewPreferredDisplayMode) } @@ -231,7 +228,7 @@ final class AppDefaults: Sendable { } // The iPad timeline column width. nil until the user has resized it. - var timelineWidth: Int? { + static var timelineWidth: Int? { get { UserDefaults.standard.object(forKey: Key.timelineWidth) as? Int } @@ -245,7 +242,7 @@ final class AppDefaults: Sendable { } // The iPad sidebar column width. nil until the user has resized it. - var sidebarWidth: Int? { + static var sidebarWidth: Int? { get { UserDefaults.standard.object(forKey: Key.sidebarWidth) as? Int } @@ -258,7 +255,7 @@ final class AppDefaults: Sendable { } } - var lastRefresh: Date? { + static var lastRefresh: Date? { get { return AppDefaults.date(for: Key.lastRefresh) } @@ -267,7 +264,7 @@ final class AppDefaults: Sendable { } } - var timelineNumberOfLines: Int { + static var timelineNumberOfLines: Int { get { return AppDefaults.int(for: Key.timelineNumberOfLines) } @@ -277,7 +274,7 @@ final class AppDefaults: Sendable { } } - var timelineIconSize: IconSize { + static var timelineIconSize: IconSize { get { let rawValue = UserDefaults.standard.integer(forKey: Key.timelineIconDimension) return IconSize(rawValue: rawValue) ?? IconSize.medium @@ -288,7 +285,7 @@ final class AppDefaults: Sendable { } } - var currentThemeName: String? { + static var currentThemeName: String? { get { return AppDefaults.string(for: Key.currentThemeName) } @@ -297,7 +294,7 @@ final class AppDefaults: Sendable { } } - var hideReadFeeds: Bool { + static var hideReadFeeds: Bool { get { UserDefaults.standard.bool(forKey: Key.hideReadFeeds) } @@ -306,7 +303,7 @@ final class AppDefaults: Sendable { } } - var isShowingExtractedArticle: Bool { + static var isShowingExtractedArticle: Bool { get { UserDefaults.standard.bool(forKey: Key.isShowingExtractedArticle) } @@ -315,7 +312,7 @@ final class AppDefaults: Sendable { } } - var articleWindowScrollY: Int { + static var articleWindowScrollY: Int { get { UserDefaults.standard.integer(forKey: Key.articleWindowScrollY) } @@ -324,7 +321,7 @@ final class AppDefaults: Sendable { } } - var expandedContainers: Set { + static var expandedContainers: Set { get { guard let rawIdentifiers = UserDefaults.standard.array(forKey: Key.expandedContainers) as? [[String: String]] else { return Set() @@ -339,7 +336,7 @@ final class AppDefaults: Sendable { } } - var smartFeedsHidingReadArticles: Set { + static var smartFeedsHidingReadArticles: Set { get { let smartFeedIDs = UserDefaults.standard.array(forKey: Key.smartFeedsHidingReadArticles) as? [String] ?? [] return Set(smartFeedIDs) @@ -350,7 +347,7 @@ final class AppDefaults: Sendable { } } - var feedsHidingReadArticles: [String: Set] { // Account id: Set + static var feedsHidingReadArticles: [String: Set] { // Account id: Set get { guard let d = UserDefaults.standard.dictionary(forKey: Key.feedsHidingReadArticles) as? [String: [String]] else { return [String: Set]() @@ -363,7 +360,7 @@ final class AppDefaults: Sendable { } } - var foldersShowingReadArticles: [String: Set] { // Account id: Set + static var foldersShowingReadArticles: [String: Set] { // Account id: Set get { guard let d = UserDefaults.standard.dictionary(forKey: Key.foldersShowingReadArticles) as? [String: [String]] else { return [String: Set]() @@ -376,7 +373,7 @@ final class AppDefaults: Sendable { } } - var selectedSidebarItem: SidebarItemIdentifier? { + static var selectedSidebarItem: SidebarItemIdentifier? { get { guard let userInfo = UserDefaults.standard.dictionary(forKey: Key.selectedSidebarItem) as? [String: String] else { return nil @@ -392,7 +389,7 @@ final class AppDefaults: Sendable { } } - var selectedArticle: ArticleSpecifier? { + static var selectedArticle: ArticleSpecifier? { get { guard let d = UserDefaults.standard.dictionary(forKey: Key.selectedArticle) as? [String: String] else { return nil @@ -408,7 +405,7 @@ final class AppDefaults: Sendable { } } - var didMigrateLegacyStateRestorationInfo: Bool { + static var didMigrateLegacyStateRestorationInfo: Bool { get { UserDefaults.standard.bool(forKey: Key.didMigrateLegacyStateRestorationInfo) } @@ -559,25 +556,25 @@ struct StateRestorationInfo { } init() { - self.init(hideReadFeeds: AppDefaults.shared.hideReadFeeds, - expandedContainers: AppDefaults.shared.expandedContainers, - selectedSidebarItem: AppDefaults.shared.selectedSidebarItem, - smartFeedsHidingReadArticles: AppDefaults.shared.smartFeedsHidingReadArticles, - feedsHidingReadArticles: AppDefaults.shared.feedsHidingReadArticles, - foldersShowingReadArticles: AppDefaults.shared.foldersShowingReadArticles, - selectedArticle: AppDefaults.shared.selectedArticle, - articleWindowScrollY: AppDefaults.shared.articleWindowScrollY, - isShowingExtractedArticle: AppDefaults.shared.isShowingExtractedArticle) + 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) } // TODO: Delete for NetNewsWire 7.1. init(legacyState: NSUserActivity?) { - if AppDefaults.shared.didMigrateLegacyStateRestorationInfo { + if AppDefaults.didMigrateLegacyStateRestorationInfo { self.init() return } - AppDefaults.shared.didMigrateLegacyStateRestorationInfo = true + AppDefaults.didMigrateLegacyStateRestorationInfo = true // Extract legacy window state if available guard let windowState = legacyState?.userInfo?[UserInfoKey.windowState] as? [AnyHashable: Any] else { @@ -589,7 +586,7 @@ struct StateRestorationInfo { if let legacyValue = windowState[UserInfoKey.readFeedsFilterState] as? Bool { hideReadFeeds = legacyValue } else { - hideReadFeeds = AppDefaults.shared.hideReadFeeds + hideReadFeeds = AppDefaults.hideReadFeeds } let expandedContainers: Set @@ -606,7 +603,7 @@ struct StateRestorationInfo { let containerIdentifiers = convertedState.compactMap { ContainerIdentifier(userInfo: $0) } expandedContainers = Set(containerIdentifiers) } else { - expandedContainers = AppDefaults.shared.expandedContainers + expandedContainers = AppDefaults.expandedContainers } let sidebarItemsHidingReadArticles: Set @@ -647,7 +644,7 @@ struct StateRestorationInfo { let sidebarItemIdentifier = SidebarItemIdentifier(userInfo: legacyState) { selectedSidebarItem = sidebarItemIdentifier } else { - selectedSidebarItem = AppDefaults.shared.selectedSidebarItem + selectedSidebarItem = AppDefaults.selectedSidebarItem } self.init(hideReadFeeds: hideReadFeeds, @@ -655,9 +652,9 @@ struct StateRestorationInfo { selectedSidebarItem: selectedSidebarItem, smartFeedsHidingReadArticles: smartFeedsHidingReadArticles, feedsHidingReadArticles: feedsHidingReadArticles, - foldersShowingReadArticles: AppDefaults.shared.foldersShowingReadArticles, - selectedArticle: AppDefaults.shared.selectedArticle, - articleWindowScrollY: AppDefaults.shared.articleWindowScrollY, - isShowingExtractedArticle: AppDefaults.shared.isShowingExtractedArticle) + foldersShowingReadArticles: AppDefaults.foldersShowingReadArticles, + selectedArticle: AppDefaults.selectedArticle, + articleWindowScrollY: AppDefaults.articleWindowScrollY, + isShowingExtractedArticle: AppDefaults.isShowingExtractedArticle) } } diff --git a/iOS/AppDelegate.swift b/iOS/AppDelegate.swift index e21b6d97f..5c145d73b 100644 --- a/iOS/AppDelegate.swift +++ b/iOS/AppDelegate.swift @@ -68,7 +68,7 @@ import Images await WebViewConfiguration.compileContentBlockingRules() } - let isFirstRun = AppDefaults.shared.isFirstRun + let isFirstRun = AppDefaults.isFirstRun if isFirstRun { Self.logger.info("Is first run.") } @@ -136,7 +136,7 @@ import Images private func updateBadge() { assert(unreadCount == AccountManager.shared.unreadCount) - let badgeCount = AppDefaults.shared.unreadCountDisplay == .count ? unreadCount : 0 + let badgeCount = AppDefaults.unreadCountDisplay == .count ? unreadCount : 0 UNUserNotificationCenter.current().setBadgeCount(badgeCount) } @@ -149,7 +149,7 @@ import Images } @objc func accountRefreshDidFinish(_ note: Notification) { - AppDefaults.shared.lastRefresh = Date() + AppDefaults.lastRefresh = Date() } @objc func handleUnreadCountDisplaySettingDidChange(_ notification: Notification) { @@ -196,7 +196,7 @@ import Images #endif ArticleStatusSyncTimer.shared.update() - if let lastRefresh = AppDefaults.shared.lastRefresh { + if let lastRefresh = AppDefaults.lastRefresh { if Date() > lastRefresh.addingTimeInterval(15 * 60) { AccountManager.shared.refreshAllWithoutWaiting(errorHandler: ErrorHandler.log) } else { diff --git a/iOS/Article/ArticleViewController.swift b/iOS/Article/ArticleViewController.swift index 5820ed40c..cefb42590 100644 --- a/iOS/Article/ArticleViewController.swift +++ b/iOS/Article/ArticleViewController.swift @@ -199,7 +199,7 @@ final class ArticleViewController: UIViewController { articleExtractorButton.buttonState = controller.articleExtractorButtonState self.pageViewController.setViewControllers([controller], direction: .forward, animated: false, completion: nil) - if AppDefaults.shared.logicalArticleFullscreenEnabled { + if AppDefaults.logicalArticleFullscreenEnabled { controller.hideBars() } @@ -215,7 +215,7 @@ final class ArticleViewController: UIViewController { } override func viewWillAppear(_ animated: Bool) { - let hideToolbars = AppDefaults.shared.logicalArticleFullscreenEnabled + let hideToolbars = AppDefaults.logicalArticleFullscreenEnabled if hideToolbars { currentWebViewController?.hideBars() } else { @@ -283,7 +283,7 @@ final class ArticleViewController: UIViewController { starBarButtonItem.isEnabled = true let permalinkPresent = article.preferredLink != nil - articleExtractorButton.isEnabled = permalinkPresent && !AppDefaults.shared.isDeveloperBuild + articleExtractorButton.isEnabled = permalinkPresent && !AppDefaults.isDeveloperBuild actionBarButtonItem.isEnabled = permalinkPresent if article.status.read { @@ -329,7 +329,7 @@ final class ArticleViewController: UIViewController { @objc func willEnterForeground(_ note: Notification) { // The toolbar will come back on you if you don't hide it again - if AppDefaults.shared.logicalArticleFullscreenEnabled { + if AppDefaults.logicalArticleFullscreenEnabled { currentWebViewController?.hideBars() } } diff --git a/iOS/Article/WebViewController.swift b/iOS/Article/WebViewController.swift index ffc1a0397..a7977c2fd 100644 --- a/iOS/Article/WebViewController.swift +++ b/iOS/Article/WebViewController.swift @@ -42,7 +42,7 @@ final class WebViewController: UIViewController { private lazy var contextMenuInteraction = UIContextMenuInteraction(delegate: self) private var isFullScreenAvailable: Bool { - return AppDefaults.shared.articleFullscreenAvailable && traitCollection.userInterfaceIdiom == .phone + return AppDefaults.articleFullscreenAvailable && traitCollection.userInterfaceIdiom == .phone } private lazy var articleIconSchemeHandler = ArticleIconSchemeHandler(coordinator: coordinator) private lazy var transition = ImageTransition(controller: self) @@ -58,8 +58,8 @@ final class WebViewController: UIViewController { } var isShowingExtractedArticle = false { didSet { - if AppDefaults.shared.isShowingExtractedArticle != isShowingExtractedArticle { - AppDefaults.shared.isShowingExtractedArticle = isShowingExtractedArticle + if AppDefaults.isShowingExtractedArticle != isShowingExtractedArticle { + AppDefaults.isShowingExtractedArticle = isShowingExtractedArticle } } } @@ -78,13 +78,13 @@ final class WebViewController: UIViewController { let scrollPositionQueue = CoalescingQueue(name: "Article Scroll Position", interval: 0.3, maxInterval: 0.3) var windowScrollY = 0 { didSet { - if windowScrollY != AppDefaults.shared.articleWindowScrollY { - AppDefaults.shared.articleWindowScrollY = windowScrollY + if windowScrollY != AppDefaults.articleWindowScrollY { + AppDefaults.articleWindowScrollY = windowScrollY } } } private var restoreWindowScrollY: Int? - private var isArticleContentJavascriptEnabled = AppDefaults.shared.isArticleContentJavascriptEnabled + private var isArticleContentJavascriptEnabled = AppDefaults.isArticleContentJavascriptEnabled override func viewDidLoad() { super.viewDidLoad() @@ -105,7 +105,7 @@ final class WebViewController: UIViewController { override func viewSafeAreaInsetsDidChange() { super.viewSafeAreaInsetsDidChange() - if isFullScreenAvailable && AppDefaults.shared.logicalArticleFullscreenEnabled { + if isFullScreenAvailable && AppDefaults.logicalArticleFullscreenEnabled { updateBottomSafeAreaForFullScreen() } } @@ -152,10 +152,10 @@ final class WebViewController: UIViewController { } private func userDefaultsDidChange() { - guard isArticleContentJavascriptEnabled != AppDefaults.shared.isArticleContentJavascriptEnabled else { + guard isArticleContentJavascriptEnabled != AppDefaults.isArticleContentJavascriptEnabled else { return } - isArticleContentJavascriptEnabled = AppDefaults.shared.isArticleContentJavascriptEnabled + isArticleContentJavascriptEnabled = AppDefaults.isArticleContentJavascriptEnabled loadWebView() } @@ -260,7 +260,7 @@ final class WebViewController: UIViewController { } func showBars(animated: Bool = true) { - AppDefaults.shared.articleFullscreenEnabled = false + AppDefaults.articleFullscreenEnabled = false coordinator.showStatusBar() topShowBarsViewConstraint?.constant = 0 bottomShowBarsViewConstraint?.constant = 0 @@ -273,7 +273,7 @@ final class WebViewController: UIViewController { func hideBars() { if isFullScreenAvailable { - AppDefaults.shared.articleFullscreenEnabled = true + AppDefaults.articleFullscreenEnabled = true coordinator.hideStatusBar() topShowBarsViewConstraint?.constant = -44.0 bottomShowBarsViewConstraint?.constant = 44.0 @@ -353,7 +353,7 @@ final class WebViewController: UIViewController { func openInAppBrowser() { guard let url = article?.preferredURL else { return } - if AppDefaults.shared.useSystemBrowser { + if AppDefaults.useSystemBrowser { UIApplication.shared.open(url, options: [:]) } else { openURLInSafariViewController(url) @@ -468,7 +468,7 @@ extension WebViewController: WKNavigationDelegate { let components = URLComponents(url: url, resolvingAgainstBaseURL: false) if components?.scheme == "http" || components?.scheme == "https" { decisionHandler(.cancel, preferences) - if AppDefaults.shared.useSystemBrowser { + if AppDefaults.useSystemBrowser { UIApplication.shared.open(url, options: [:]) } else { UIApplication.shared.open(url, options: [.universalLinksOnly: true]) { didOpen in @@ -799,7 +799,7 @@ private extension WebViewController { topShowBarsView.translatesAutoresizingMaskIntoConstraints = false view.addSubview(topShowBarsView) - if AppDefaults.shared.logicalArticleFullscreenEnabled { + if AppDefaults.logicalArticleFullscreenEnabled { topShowBarsViewConstraint = view.topAnchor.constraint(equalTo: topShowBarsView.bottomAnchor, constant: -44.0) } else { topShowBarsViewConstraint = view.topAnchor.constraint(equalTo: topShowBarsView.bottomAnchor, constant: 0.0) @@ -819,7 +819,7 @@ private extension WebViewController { bottomShowBarsView.backgroundColor = .clear bottomShowBarsView.translatesAutoresizingMaskIntoConstraints = false view.addSubview(bottomShowBarsView) - if AppDefaults.shared.logicalArticleFullscreenEnabled { + if AppDefaults.logicalArticleFullscreenEnabled { bottomShowBarsViewConstraint = view.bottomAnchor.constraint(equalTo: bottomShowBarsView.topAnchor, constant: 44.0) } else { bottomShowBarsViewConstraint = view.bottomAnchor.constraint(equalTo: bottomShowBarsView.topAnchor, constant: 0.0) diff --git a/iOS/HidingReadArticlesState.swift b/iOS/HidingReadArticlesState.swift index 67a0b1aad..255d95187 100644 --- a/iOS/HidingReadArticlesState.swift +++ b/iOS/HidingReadArticlesState.swift @@ -126,7 +126,7 @@ private extension HidingReadArticlesState { d[accountID] = d[accountID]?.filter { account.existingFolder(withDisplayName: $0) != nil } } - AppDefaults.shared.foldersShowingReadArticles = d + AppDefaults.foldersShowingReadArticles = d } func saveFeedsHidingReadArticles() { @@ -141,10 +141,10 @@ private extension HidingReadArticlesState { d[accountID] = d[accountID]?.filter { account.existingFeed(withFeedID: $0) != nil } } - AppDefaults.shared.feedsHidingReadArticles = d + AppDefaults.feedsHidingReadArticles = d } func saveSmartFeedsHidingReadArticles() { - AppDefaults.shared.smartFeedsHidingReadArticles = smartFeedsHidingReadArticles + AppDefaults.smartFeedsHidingReadArticles = smartFeedsHidingReadArticles } } diff --git a/iOS/MainFeed/Collection View Cells/MainFeedCollectionHeaderReusableView.swift b/iOS/MainFeed/Collection View Cells/MainFeedCollectionHeaderReusableView.swift index ad220620a..49deda0fa 100644 --- a/iOS/MainFeed/Collection View Cells/MainFeedCollectionHeaderReusableView.swift +++ b/iOS/MainFeed/Collection View Cells/MainFeedCollectionHeaderReusableView.swift @@ -29,7 +29,7 @@ final class MainFeedCollectionHeaderReusableView: UICollectionReusableView { override var accessibilityLabel: String? { get { let name = headerTitle.text ?? "" - guard let unreadText = AppDefaults.shared.unreadCountDisplay.accessibilityText(for: unreadCount) else { + guard let unreadText = AppDefaults.unreadCountDisplay.accessibilityText(for: unreadCount) else { return "\(name) \(expandedStateMessage) " } return "\(name) \(unreadText) \(expandedStateMessage) " @@ -58,7 +58,7 @@ final class MainFeedCollectionHeaderReusableView: UICollectionReusableView { } private var unreadCountText: String? { - AppDefaults.shared.unreadCountDisplay.text(for: unreadCount) + AppDefaults.unreadCountDisplay.text(for: unreadCount) } // Mutate via setDisclosure(isExpanded:animated:) — the supplementary provider diff --git a/iOS/MainFeed/Collection View Cells/MainFeedCollectionViewCell.swift b/iOS/MainFeed/Collection View Cells/MainFeedCollectionViewCell.swift index 9e2e2fb02..6a3be5247 100644 --- a/iOS/MainFeed/Collection View Cells/MainFeedCollectionViewCell.swift +++ b/iOS/MainFeed/Collection View Cells/MainFeedCollectionViewCell.swift @@ -33,7 +33,7 @@ final class MainFeedCollectionViewCell: UICollectionViewCell { } set { _unreadCount = newValue - unreadCountLabel.isHidden = AppDefaults.shared.unreadCountDisplay.text(for: newValue) == nil + unreadCountLabel.isHidden = AppDefaults.unreadCountDisplay.text(for: newValue) == nil unreadCountLabel.setUnreadCount(newValue) setNeedsUpdateConfiguration() } @@ -57,7 +57,7 @@ final class MainFeedCollectionViewCell: UICollectionViewCell { override var accessibilityLabel: String? { get { let name = feedTitle.text ?? "" - guard let unreadText = AppDefaults.shared.unreadCountDisplay.accessibilityText(for: unreadCount) else { + guard let unreadText = AppDefaults.unreadCountDisplay.accessibilityText(for: unreadCount) else { return name } return "\(name) \(unreadText)" diff --git a/iOS/MainFeed/Collection View Cells/MainFeedCollectionViewFolderCell.swift b/iOS/MainFeed/Collection View Cells/MainFeedCollectionViewFolderCell.swift index 5c357c620..6e6508e19 100644 --- a/iOS/MainFeed/Collection View Cells/MainFeedCollectionViewFolderCell.swift +++ b/iOS/MainFeed/Collection View Cells/MainFeedCollectionViewFolderCell.swift @@ -40,7 +40,7 @@ class MainFeedCollectionViewFolderCell: UICollectionViewCell { } private var unreadCountText: String? { - AppDefaults.shared.unreadCountDisplay.text(for: unreadCount) + AppDefaults.unreadCountDisplay.text(for: unreadCount) } var iconImage: IconImage? { @@ -105,7 +105,7 @@ class MainFeedCollectionViewFolderCell: UICollectionViewCell { override var accessibilityLabel: String? { get { let name = folderTitle.text ?? "" - guard let unreadText = AppDefaults.shared.unreadCountDisplay.accessibilityText(for: unreadCount) else { + guard let unreadText = AppDefaults.unreadCountDisplay.accessibilityText(for: unreadCount) else { return "\(name) \(expandedStateMessage)" } return "\(name) \(unreadText) \(expandedStateMessage)" diff --git a/iOS/MainFeed/Collection View Cells/UILabel+UnreadCount.swift b/iOS/MainFeed/Collection View Cells/UILabel+UnreadCount.swift index 9fc1b8566..36db5ceed 100644 --- a/iOS/MainFeed/Collection View Cells/UILabel+UnreadCount.swift +++ b/iOS/MainFeed/Collection View Cells/UILabel+UnreadCount.swift @@ -12,7 +12,7 @@ extension UILabel { /// Shows `unreadCount` per the Unread Counts setting: the number, a dot, or nothing. /// The dot is drawn in the label’s text color. func setUnreadCount(_ unreadCount: Int) { - let unreadCountDisplay = AppDefaults.shared.unreadCountDisplay + let unreadCountDisplay = AppDefaults.unreadCountDisplay if unreadCountDisplay.showsDot(for: unreadCount) { attributedText = NSAttributedString(attachment: unreadDotAttachment()) } else { diff --git a/iOS/MainTimeline/MainTimelineViewController.swift b/iOS/MainTimeline/MainTimelineViewController.swift index 432e84896..61700d2ec 100644 --- a/iOS/MainTimeline/MainTimelineViewController.swift +++ b/iOS/MainTimeline/MainTimelineViewController.swift @@ -187,8 +187,8 @@ final class MainTimelineViewController: UIViewController, UndoableCommandRunner configureSearchController() definesPresentationContext = true - numberOfTextLines = AppDefaults.shared.timelineNumberOfLines - iconSize = AppDefaults.shared.timelineIconSize + numberOfTextLines = AppDefaults.timelineNumberOfLines + iconSize = AppDefaults.timelineIconSize assert(collectionView?.refreshControl != nil) collectionView?.refreshControl = UIRefreshControl() @@ -1100,16 +1100,16 @@ private extension MainTimelineViewController { @objc func timelineIconSizeDidChange(_ note: Notification) { Self.logger.debug("MainTimelineViewController: timelineIconSizeDidChange") - if iconSize != AppDefaults.shared.timelineIconSize { - iconSize = AppDefaults.shared.timelineIconSize + if iconSize != AppDefaults.timelineIconSize { + iconSize = AppDefaults.timelineIconSize reloadVisibleCells() } } @objc func timelineNumberOfLinesDidChange(_ note: Notification) { Self.logger.debug("MainTimelineViewController: timelineNumberOfLinesDidChange") - if numberOfTextLines != AppDefaults.shared.timelineNumberOfLines { - numberOfTextLines = AppDefaults.shared.timelineNumberOfLines + if numberOfTextLines != AppDefaults.timelineNumberOfLines { + numberOfTextLines = AppDefaults.timelineNumberOfLines reloadVisibleCells() } } diff --git a/iOS/MainTimeline/MarkAsReadAlertController.swift b/iOS/MainTimeline/MarkAsReadAlertController.swift index f2478e15e..ed392a44e 100644 --- a/iOS/MainTimeline/MarkAsReadAlertController.swift +++ b/iOS/MainTimeline/MarkAsReadAlertController.swift @@ -28,7 +28,7 @@ extension UIBarButtonItem: MarkAsReadAlertControllerSourceType {} return } - if AppDefaults.shared.confirmMarkAllAsRead { + if AppDefaults.confirmMarkAllAsRead { let alertController = MarkAsReadAlertController.alert(coordinator: coordinator, confirmTitle: confirmTitle, cancelCompletion: cancelCompletion, sourceType: sourceType) { _ in completion() } diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index 261975ac6..5ea8fbe05 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -98,7 +98,7 @@ struct SidebarItemNode: Hashable, Sendable { /// `Bool` to track whether a refresh is scheduled. private var isNavigationBarSubtitleRefreshScheduled: Bool = false - private(set) var sortDirection = AppDefaults.shared.timelineSortDirection { + private(set) var sortDirection = AppDefaults.timelineSortDirection { didSet { if sortDirection != oldValue { sortParametersDidChange() @@ -106,7 +106,7 @@ struct SidebarItemNode: Hashable, Sendable { } } - private(set) var groupByFeed = AppDefaults.shared.timelineGroupByFeed { + private(set) var groupByFeed = AppDefaults.timelineGroupByFeed { didSet { if groupByFeed != oldValue { sortParametersDidChange() @@ -266,9 +266,9 @@ struct SidebarItemNode: Hashable, Sendable { var currentArticle: Article? { didSet { if let article = currentArticle { - AppDefaults.shared.selectedArticle = ArticleSpecifier(article: article) + AppDefaults.selectedArticle = ArticleSpecifier(article: article) } else { - AppDefaults.shared.selectedArticle = nil + AppDefaults.selectedArticle = nil } } } @@ -317,7 +317,7 @@ struct SidebarItemNode: Hashable, Sendable { } private var isTimelineUnreadCountSubtitleShown: Bool { - timelineFeed != nil && timelineUnreadCount > 0 && AppDefaults.shared.unreadCountDisplay == .count + timelineFeed != nil && timelineUnreadCount > 0 && AppDefaults.unreadCountDisplay == .count } private static let minimumTimelineWidth: CGFloat = 280 @@ -353,13 +353,13 @@ struct SidebarItemNode: Hashable, Sendable { self.rootSplitViewController.minimumSupplementaryColumnWidth = SceneCoordinator.minimumTimelineWidth self.rootSplitViewController.maximumSupplementaryColumnWidth = SceneCoordinator.maximumTimelineWidth let restoredTimelineWidth: CGFloat - if let savedTimelineWidth = AppDefaults.shared.timelineWidth { + if let savedTimelineWidth = AppDefaults.timelineWidth { restoredTimelineWidth = CGFloat(savedTimelineWidth) } else { restoredTimelineWidth = 320 } self.rootSplitViewController.preferredSupplementaryColumnWidth = Self.clampTimelineWidth(restoredTimelineWidth) - if let savedSidebarWidth = AppDefaults.shared.sidebarWidth { + if let savedSidebarWidth = AppDefaults.sidebarWidth { self.rootSplitViewController.preferredPrimaryColumnWidth = Self.clampSidebarWidth(CGFloat(savedSidebarWidth)) } self.rootSplitViewController.preferredSplitBehavior = .tile @@ -418,7 +418,7 @@ struct SidebarItemNode: Hashable, Sendable { isRestoringState = true - if AppDefaults.shared.isFirstRun { + if AppDefaults.isFirstRun { // Expand top-level items on first run. for sectionNode in treeController.rootNode.childNodes { markExpanded(sectionNode) @@ -660,8 +660,8 @@ struct SidebarItemNode: Hashable, Sendable { } func userDefaultsDidChange() { - sortDirection = AppDefaults.shared.timelineSortDirection - groupByFeed = AppDefaults.shared.timelineGroupByFeed + sortDirection = AppDefaults.timelineSortDirection + groupByFeed = AppDefaults.timelineGroupByFeed } @objc func accountDidDownloadArticles(_ note: Notification) { @@ -838,7 +838,7 @@ struct SidebarItemNode: Hashable, Sendable { guard width > 0 else { return } - AppDefaults.shared.timelineWidth = Int(SceneCoordinator.clampTimelineWidth(width)) + AppDefaults.timelineWidth = Int(SceneCoordinator.clampTimelineWidth(width)) } func sidebarDidLayout() { @@ -857,7 +857,7 @@ struct SidebarItemNode: Hashable, Sendable { guard width > 0 else { return } - AppDefaults.shared.sidebarWidth = Int(SceneCoordinator.clampSidebarWidth(width)) + AppDefaults.sidebarWidth = Int(SceneCoordinator.clampSidebarWidth(width)) } func suspend() { @@ -867,7 +867,7 @@ struct SidebarItemNode: Hashable, Sendable { } func saveExpandedContainers() { - AppDefaults.shared.expandedContainers = expandedContainers + AppDefaults.expandedContainers = expandedContainers } func cleanUp(conditional: Bool) { @@ -875,7 +875,7 @@ struct SidebarItemNode: Hashable, Sendable { if isReadFeedsFiltered { rebuildBackingStores() } - if AppDefaults.shared.refreshClearsReadArticles || !conditional { + if AppDefaults.refreshClearsReadArticles || !conditional { removeArticlesHiddenByReadFilter() } } @@ -928,7 +928,7 @@ struct SidebarItemNode: Hashable, Sendable { let newValue = !isReadFeedsFiltered treeControllerDelegate.isReadFiltered = newValue - AppDefaults.shared.hideReadFeeds = newValue + AppDefaults.hideReadFeeds = newValue rebuildBackingStores() mainFeedCollectionViewController?.updateUI() } @@ -1130,7 +1130,7 @@ struct SidebarItemNode: Hashable, Sendable { if self.isReadFeedsFiltered { self.rebuildBackingStores() } - AppDefaults.shared.selectedSidebarItem = sidebarItem.sidebarItemID + AppDefaults.selectedSidebarItem = sidebarItem.sidebarItemID completion?() } @@ -1142,7 +1142,7 @@ struct SidebarItemNode: Hashable, Sendable { } self.activityManager.invalidateSelecting() self.rootSplitViewController.showColumn(.primary) - AppDefaults.shared.selectedSidebarItem = nil + AppDefaults.selectedSidebarItem = nil completion?() } @@ -1797,7 +1797,7 @@ extension SceneCoordinator: UISplitViewControllerDelegate { } func splitViewController(_ svc: UISplitViewController, willChangeTo displayMode: UISplitViewController.DisplayMode) { - AppDefaults.shared.splitViewPreferredDisplayMode = displayMode.rawValue + AppDefaults.splitViewPreferredDisplayMode = displayMode.rawValue mainTimelineViewController?.updateToolbarProgressView(for: displayMode) } diff --git a/iOS/SceneDelegate.swift b/iOS/SceneDelegate.swift index a2eedcd92..09ccc96b8 100644 --- a/iOS/SceneDelegate.swift +++ b/iOS/SceneDelegate.swift @@ -24,10 +24,10 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate { let rootViewController = window!.rootViewController as! RootSplitViewController rootViewController.presentsWithGesture = true rootViewController.showsSecondaryOnlyButton = true - rootViewController.preferredDisplayMode = UISplitViewController.DisplayMode(rawValue: AppDefaults.shared.splitViewPreferredDisplayMode) ?? .oneBesideSecondary + rootViewController.preferredDisplayMode = UISplitViewController.DisplayMode(rawValue: AppDefaults.splitViewPreferredDisplayMode) ?? .oneBesideSecondary // On first run on iPad, show all three columns so the sidebar is visible - if AppDefaults.shared.isFirstRun && UIDevice.current.userInterfaceIdiom == .pad { + if AppDefaults.isFirstRun && UIDevice.current.userInterfaceIdiom == .pad { rootViewController.preferredDisplayMode = .twoBesideSecondary } diff --git a/iOS/Settings/AddAccountView.swift b/iOS/Settings/AddAccountView.swift index 15efee406..bf68330c8 100644 --- a/iOS/Settings/AddAccountView.swift +++ b/iOS/Settings/AddAccountView.swift @@ -129,7 +129,7 @@ struct AddAccountView: View { } private func visibleAccountTypes(in group: AccountGroup) -> [AccountType] { - group.accountTypes.filter { !(AppDefaults.shared.isDeveloperBuild && $0.isDeveloperRestricted) } + group.accountTypes.filter { !(AppDefaults.isDeveloperBuild && $0.isDeveloperRestricted) } } private func isDisabled(_ accountType: AccountType) -> Bool { diff --git a/iOS/Settings/SettingsViewController.swift b/iOS/Settings/SettingsViewController.swift index 130cf8fbb..5e0a353cc 100644 --- a/iOS/Settings/SettingsViewController.swift +++ b/iOS/Settings/SettingsViewController.swift @@ -110,19 +110,19 @@ final class SettingsViewController: UITableViewController { override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) - if AppDefaults.shared.timelineSortDirection == .orderedAscending { + if AppDefaults.timelineSortDirection == .orderedAscending { timelineSortOrderSwitch.isOn = true } else { timelineSortOrderSwitch.isOn = false } - if AppDefaults.shared.timelineGroupByFeed { + if AppDefaults.timelineGroupByFeed { groupByFeedSwitch.isOn = true } else { groupByFeedSwitch.isOn = false } - if AppDefaults.shared.refreshClearsReadArticles { + if AppDefaults.refreshClearsReadArticles { refreshClearsReadArticlesSwitch.isOn = true } else { refreshClearsReadArticlesSwitch.isOn = false @@ -130,25 +130,25 @@ final class SettingsViewController: UITableViewController { articleThemeDetailLabel.text = ArticleThemesManager.shared.currentTheme.name - if AppDefaults.shared.confirmMarkAllAsRead { + if AppDefaults.confirmMarkAllAsRead { confirmMarkAllAsReadSwitch.isOn = true } else { confirmMarkAllAsReadSwitch.isOn = false } - if AppDefaults.shared.articleFullscreenAvailable { + if AppDefaults.articleFullscreenAvailable { showFullscreenArticlesSwitch.isOn = true } else { showFullscreenArticlesSwitch.isOn = false } - if AppDefaults.shared.isArticleContentJavascriptEnabled { + if AppDefaults.isArticleContentJavascriptEnabled { enableJavaScriptSwitch.isOn = true } else { enableJavaScriptSwitch.isOn = false } - openLinksInNetNewsWire.isOn = !AppDefaults.shared.useSystemBrowser + openLinksInNetNewsWire.isOn = !AppDefaults.useSystemBrowser let buildLabel = CopyableLabel(frame: CGRect(x: 32.0, y: 0.0, width: 0.0, height: 0.0)) buildLabel.font = UIFont.systemFont(ofSize: 11.0) @@ -362,54 +362,54 @@ final class SettingsViewController: UITableViewController { @IBAction func switchTimelineOrder(_ sender: Any) { if timelineSortOrderSwitch.isOn { - AppDefaults.shared.timelineSortDirection = .orderedAscending + AppDefaults.timelineSortDirection = .orderedAscending } else { - AppDefaults.shared.timelineSortDirection = .orderedDescending + AppDefaults.timelineSortDirection = .orderedDescending } } @IBAction func switchGroupByFeed(_ sender: Any) { if groupByFeedSwitch.isOn { - AppDefaults.shared.timelineGroupByFeed = true + AppDefaults.timelineGroupByFeed = true } else { - AppDefaults.shared.timelineGroupByFeed = false + AppDefaults.timelineGroupByFeed = false } } @IBAction func switchClearsReadArticles(_ sender: Any) { if refreshClearsReadArticlesSwitch.isOn { - AppDefaults.shared.refreshClearsReadArticles = true + AppDefaults.refreshClearsReadArticles = true } else { - AppDefaults.shared.refreshClearsReadArticles = false + AppDefaults.refreshClearsReadArticles = false } } @IBAction func switchConfirmMarkAllAsRead(_ sender: Any) { if confirmMarkAllAsReadSwitch.isOn { - AppDefaults.shared.confirmMarkAllAsRead = true + AppDefaults.confirmMarkAllAsRead = true } else { - AppDefaults.shared.confirmMarkAllAsRead = false + AppDefaults.confirmMarkAllAsRead = false } } @IBAction func switchFullscreenArticles(_ sender: Any) { if showFullscreenArticlesSwitch.isOn { - AppDefaults.shared.articleFullscreenAvailable = true + AppDefaults.articleFullscreenAvailable = true } else { - AppDefaults.shared.articleFullscreenAvailable = false + AppDefaults.articleFullscreenAvailable = false } } @IBAction func switchBrowserPreference(_ sender: Any) { if openLinksInNetNewsWire.isOn { - AppDefaults.shared.useSystemBrowser = false + AppDefaults.useSystemBrowser = false } else { - AppDefaults.shared.useSystemBrowser = true + AppDefaults.useSystemBrowser = true } } @IBAction func switchJavaScriptPreference(_ sender: Any) { - AppDefaults.shared.isArticleContentJavascriptEnabled = enableJavaScriptSwitch.isOn + AppDefaults.isArticleContentJavascriptEnabled = enableJavaScriptSwitch.isOn } // MARK: - Notifications @@ -502,10 +502,10 @@ private extension SettingsViewController { } func updateUnreadCountDisplayPopUpButton() { - let currentUnreadCountDisplay = AppDefaults.shared.unreadCountDisplay + let currentUnreadCountDisplay = AppDefaults.unreadCountDisplay let actions = UnreadCountDisplay.allCases.map { unreadCountDisplay in UIAction(title: String(describing: unreadCountDisplay), state: unreadCountDisplay == currentUnreadCountDisplay ? .on : .off) { _ in - AppDefaults.shared.unreadCountDisplay = unreadCountDisplay + AppDefaults.unreadCountDisplay = unreadCountDisplay } } unreadCountDisplayPopUpButton.menu = UIMenu(children: actions) diff --git a/iOS/Settings/TimelineCustomizerCell.swift b/iOS/Settings/TimelineCustomizerCell.swift index 80b01faa8..00b84e21b 100644 --- a/iOS/Settings/TimelineCustomizerCell.swift +++ b/iOS/Settings/TimelineCustomizerCell.swift @@ -26,7 +26,7 @@ final class TimelineCustomizerCell: UICollectionViewCell { if #available(iOS 26, *) { slider.trackConfiguration = .init(allowsTickValuesOnly: true, numberOfTicks: 6) } - slider.value = Float(AppDefaults.shared.timelineNumberOfLines) + slider.value = Float(AppDefaults.timelineNumberOfLines) slider.addTickMarks() case .iconSize: slider.minimumValue = 1 @@ -34,7 +34,7 @@ final class TimelineCustomizerCell: UICollectionViewCell { if #available(iOS 26, *) { slider.trackConfiguration = .init(allowsTickValuesOnly: true, numberOfTicks: 3) } - slider.value = Float(AppDefaults.shared.timelineIconSize.rawValue) + slider.value = Float(AppDefaults.timelineIconSize.rawValue) slider.addTickMarks() case .none: return @@ -45,10 +45,10 @@ final class TimelineCustomizerCell: UICollectionViewCell { @IBAction func sliderValueChanges(_ sender: Any) { switch sliderConfiguration { case .numberOfLines: - AppDefaults.shared.timelineNumberOfLines = Int(slider.value.rounded()) + AppDefaults.timelineNumberOfLines = Int(slider.value.rounded()) case .iconSize: guard let iconSize = IconSize(rawValue: Int(slider.value.rounded())) else { return } - AppDefaults.shared.timelineIconSize = iconSize + AppDefaults.timelineIconSize = iconSize case .none: return } diff --git a/iOS/Settings/TimelineCustomizerCollectionViewController.swift b/iOS/Settings/TimelineCustomizerCollectionViewController.swift index e31bf302a..30134df9e 100644 --- a/iOS/Settings/TimelineCustomizerCollectionViewController.swift +++ b/iOS/Settings/TimelineCustomizerCollectionViewController.swift @@ -38,8 +38,8 @@ class TimelineCustomizerCollectionViewController: UICollectionViewController { status: ArticleStatus(articleID: "_testArticleID", read: false, starred: false, dateArrived: .now)) } - private var cachedTimelineLines: Int = AppDefaults.shared.timelineNumberOfLines - private var cachedIconSize: IconSize = AppDefaults.shared.timelineIconSize + private var cachedTimelineLines: Int = AppDefaults.timelineNumberOfLines + private var cachedIconSize: IconSize = AppDefaults.timelineIconSize override func viewDidLoad() { super.viewDidLoad() @@ -49,13 +49,13 @@ class TimelineCustomizerCollectionViewController: UICollectionViewController { guard let self = self else { return } Task { @MainActor in - if AppDefaults.shared.timelineNumberOfLines != self.cachedTimelineLines { - self.cachedTimelineLines = AppDefaults.shared.timelineNumberOfLines + if AppDefaults.timelineNumberOfLines != self.cachedTimelineLines { + self.cachedTimelineLines = AppDefaults.timelineNumberOfLines self.userDefaultsDidChange() } - if AppDefaults.shared.timelineIconSize != self.cachedIconSize { - self.cachedIconSize = AppDefaults.shared.timelineIconSize + if AppDefaults.timelineIconSize != self.cachedIconSize { + self.cachedIconSize = AppDefaults.timelineIconSize self.userDefaultsDidChange() } } @@ -115,8 +115,8 @@ class TimelineCustomizerCollectionViewController: UICollectionViewController { byline: "J. R. R. Tolkien", iconImage: IconImage(Assets.Images.nnwFeedIcon), showIcon: false, - numberOfLines: AppDefaults.shared.timelineNumberOfLines, - iconSize: AppDefaults.shared.timelineIconSize) + numberOfLines: AppDefaults.timelineNumberOfLines, + iconSize: AppDefaults.timelineIconSize) cell.isPreview = true return cell } @@ -129,8 +129,8 @@ class TimelineCustomizerCollectionViewController: UICollectionViewController { byline: "J. R. R. Tolkien", iconImage: IconImage(Assets.Images.nnwFeedIcon), showIcon: true, - numberOfLines: AppDefaults.shared.timelineNumberOfLines, - iconSize: AppDefaults.shared.timelineIconSize) + numberOfLines: AppDefaults.timelineNumberOfLines, + iconSize: AppDefaults.timelineIconSize) cell.isPreview = true return cell }