From 5f6445c953ee15bbe28e95fb5f379a3b63382646 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Wed, 18 Mar 2026 20:48:10 -0700 Subject: [PATCH 01/16] Create AppDefaults+Shared. Create wrapper and migration for the new iCloudSyncArticleContentForUnreadArticles setting. --- Shared/AppDefaults+Shared.swift | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Shared/AppDefaults+Shared.swift diff --git a/Shared/AppDefaults+Shared.swift b/Shared/AppDefaults+Shared.swift new file mode 100644 index 000000000..4f02d5be4 --- /dev/null +++ b/Shared/AppDefaults+Shared.swift @@ -0,0 +1,33 @@ +// +// AppDefaults+Shared.swift +// NetNewsWire +// +// Created by Brent Simmons on 3/18/26. +// Copyright © 2026 Ranchero Software. All rights reserved. +// + +import Foundation +import Account + +extension AppDefaults { + + static let iCloudSyncArticleContentForUnreadArticles = "iCloudSyncArticleContentForUnreadArticles" + + var iCloudSyncArticleContentForUnreadArticles: Bool { + get { + UserDefaults.standard.bool(forKey: Self.iCloudSyncArticleContentForUnreadArticles) + } + set { + UserDefaults.standard.set(newValue, forKey: Self.iCloudSyncArticleContentForUnreadArticles) + } + } + + func migrateiCloudSyncArticleContentForUnreadArticlesSetting() { + // iCloudSyncArticleContentForUnreadArticles should be set to false unless + // the user already has an iCloud account. + guard UserDefaults.standard.object(forKey: Self.iCloudSyncArticleContentForUnreadArticles) == nil else { + return + } + iCloudSyncArticleContentForUnreadArticles = AccountManager.shared.hasiCloudAccount + } +} From 25cf159110ad2f4ad2f9322131812cad3e602fc2 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Wed, 18 Mar 2026 20:48:30 -0700 Subject: [PATCH 02/16] Migrate the new iCloud setting on launch. --- Mac/AppDelegate.swift | 2 +- iOS/AppDelegate.swift | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Mac/AppDelegate.swift b/Mac/AppDelegate.swift index 203b7d9f1..85e1babba 100644 --- a/Mac/AppDelegate.swift +++ b/Mac/AppDelegate.swift @@ -179,7 +179,7 @@ let appName = "NetNewsWire" Self.logger.debug("Is first run.") } let localAccount = AccountManager.shared.defaultAccount - + AppDefaults.shared.migrateiCloudSyncArticleContentForUnreadArticlesSetting() if isFirstRun && !AccountManager.shared.anyAccountHasAtLeastOneFeed() { // Import default feeds. DefaultFeedsImporter.importDefaultFeeds(account: localAccount) diff --git a/iOS/AppDelegate.swift b/iOS/AppDelegate.swift index 2e026bef1..9292de438 100644 --- a/iOS/AppDelegate.swift +++ b/iOS/AppDelegate.swift @@ -71,6 +71,7 @@ import ErrorLog let localAccount = AccountManager.shared.defaultAccount DefaultFeedsImporter.importDefaultFeeds(account: localAccount) } + AppDefaults.shared.migrateiCloudSyncArticleContentForUnreadArticlesSetting() registerBackgroundTasks() CacheCleaner.purgeIfNecessary() From 76fddfb16535442ecdd2a2de9ce1c90f20510711 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Wed, 18 Mar 2026 21:02:09 -0700 Subject: [PATCH 03/16] Fix concurrency error. Mark as @MainActor. --- Shared/AppDefaults+Shared.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Shared/AppDefaults+Shared.swift b/Shared/AppDefaults+Shared.swift index 4f02d5be4..ff05af50f 100644 --- a/Shared/AppDefaults+Shared.swift +++ b/Shared/AppDefaults+Shared.swift @@ -22,7 +22,7 @@ extension AppDefaults { } } - func migrateiCloudSyncArticleContentForUnreadArticlesSetting() { + @MainActor func migrateiCloudSyncArticleContentForUnreadArticlesSetting() { // iCloudSyncArticleContentForUnreadArticles should be set to false unless // the user already has an iCloud account. guard UserDefaults.standard.object(forKey: Self.iCloudSyncArticleContentForUnreadArticles) == nil else { From 0dd71cd747f4e2cc5f4f84351c38941afca78a94 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Wed, 18 Mar 2026 21:10:28 -0700 Subject: [PATCH 04/16] Remove iCloud setting migration from AppDelegate. --- Mac/AppDelegate.swift | 1 - iOS/AppDelegate.swift | 1 - 2 files changed, 2 deletions(-) diff --git a/Mac/AppDelegate.swift b/Mac/AppDelegate.swift index 85e1babba..7ea878eba 100644 --- a/Mac/AppDelegate.swift +++ b/Mac/AppDelegate.swift @@ -179,7 +179,6 @@ let appName = "NetNewsWire" Self.logger.debug("Is first run.") } let localAccount = AccountManager.shared.defaultAccount - AppDefaults.shared.migrateiCloudSyncArticleContentForUnreadArticlesSetting() if isFirstRun && !AccountManager.shared.anyAccountHasAtLeastOneFeed() { // Import default feeds. DefaultFeedsImporter.importDefaultFeeds(account: localAccount) diff --git a/iOS/AppDelegate.swift b/iOS/AppDelegate.swift index 9292de438..2e026bef1 100644 --- a/iOS/AppDelegate.swift +++ b/iOS/AppDelegate.swift @@ -71,7 +71,6 @@ import ErrorLog let localAccount = AccountManager.shared.defaultAccount DefaultFeedsImporter.importDefaultFeeds(account: localAccount) } - AppDefaults.shared.migrateiCloudSyncArticleContentForUnreadArticlesSetting() registerBackgroundTasks() CacheCleaner.purgeIfNecessary() From 75cbc810b5a5fd028700406bd38752cd67b34ed5 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Wed, 18 Mar 2026 21:25:06 -0700 Subject: [PATCH 05/16] Delete AppDefaults+Shared. No longer needed. --- Shared/AppDefaults+Shared.swift | 33 --------------------------------- 1 file changed, 33 deletions(-) delete mode 100644 Shared/AppDefaults+Shared.swift diff --git a/Shared/AppDefaults+Shared.swift b/Shared/AppDefaults+Shared.swift deleted file mode 100644 index ff05af50f..000000000 --- a/Shared/AppDefaults+Shared.swift +++ /dev/null @@ -1,33 +0,0 @@ -// -// AppDefaults+Shared.swift -// NetNewsWire -// -// Created by Brent Simmons on 3/18/26. -// Copyright © 2026 Ranchero Software. All rights reserved. -// - -import Foundation -import Account - -extension AppDefaults { - - static let iCloudSyncArticleContentForUnreadArticles = "iCloudSyncArticleContentForUnreadArticles" - - var iCloudSyncArticleContentForUnreadArticles: Bool { - get { - UserDefaults.standard.bool(forKey: Self.iCloudSyncArticleContentForUnreadArticles) - } - set { - UserDefaults.standard.set(newValue, forKey: Self.iCloudSyncArticleContentForUnreadArticles) - } - } - - @MainActor func migrateiCloudSyncArticleContentForUnreadArticlesSetting() { - // iCloudSyncArticleContentForUnreadArticles should be set to false unless - // the user already has an iCloud account. - guard UserDefaults.standard.object(forKey: Self.iCloudSyncArticleContentForUnreadArticles) == nil else { - return - } - iCloudSyncArticleContentForUnreadArticles = AccountManager.shared.hasiCloudAccount - } -} From 5c9f09e56937d1d8d374733a5d08a783db961284 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Wed, 18 Mar 2026 21:25:46 -0700 Subject: [PATCH 06/16] Handle the syncArticleContentForUnreadArticles setting. --- .../CloudKit/CloudKitAccountDelegate.swift | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift b/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift index 99aafd673..74d45561d 100644 --- a/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift +++ b/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift @@ -76,6 +76,17 @@ enum CloudKitAccountDelegateError: LocalizedError, Sendable { } } + private static let syncArticleContentForUnreadArticlesKey = "iCloudSyncArticleContentForUnreadArticles" + + static var syncArticleContentForUnreadArticles: Bool { + get { + UserDefaults.standard.bool(forKey: syncArticleContentForUnreadArticlesKey) + } + set { + UserDefaults.standard.set(newValue, forKey: syncArticleContentForUnreadArticlesKey) + } + } + init(dataFolder: String) { Self.logger.debug("CloudKitAccountDelegate: \(#function, privacy: .public)") self.accountZone = CloudKitAccountZone(container: container) @@ -86,12 +97,22 @@ enum CloudKitAccountDelegateError: LocalizedError, Sendable { self.refresher = LocalAccountRefresher() self.refresher.delegate = self + self.articlesZone.settings = self NotificationCenter.default.addObserver(self, selector: #selector(refreshProgressDidChange(_:)), name: .progressInfoDidChange, object: refresher) NotificationCenter.default.addObserver(self, selector: #selector(syncProgressDidChange(_:)), name: .progressInfoDidChange, object: syncProgress) Self.logger.debug("CloudKitAccountDelegate: \(#function, privacy: .public) did complete") } + static func migrateiCloudSyncArticleContentForUnreadArticlesSetting(hasiCloudAccount: Bool) { + // iCloudSyncArticleContentForUnreadArticles should be set to false unless + // the user already has an iCloud account. + guard UserDefaults.standard.object(forKey: syncArticleContentForUnreadArticlesKey) == nil else { + return + } + syncArticleContentForUnreadArticles = hasiCloudAccount + } + func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable: Any]) async { Self.logger.debug("CloudKitAccountDelegate: \(#function, privacy: .public)") await withCheckedContinuation { continuation in @@ -766,7 +787,8 @@ private extension CloudKitAccountDelegate { try await withCheckedThrowingContinuation { (continuation: CheckedContinuation) in let op = CloudKitSendStatusOperation(account: account, articlesZone: articlesZone, - database: syncDatabase) + database: syncDatabase, + settings: self) op.completionBlock = { mainThreadOperation in Self.logger.debug("CloudKitAccountDelegate: \(#function, privacy: .public) did complete") if mainThreadOperation.isCanceled { From af288dc8165e55dc1b77cc019920182c1aade2f0 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Wed, 18 Mar 2026 21:26:27 -0700 Subject: [PATCH 07/16] Call CloudKitAccountDelegate to migrate the new iCloud setting for syncing content of unread articles. --- Modules/Account/Sources/Account/AccountManager.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Modules/Account/Sources/Account/AccountManager.swift b/Modules/Account/Sources/Account/AccountManager.swift index 0f8eb79d7..ac153c044 100644 --- a/Modules/Account/Sources/Account/AccountManager.swift +++ b/Modules/Account/Sources/Account/AccountManager.swift @@ -123,6 +123,8 @@ import ErrorLog accountsDictionary[defaultAccount.accountID] = defaultAccount readAccountsFromDisk() + + CloudKitAccountDelegate.migrateiCloudSyncArticleContentForUnreadArticlesSetting(hasiCloudAccount: hasiCloudAccount) } public func start() { From 2a99a24fc317195985eec5eb004b997db1d06c93 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Wed, 18 Mar 2026 21:26:56 -0700 Subject: [PATCH 08/16] Create CloudKitSettings protocol to have a thing to pass around for the syncArticleContentForUnreadArticles setting. --- .../Account/CloudKit/CloudKitSettings.swift | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Modules/Account/Sources/Account/CloudKit/CloudKitSettings.swift diff --git a/Modules/Account/Sources/Account/CloudKit/CloudKitSettings.swift b/Modules/Account/Sources/Account/CloudKit/CloudKitSettings.swift new file mode 100644 index 000000000..90e5bace5 --- /dev/null +++ b/Modules/Account/Sources/Account/CloudKit/CloudKitSettings.swift @@ -0,0 +1,19 @@ +// +// CloudKitSettings.swift +// Account +// +// Created by Brent Simmons on 3/18/26. +// + +import Foundation + +protocol CloudKitSettings { + var syncArticleContentForUnreadArticles: Bool { get } +} + +extension CloudKitAccountDelegate: CloudKitSettings { + + var syncArticleContentForUnreadArticles: Bool { + CloudKitAccountDelegate.syncArticleContentForUnreadArticles + } +} From 143e79138a1dbbeaa10677629d5923c51e2f5442 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Wed, 18 Mar 2026 21:42:22 -0700 Subject: [PATCH 09/16] Pass CloudKitSettings around as needed and use it to check if syncing content of unread articles. --- .../CloudKitArticleStatusUpdate.swift | 11 ++++++--- .../CloudKit/CloudKitArticlesZone.swift | 23 +++++++++++++++---- .../CloudKitSendStatusOperation.swift | 6 +++-- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/Modules/Account/Sources/Account/CloudKit/CloudKitArticleStatusUpdate.swift b/Modules/Account/Sources/Account/CloudKit/CloudKitArticleStatusUpdate.swift index 7cd1a2aec..f70852982 100644 --- a/Modules/Account/Sources/Account/CloudKit/CloudKitArticleStatusUpdate.swift +++ b/Modules/Account/Sources/Account/CloudKit/CloudKitArticleStatusUpdate.swift @@ -22,11 +22,13 @@ struct CloudKitArticleStatusUpdate { var articleID: String var statuses: [SyncStatus] var article: Article? + var settings: any CloudKitSettings - init?(articleID: String, statuses: [SyncStatus], article: Article?) { + init?(articleID: String, statuses: [SyncStatus], article: Article?, settings: any CloudKitSettings) { self.articleID = articleID self.statuses = statuses self.article = article + self.settings = settings let rec = record // This is an invalid status update. The article is required for new and all @@ -44,8 +46,11 @@ struct CloudKitArticleStatusUpdate { return .new } - if let article = article { - if article.status.read == false || article.status.starred == true { + if let article { + if article.status.starred { + return .all + } + if !article.status.read && settings.syncArticleContentForUnreadArticles { return .all } } diff --git a/Modules/Account/Sources/Account/CloudKit/CloudKitArticlesZone.swift b/Modules/Account/Sources/Account/CloudKit/CloudKitArticlesZone.swift index 4055ca48f..45e016e94 100644 --- a/Modules/Account/Sources/Account/CloudKit/CloudKitArticlesZone.swift +++ b/Modules/Account/Sources/Account/CloudKit/CloudKitArticlesZone.swift @@ -55,6 +55,8 @@ final class CloudKitArticlesZone: CloudKitZone { } } + var settings: (any CloudKitSettings)! + init(container: CKContainer) { self.container = container self.database = container.privateCloudDatabase @@ -82,10 +84,17 @@ final class CloudKitArticlesZone: CloudKitZone { var records = [CKRecord]() - let saveArticles = articles.filter { $0.status.read == false || $0.status.starred == true } - for saveArticle in saveArticles { - records.append(makeStatusRecord(saveArticle)) - records.append(makeArticleRecord(saveArticle)) + let syncUnreadContent = settings.syncArticleContentForUnreadArticles + for article in articles { + if article.status.starred { + records.append(makeStatusRecord(article)) + records.append(makeArticleRecord(article)) + } else if !article.status.read { + records.append(makeStatusRecord(article)) + if syncUnreadContent { + records.append(makeArticleRecord(article)) + } + } } let compressedRecords = await Task.detached(priority: .userInitiated) { @@ -109,6 +118,8 @@ final class CloudKitArticlesZone: CloudKitZone { var newRecords = [CKRecord]() var deleteRecordIDs = [CKRecord.ID]() + let syncUnreadContent = settings.syncArticleContentForUnreadArticles + for statusUpdate in statusUpdates { switch statusUpdate.record { case .all: @@ -116,7 +127,9 @@ final class CloudKitArticlesZone: CloudKitZone { modifyRecords.append(self.makeArticleRecord(statusUpdate.article!)) case .new: newRecords.append(self.makeStatusRecord(statusUpdate)) - newRecords.append(self.makeArticleRecord(statusUpdate.article!)) + if statusUpdate.article!.status.starred || syncUnreadContent { + newRecords.append(self.makeArticleRecord(statusUpdate.article!)) + } case .delete: deleteRecordIDs.append(CKRecord.ID(recordName: self.statusID(statusUpdate.articleID), zoneID: zoneID)) case .statusOnly: diff --git a/Modules/Account/Sources/Account/CloudKit/CloudKitSendStatusOperation.swift b/Modules/Account/Sources/Account/CloudKit/CloudKitSendStatusOperation.swift index 086213b08..7f3cd9bd1 100644 --- a/Modules/Account/Sources/Account/CloudKit/CloudKitSendStatusOperation.swift +++ b/Modules/Account/Sources/Account/CloudKit/CloudKitSendStatusOperation.swift @@ -19,12 +19,14 @@ final class CloudKitSendStatusOperation: MainThreadOperation, @unchecked Sendabl private weak var account: Account? private weak var articlesZone: CloudKitArticlesZone? private var syncDatabase: SyncDatabase + private let settings: any CloudKitSettings private static let logger = cloudKitLogger - init(account: Account, articlesZone: CloudKitArticlesZone, database: SyncDatabase) { + init(account: Account, articlesZone: CloudKitArticlesZone, database: SyncDatabase, settings: any CloudKitSettings) { self.account = account self.articlesZone = articlesZone self.syncDatabase = database + self.settings = settings super.init(name: "CloudKitSendStatusOperation") } @@ -81,7 +83,7 @@ final class CloudKitSendStatusOperation: MainThreadOperation, @unchecked Sendabl result[article.articleID] = article } let statusUpdates = syncStatusesDict.compactMap { (key, value) in - CloudKitArticleStatusUpdate(articleID: key, statuses: value, article: articlesDict[key]) + CloudKitArticleStatusUpdate(articleID: key, statuses: value, article: articlesDict[key], settings: self.settings) } // If this happens, we have somehow gotten into a state where we have new status records From e4df1f3dd8944ef17f6dad694754fd6258b9f54d Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Thu, 19 Mar 2026 10:14:37 -0700 Subject: [PATCH 10/16] Fix (hopefully) type-checker timeouts. --- .../OPML/ExportOPMLWindowController.swift | 18 +++++++++++------- .../OPML/ImportOPMLWindowController.swift | 17 ++++++++++------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/Mac/MainWindow/OPML/ExportOPMLWindowController.swift b/Mac/MainWindow/OPML/ExportOPMLWindowController.swift index 0e888094d..909848676 100644 --- a/Mac/MainWindow/OPML/ExportOPMLWindowController.swift +++ b/Mac/MainWindow/OPML/ExportOPMLWindowController.swift @@ -29,14 +29,18 @@ final class ExportOPMLWindowController: NSWindowController { let savedAccountID: String? = AppDefaults.shared.exportOPMLAccountID for oneAccount in accounts { - let oneMenuItem = NSMenuItem() - oneMenuItem.title = oneAccount.nameForDisplay - oneMenuItem.representedObject = oneAccount - menu.addItem(oneMenuItem) + addMenuItem(to: menu, for: oneAccount, savedAccountID: savedAccountID) + } + } - if oneAccount.accountID == savedAccountID { - accountPopUpButton.select(oneMenuItem) - } + private func addMenuItem(to menu: NSMenu, for account: Account, savedAccountID: String?) { + let menuItem = NSMenuItem() + menuItem.title = account.nameForDisplay + menuItem.representedObject = account + menu.addItem(menuItem) + + if account.accountID == savedAccountID { + accountPopUpButton.select(menuItem) } } diff --git a/Mac/MainWindow/OPML/ImportOPMLWindowController.swift b/Mac/MainWindow/OPML/ImportOPMLWindowController.swift index 79c48c2ad..7f68d6ab3 100644 --- a/Mac/MainWindow/OPML/ImportOPMLWindowController.swift +++ b/Mac/MainWindow/OPML/ImportOPMLWindowController.swift @@ -32,15 +32,18 @@ final class ImportOPMLWindowController: NSWindowController { if oneAccount.behaviors.contains(.disallowOPMLImports) { continue } + addMenuItem(to: menu, for: oneAccount, savedAccountID: savedAccountID) + } + } - let oneMenuItem = NSMenuItem() - oneMenuItem.title = oneAccount.nameForDisplay - oneMenuItem.representedObject = oneAccount - menu.addItem(oneMenuItem) + private func addMenuItem(to menu: NSMenu, for account: Account, savedAccountID: String?) { + let menuItem = NSMenuItem() + menuItem.title = account.nameForDisplay + menuItem.representedObject = account + menu.addItem(menuItem) - if oneAccount.accountID == savedAccountID { - accountPopUpButton.select(oneMenuItem) - } + if account.accountID == savedAccountID { + accountPopUpButton.select(menuItem) } } From dd39dae9451011611b3e59221eee6c14b350c9b7 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Thu, 19 Mar 2026 10:15:18 -0700 Subject: [PATCH 11/16] Move key for iCloud content syncing to Account so it's available to settings screens. --- Modules/Account/Sources/Account/Account.swift | 2 ++ .../Account/CloudKit/CloudKitAccountDelegate.swift | 8 +++----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Modules/Account/Sources/Account/Account.swift b/Modules/Account/Sources/Account/Account.swift index ed9de5368..ba99e706c 100644 --- a/Modules/Account/Sources/Account/Account.swift +++ b/Modules/Account/Sources/Account/Account.swift @@ -101,6 +101,8 @@ public enum FetchType { public static let syncErrors = "syncErrors" // AccountsDidFailToSyncWithErrors } + public static let iCloudSyncArticleContentForUnreadArticlesKey = "iCloudSyncArticleContentForUnreadArticles" + public var isDeleted = false public var containerID: ContainerIdentifier? { diff --git a/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift b/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift index 74d45561d..b61566404 100644 --- a/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift +++ b/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift @@ -76,14 +76,12 @@ enum CloudKitAccountDelegateError: LocalizedError, Sendable { } } - private static let syncArticleContentForUnreadArticlesKey = "iCloudSyncArticleContentForUnreadArticles" - static var syncArticleContentForUnreadArticles: Bool { get { - UserDefaults.standard.bool(forKey: syncArticleContentForUnreadArticlesKey) + UserDefaults.standard.bool(forKey: Account.iCloudSyncArticleContentForUnreadArticlesKey) } set { - UserDefaults.standard.set(newValue, forKey: syncArticleContentForUnreadArticlesKey) + UserDefaults.standard.set(newValue, forKey: Account.iCloudSyncArticleContentForUnreadArticlesKey) } } @@ -107,7 +105,7 @@ enum CloudKitAccountDelegateError: LocalizedError, Sendable { static func migrateiCloudSyncArticleContentForUnreadArticlesSetting(hasiCloudAccount: Bool) { // iCloudSyncArticleContentForUnreadArticles should be set to false unless // the user already has an iCloud account. - guard UserDefaults.standard.object(forKey: syncArticleContentForUnreadArticlesKey) == nil else { + guard UserDefaults.standard.object(forKey: Account.iCloudSyncArticleContentForUnreadArticlesKey) == nil else { return } syncArticleContentForUnreadArticles = hasiCloudAccount From b6a61485cb7019b1ffd27565eb596080590d2315 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Thu, 19 Mar 2026 10:17:41 -0700 Subject: [PATCH 12/16] Fix (hopefully) type-checker timeout. --- Mac/MainWindow/NNW3/NNW3OpenPanelAccessoryViewController.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Mac/MainWindow/NNW3/NNW3OpenPanelAccessoryViewController.swift b/Mac/MainWindow/NNW3/NNW3OpenPanelAccessoryViewController.swift index b7cd973c0..c62c6f1b4 100644 --- a/Mac/MainWindow/NNW3/NNW3OpenPanelAccessoryViewController.swift +++ b/Mac/MainWindow/NNW3/NNW3OpenPanelAccessoryViewController.swift @@ -17,7 +17,8 @@ final class NNW3OpenPanelAccessoryViewController: NSViewController { guard let item: NSMenuItem = accountPopUpButton.selectedItem else { return nil } - return item.representedObject as? Account + let account: Account? = item.representedObject as? Account + return account } init() { From 86ec02579984259b1b7013f9270099a2bf5ce90c Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Thu, 19 Mar 2026 11:24:50 -0700 Subject: [PATCH 13/16] Add debug logging to show when it's skipping syncing content of unread articles. --- .../Sources/Account/CloudKit/CloudKitArticlesZone.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Modules/Account/Sources/Account/CloudKit/CloudKitArticlesZone.swift b/Modules/Account/Sources/Account/CloudKit/CloudKitArticlesZone.swift index 45e016e94..bc33678a6 100644 --- a/Modules/Account/Sources/Account/CloudKit/CloudKitArticlesZone.swift +++ b/Modules/Account/Sources/Account/CloudKit/CloudKitArticlesZone.swift @@ -17,6 +17,8 @@ import SyncDatabase import CloudKitSync final class CloudKitArticlesZone: CloudKitZone { + + private static let logger = cloudKitLogger var zoneID: CKRecordZone.ID weak var container: CKContainer? @@ -85,6 +87,8 @@ final class CloudKitArticlesZone: CloudKitZone { var records = [CKRecord]() let syncUnreadContent = settings.syncArticleContentForUnreadArticles + Self.logger.info("CloudKitArticlesZone: saveNewArticles syncUnreadContent: \(syncUnreadContent, privacy: .public)") + for article in articles { if article.status.starred { records.append(makeStatusRecord(article)) @@ -93,6 +97,8 @@ final class CloudKitArticlesZone: CloudKitZone { records.append(makeStatusRecord(article)) if syncUnreadContent { records.append(makeArticleRecord(article)) + } else { + Self.logger.debug("CloudKitArticlesZone: saveNewArticles skipping content for unread article \(article.articleID, privacy: .public)") } } } @@ -119,6 +125,7 @@ final class CloudKitArticlesZone: CloudKitZone { var deleteRecordIDs = [CKRecord.ID]() let syncUnreadContent = settings.syncArticleContentForUnreadArticles + Self.logger.info("CloudKitArticlesZone: modifyArticles syncUnreadContent: \(syncUnreadContent, privacy: .public)") for statusUpdate in statusUpdates { switch statusUpdate.record { @@ -129,6 +136,8 @@ final class CloudKitArticlesZone: CloudKitZone { newRecords.append(self.makeStatusRecord(statusUpdate)) if statusUpdate.article!.status.starred || syncUnreadContent { newRecords.append(self.makeArticleRecord(statusUpdate.article!)) + } else { + Self.logger.debug("CloudKitArticlesZone: modifyArticles skipping content for unread article \(statusUpdate.articleID, privacy: .public)") } case .delete: deleteRecordIDs.append(CKRecord.ID(recordName: self.statusID(statusUpdate.articleID), zoneID: zoneID)) From a11b75d826b61003c7ee5c28c7a972fb95eb07a8 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Thu, 19 Mar 2026 11:39:44 -0700 Subject: [PATCH 14/16] Replace AccountsDetail view with SwiftUI view. Add checkbox for iCloud syncing contents of unread articles. --- Mac/Base.lproj/Preferences.storyboard | 2 +- .../Accounts/AccountsAddCloudKit.xib | 21 ++- Mac/Preferences/Accounts/AccountsAddLocal.xib | 31 ++-- Mac/Preferences/Accounts/AccountsDetail.xib | 135 ------------------ .../Accounts/AccountsDetailView.swift | 115 +++++++++++++++ .../AccountsDetailViewController.swift | 54 ++----- 6 files changed, 152 insertions(+), 206 deletions(-) delete mode 100644 Mac/Preferences/Accounts/AccountsDetail.xib create mode 100644 Mac/Preferences/Accounts/AccountsDetailView.swift diff --git a/Mac/Base.lproj/Preferences.storyboard b/Mac/Base.lproj/Preferences.storyboard index 35d4ad895..4ce945c4e 100644 --- a/Mac/Base.lproj/Preferences.storyboard +++ b/Mac/Base.lproj/Preferences.storyboard @@ -532,7 +532,7 @@ - + diff --git a/Mac/Preferences/Accounts/AccountsAddCloudKit.xib b/Mac/Preferences/Accounts/AccountsAddCloudKit.xib index ce029a13e..61ff5ac40 100644 --- a/Mac/Preferences/Accounts/AccountsAddCloudKit.xib +++ b/Mac/Preferences/Accounts/AccountsAddCloudKit.xib @@ -1,8 +1,7 @@ - + - - + @@ -18,29 +17,29 @@ - + - + - - + + - - + + @@ -48,7 +47,7 @@ - + @@ -75,16 +74,16 @@ Gw - - + + - - + + @@ -94,7 +93,7 @@ Gw - + diff --git a/Mac/Preferences/Accounts/AccountsDetail.xib b/Mac/Preferences/Accounts/AccountsDetail.xib deleted file mode 100644 index 0fc570b52..000000000 --- a/Mac/Preferences/Accounts/AccountsDetail.xib +++ /dev/null @@ -1,135 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - The name appears in the sidebar. It can be anything you want. You can even use emoji. 🎸 - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Mac/Preferences/Accounts/AccountsDetailView.swift b/Mac/Preferences/Accounts/AccountsDetailView.swift new file mode 100644 index 000000000..41fcdd4ef --- /dev/null +++ b/Mac/Preferences/Accounts/AccountsDetailView.swift @@ -0,0 +1,115 @@ +// +// AccountsDetailView.swift +// NetNewsWire +// +// Created by Brent Simmons on 3/19/26. +// + +import SwiftUI +import Account + +struct AccountsDetailView: View { + + let account: Account + var onCredentials: (() -> Void)? + + @State private var accountName: String + @State private var isActive: Bool + @State private var syncUnreadContent: Bool + + init(account: Account, onCredentials: (() -> Void)? = nil) { + self.account = account + self.onCredentials = onCredentials + _accountName = State(initialValue: account.name ?? "") + _isActive = State(initialValue: account.isActive) + _syncUnreadContent = State(initialValue: UserDefaults.standard.bool(forKey: Account.iCloudSyncArticleContentForUnreadArticlesKey)) + } + + private var showCredentialsButton: Bool { + switch account.type { + case .onMyMac, .cloudKit, .feedly: + return false + default: + return true + } + } + + var body: some View { + VStack(alignment: .leading, spacing: 0) { + Grid(alignment: .leading, verticalSpacing: 0) { + GridRow(alignment: .firstTextBaseline) { + Text("Type:") + .gridColumnAlignment(.trailing) + Text(account.defaultName) + } + + GridRow { + Color.clear + .gridCellUnsizedAxes([.horizontal, .vertical]) + Toggle("Active", isOn: $isActive) + .onChange(of: isActive) { + account.isActive = isActive + } + .padding(.top, 9) + } + + GridRow(alignment: .firstTextBaseline) { + Text("Name:") + TextField("", text: $accountName) + .frame(width: 150) + .onSubmit { + commitName() + } + .onChange(of: accountName) { + commitName() + } + } + .padding(.top, 14) + + GridRow { + Color.clear + .gridCellUnsizedAxes([.horizontal, .vertical]) + Text("The name can be anything you want. You can even use emoji. 🎸") + .foregroundStyle(.secondary) + .fixedSize(horizontal: false, vertical: true) + .padding(.top, 1) + } + + if showCredentialsButton { + GridRow { + Color.clear + .gridCellUnsizedAxes([.horizontal, .vertical]) + Button("Credentials") { + onCredentials?() + } + .padding(.top, 12) + } + } + } + + if account.type == .cloudKit { + Toggle("Sync content of unread articles", isOn: $syncUnreadContent) + .onChange(of: syncUnreadContent) { + UserDefaults.standard.set(syncUnreadContent, forKey: Account.iCloudSyncArticleContentForUnreadArticlesKey) + } + .padding(.top, 12) + + Text("Syncing article content increases iCloud storage use, sync time, and battery use.\n\nArticle status and the content of starred articles are always synced.") + .foregroundStyle(.secondary) + .fixedSize(horizontal: false, vertical: true) + .padding(.top, 4) + .padding(.leading, 21) + } + } + .padding(20) + .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading) + } + + private func commitName() { + if accountName.isEmpty { + account.name = nil + } else { + account.name = accountName + } + } +} diff --git a/Mac/Preferences/Accounts/AccountsDetailViewController.swift b/Mac/Preferences/Accounts/AccountsDetailViewController.swift index 98a20da6e..2c3b4a6ee 100644 --- a/Mac/Preferences/Accounts/AccountsDetailViewController.swift +++ b/Mac/Preferences/Accounts/AccountsDetailViewController.swift @@ -7,64 +7,32 @@ // import AppKit +import SwiftUI import Account -final class AccountsDetailViewController: NSViewController, NSTextFieldDelegate { - @IBOutlet var typeLabel: NSTextField! - @IBOutlet var nameTextField: NSTextField! - @IBOutlet var activeButton: NSButtonCell! - @IBOutlet var credentialsButton: NSButton! +final class AccountsDetailViewController: NSViewController { + private let account: Account private var accountsWindowController: NSWindowController? - private var account: Account? init(account: Account) { - super.init(nibName: "AccountsDetail", bundle: nil) self.account = account + super.init(nibName: nil, bundle: nil) } public required init?(coder: NSCoder) { - super.init(coder: coder) + fatalError("AccountsDetailViewController does not support init(coder:)") } - private var hidesCredentialsButton: Bool { - guard let account = account else { - return true - } - switch account.type { - case .onMyMac, .cloudKit, .feedly: - return true - default: - return false + override func loadView() { + let detailView = AccountsDetailView(account: account) { [weak self] in + self?.showCredentials() } + let hostingView = NSHostingView(rootView: detailView) + self.view = hostingView } - override func viewDidLoad() { - super.viewDidLoad() - - nameTextField.delegate = self - typeLabel.stringValue = account?.defaultName ?? "" - nameTextField.stringValue = account?.name ?? "" - activeButton.state = account?.isActive ?? false ? .on : .off - credentialsButton.isHidden = hidesCredentialsButton - } - - func controlTextDidEndEditing(_ obj: Notification) { - if !nameTextField.stringValue.isEmpty { - account?.name = nameTextField.stringValue - } else { - account?.name = nil - } - } - - @IBAction func active(_ sender: NSButtonCell) { - account?.isActive = sender.state == .on ? true : false - } - - @IBAction func credentials(_ sender: Any) { - guard let account else { - return - } + private func showCredentials() { guard let window = view.window else { return } From 2a3fa45221ae8c6f03c8007c90e97295b68b5b63 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Thu, 19 Mar 2026 12:16:35 -0700 Subject: [PATCH 15/16] Add toggle for new iCloud setting for syncing unread content. Use enum for sections in view controller. --- .../AccountInspectorViewController.swift | 90 ++++++++++++++----- iOS/Inspector/Inspector.storyboard | 31 +++++++ 2 files changed, 97 insertions(+), 24 deletions(-) diff --git a/iOS/Inspector/AccountInspectorViewController.swift b/iOS/Inspector/AccountInspectorViewController.swift index 8ac64b9f2..bae61cf62 100644 --- a/iOS/Inspector/AccountInspectorViewController.swift +++ b/iOS/Inspector/AccountInspectorViewController.swift @@ -17,6 +17,7 @@ final class AccountInspectorViewController: UITableViewController { @IBOutlet var nameTextField: UITextField! @IBOutlet var activeSwitch: UISwitch! @IBOutlet var deleteAccountButton: VibrantButton! + @IBOutlet var syncContentSwitch: UISwitch! @IBOutlet var limitationsAndSolutionsButton: UIButton! var isModal = false @@ -31,6 +32,7 @@ final class AccountInspectorViewController: UITableViewController { nameTextField.text = account.name nameTextField.delegate = self activeSwitch.isOn = account.isActive + syncContentSwitch.isOn = UserDefaults.standard.bool(forKey: Account.iCloudSyncArticleContentForUnreadArticlesKey) navigationItem.title = account.nameForDisplay @@ -54,6 +56,9 @@ final class AccountInspectorViewController: UITableViewController { override func viewWillDisappear(_ animated: Bool) { account?.name = nameTextField.text account?.isActive = activeSwitch.isOn + if account?.type == .cloudKit { + UserDefaults.standard.set(syncContentSwitch.isOn, forKey: Account.iCloudSyncArticleContentForUnreadArticlesKey) + } } @objc func done() { @@ -131,12 +136,24 @@ final class AccountInspectorViewController: UITableViewController { } } -// MARK: Table View +// MARK: - Table View extension AccountInspectorViewController { + /// Sections as laid out in the storyboard. + enum StoryboardSection: Int { + case nameAndActive = 0 + case credentials = 1 + case deleteAccount = 2 + case syncContent = 3 + } + + var isCloudKitAccount: Bool { + account?.type == .cloudKit + } + var hidesCredentialsSection: Bool { - guard let account = account else { + guard let account else { return true } switch account.type { @@ -147,44 +164,69 @@ extension AccountInspectorViewController { } } - override func numberOfSections(in tableView: UITableView) -> Int { - guard let account = account else { return 0 } - - if account == AccountManager.shared.defaultAccount { - return 1 - } else if hidesCredentialsSection { - return 2 - } else { - return super.numberOfSections(in: tableView) + /// The storyboard sections to display, in order, for the current account type. + /// + /// - Default account: name/active only + /// - cloudKit: name/active, sync content, delete + /// - Other hidden-credentials: name/active, delete + /// - All others: name/active, credentials, delete + var displayedSections: [StoryboardSection] { + guard let account else { + return [] } + if account == AccountManager.shared.defaultAccount { + return [.nameAndActive] + } + if isCloudKitAccount { + return [.nameAndActive, .syncContent, .deleteAccount] + } + if hidesCredentialsSection { + return [.nameAndActive, .deleteAccount] + } + return [.nameAndActive, .credentials, .deleteAccount] + } + + override func numberOfSections(in tableView: UITableView) -> Int { + displayedSections.count + } + + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + let storyboardIndex = displayedSections[section].rawValue + return super.tableView(tableView, numberOfRowsInSection: storyboardIndex) } override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { - return section == 0 ? ImageHeaderView.rowHeight : super.tableView(tableView, heightForHeaderInSection: section) + if displayedSections[section] == .nameAndActive { + return ImageHeaderView.rowHeight + } + let storyboardIndex = displayedSections[section].rawValue + return super.tableView(tableView, heightForHeaderInSection: storyboardIndex) } override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { - guard let account = account else { return nil } - - if section == 0 { + guard let account else { + return nil + } + if displayedSections[section] == .nameAndActive { let headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "SectionHeader") as! ImageHeaderView headerView.imageView.image = Assets.accountImage(account.type) return headerView - } else { - return super.tableView(tableView, viewForHeaderInSection: section) } + let storyboardIndex = displayedSections[section].rawValue + return super.tableView(tableView, viewForHeaderInSection: storyboardIndex) } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: UITableViewCell + let storyboardIndex = displayedSections[indexPath.section].rawValue + return super.tableView(tableView, cellForRowAt: IndexPath(row: indexPath.row, section: storyboardIndex)) + } - if indexPath.section == 1, hidesCredentialsSection { - cell = super.tableView(tableView, cellForRowAt: IndexPath(row: 0, section: 2)) - } else { - cell = super.tableView(tableView, cellForRowAt: indexPath) + override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? { + if displayedSections[section] == .syncContent { + return "Syncing article content increases iCloud storage use, sync time, and battery use.\n\nArticle status and the content of starred articles are always synced." } - - return cell + let storyboardIndex = displayedSections[section].rawValue + return super.tableView(tableView, titleForFooterInSection: storyboardIndex) } override func tableView(_ tableView: UITableView, shouldHighlightRowAt indexPath: IndexPath) -> Bool { diff --git a/iOS/Inspector/Inspector.storyboard b/iOS/Inspector/Inspector.storyboard index c22eeda00..95cffca4a 100644 --- a/iOS/Inspector/Inspector.storyboard +++ b/iOS/Inspector/Inspector.storyboard @@ -163,6 +163,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + @@ -175,6 +205,7 @@ + From 3a53ebefd1ccbf18b9d39b738867ae5a0b6d4c9e Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Thu, 19 Mar 2026 12:26:21 -0700 Subject: [PATCH 16/16] Update user defaults immediately on toggle switch for iCloud sync content setting. --- .../AccountInspectorViewController.swift | 7 ++++--- iOS/Inspector/Inspector.storyboard | 15 +++++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/iOS/Inspector/AccountInspectorViewController.swift b/iOS/Inspector/AccountInspectorViewController.swift index bae61cf62..57639c02a 100644 --- a/iOS/Inspector/AccountInspectorViewController.swift +++ b/iOS/Inspector/AccountInspectorViewController.swift @@ -56,9 +56,10 @@ final class AccountInspectorViewController: UITableViewController { override func viewWillDisappear(_ animated: Bool) { account?.name = nameTextField.text account?.isActive = activeSwitch.isOn - if account?.type == .cloudKit { - UserDefaults.standard.set(syncContentSwitch.isOn, forKey: Account.iCloudSyncArticleContentForUnreadArticlesKey) - } + } + + @IBAction func syncContentSwitchDidChange(_ sender: UISwitch) { + UserDefaults.standard.set(sender.isOn, forKey: Account.iCloudSyncArticleContentForUnreadArticlesKey) } @objc func done() { diff --git a/iOS/Inspector/Inspector.storyboard b/iOS/Inspector/Inspector.storyboard index 95cffca4a..e88729b20 100644 --- a/iOS/Inspector/Inspector.storyboard +++ b/iOS/Inspector/Inspector.storyboard @@ -1,8 +1,8 @@ - + - + @@ -16,7 +16,7 @@ - +