Skip showing the iCloud account icon when the user already has an iCloud account. This way there’s no need to present an error. Fix #4319.

This commit is contained in:
Brent Simmons committed 2025-09-16 14:01:05 -07:00
1 parent 718204e4d8
commit 1c854b2606
1 file changed
+10 -17
@@ -14,19 +14,21 @@ struct AddAccountHelpView: View {
let accountTypes: [AccountType] = AddAccountSections.allOrdered.sectionContent
var delegate: AccountsPreferencesAddAccountDelegate?
var helpText: String
@State private var iCloudUnavailableError: Bool = false
var hasiCloudAccount: Bool {
AccountManager.shared.accounts.contains(where: { $0.type == .cloudKit })
}
var body: some View {
VStack {
HStack {
ForEach(accountTypes, id: \.self) { accountType in
if !(AppDefaults.shared.isDeveloperBuild && accountType.isDeveloperRestricted) {
if accountType == .cloudKit && hasiCloudAccount {
EmptyView()
}
else if !(AppDefaults.shared.isDeveloperBuild && accountType.isDeveloperRestricted) {
Button(action: {
if accountType == .cloudKit && AccountManager.shared.accounts.contains(where: { $0.type == .cloudKit }) {
iCloudUnavailableError = true
} else {
delegate?.presentSheetForAccount(accountType)
}
delegate?.presentSheetForAccount(accountType)
}, label: {
accountType.image()
.resizable()
@@ -40,15 +42,6 @@ struct AddAccountHelpView: View {
Text(helpText)
.multilineTextAlignment(.center)
.padding(.top, 8)
}
.alert(isPresented: $iCloudUnavailableError, content: {
Alert(title: Text(NSLocalizedString("Error", comment: "Error")),
message: Text(NSLocalizedString("You've already set up an iCloud account.", comment: "Error")),
dismissButton: Alert.Button.cancel({
iCloudUnavailableError = false
}))
})
}
}