From b8b50ec2ca97d08acac0f7d04365635196ef183e Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 22 Sep 2025 18:10:29 -0700 Subject: [PATCH] Add hasiCloudAccount computed var. In createAccount, return the existing iCloud account instead of trying to create a new account. --- .../Sources/Account/AccountManager.swift | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Modules/Account/Sources/Account/AccountManager.swift b/Modules/Account/Sources/Account/AccountManager.swift index cdda3e390..828eae170 100644 --- a/Modules/Account/Sources/Account/AccountManager.swift +++ b/Modules/Account/Sources/Account/AccountManager.swift @@ -55,6 +55,16 @@ public final class AccountManager: UnreadCountProvider { return sortByName(accounts) } + public var hasiCloudAccount: Bool { + for account in accounts { + if account.type == .cloudKit { + return true + } + } + return false + } + + public var activeAccounts: [Account] { assert(Thread.isMainThread) return Array(accountsDictionary.values.filter { $0.isActive }) @@ -121,6 +131,12 @@ public final class AccountManager: UnreadCountProvider { // MARK: - API public func createAccount(type: AccountType) -> Account { + if type == .cloudKit { + if let existingiCloudAccount = accounts.first(where: { $0.type == .cloudKit }) { + return existingiCloudAccount + } + } + let accountID = type == .cloudKit ? "iCloud" : UUID().uuidString let accountFolder = (accountsFolder as NSString).appendingPathComponent("\(type.rawValue)_\(accountID)") @@ -140,7 +156,7 @@ public final class AccountManager: UnreadCountProvider { return account } - + public func deleteAccount(_ account: Account) { guard !account.refreshInProgress else { return