Merge branch 'bug/icloud-drive-not-required'

This commit is contained in:
Brent Simmons committed 2026-11-27 22:02:39 -08:00
commit bcc25bb769
11 files changed
+81 -46

No files matched your search

+2 -2
View File
@@ -845,13 +845,13 @@ extension AppDelegate {
accountStatsWindowController?.showWindow(self)
}
@IBAction func showiCloudDriveMissingAlert(_ sender: Any?) {
@IBAction func showiCloudUnavailableAlert(_ sender: Any?) {
// Manual testing for alert in AccountsAddCloudKitWindowController
// Check for:
// - Expected text
// - Button for opening Settings
// - Button works
mainWindowController?.presentError(AddCloudKitAccountError.iCloudDriveMissing)
mainWindowController?.presentError(AddCloudKitAccountError.iCloudUnavailable)
}
}
+2 -2
View File
@@ -591,10 +591,10 @@
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="dgO-u4-aEs"/>
<menuItem title="Show iCloud Drive Missing Alert" id="m0T-w3-neT">
<menuItem title="Show iCloud Unavailable Alert" id="m0T-w3-neT">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="showiCloudDriveMissingAlert:" target="-1" id="kfQ-dM-8vB"/>
<action selector="showiCloudUnavailableAlert:" target="-1" id="kfQ-dM-8vB"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="AQO-MD-QVj"/>
+3 -3
View File
@@ -1298,19 +1298,19 @@
}
},
"m0T-w3-neT.title" : {
"comment" : "Class = \"NSMenuItem\"; title = \"Show iCloud Drive Missing Alert\"; ObjectID = \"m0T-w3-neT\";",
"comment" : "Class = \"NSMenuItem\"; title = \"Show iCloud Unavailable Alert\"; ObjectID = \"m0T-w3-neT\";",
"extractionState" : "extracted_with_value",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "new",
"value" : "Show iCloud Drive Missing Alert"
"value" : "Show iCloud Unavailable Alert"
}
},
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "Mostrar alerta de iCloud Drive no disponible"
"value" : "Mostrar alerta de iCloud no disponible"
}
}
}
@@ -11,6 +11,7 @@ import Account
final class AccountsAddCloudKitWindowController: NSWindowController {
private weak var hostWindow: NSWindow?
private var isCheckingiCloud = false
convenience init() {
self.init(windowNibName: "AccountsAddCloudKit")
@@ -40,19 +41,29 @@ final class AccountsAddCloudKitWindowController: NSWindowController {
}
@IBAction func create(_ sender: Any) {
guard !isCheckingiCloud else {
return
}
assert(!AccountManager.shared.hasiCloudAccount)
guard AddCloudKitAccountUtilities.isiCloudDriveEnabled else {
presentError(AddCloudKitAccountError.iCloudDriveMissing)
return
}
isCheckingiCloud = true
Task {
defer {
isCheckingiCloud = false
}
assert(hostWindow != nil && window != nil)
guard let hostWindow, let window else {
return
}
guard await AccountManager.shared.isiCloudAvailable() else {
presentError(AddCloudKitAccountError.iCloudUnavailable)
return
}
_ = AccountManager.shared.createAccount(type: .cloudKit)
hostWindow.endSheet(window, returnCode: NSApplication.ModalResponse.OK)
assert(hostWindow != nil && window != nil)
guard let hostWindow, let window else {
return
}
_ = AccountManager.shared.createAccount(type: .cloudKit)
hostWindow.endSheet(window, returnCode: NSApplication.ModalResponse.OK)
}
}
}
@@ -187,6 +187,10 @@ import ActivityLog
// MARK: - API
public func isiCloudAvailable() async -> Bool {
await CloudKitAccountDelegate.isiCloudAvailable()
}
public func createAccount(type: AccountType) -> Account {
if type == .cloudKit {
if let existingiCloudAccount = iCloudAccount {
@@ -39,10 +39,7 @@ enum CloudKitAccountDelegateError: LocalizedError, Sendable {
private let syncDatabase: SyncDatabase
private let container: CKContainer = {
let orgID = Bundle.main.object(forInfoDictionaryKey: "OrganizationIdentifier") as! String
return CKContainer(identifier: "iCloud.\(orgID).NetNewsWire")
}()
private let container = CloudKitAccountDelegate.makeContainer()
private let accountZone: CloudKitAccountZone
private let articlesZone: CloudKitArticlesZone
@@ -113,6 +110,25 @@ enum CloudKitAccountDelegateError: LocalizedError, Sendable {
Self.logger.debug("CloudKitAccountDelegate: \(#function, privacy: .public) did complete")
}
nonisolated static func makeContainer() -> CKContainer {
let orgID = Bundle.main.object(forInfoDictionaryKey: "OrganizationIdentifier") as! String
return CKContainer(identifier: "iCloud.\(orgID).NetNewsWire")
}
/// False when there’s no iCloud account, the account is restricted, or iCloud is turned off for this app.
/// True when the status check itself fails, since sync reports its own errors.
nonisolated static func isiCloudAvailable() async -> Bool {
guard let status = try? await makeContainer().accountStatus() else {
return true
}
switch status {
case .noAccount, .restricted:
return false
default:
return true
}
}
// CKAccountChanged can arrive on any thread.
@objc nonisolated func handleCKAccountChanged(_ note: Notification) {
Task { @MainActor in
@@ -60,7 +60,7 @@ public final class CloudKitError: LocalizedError, Sendable {
case .networkFailure:
return NSLocalizedString("Network Failure: the internet connection appears to be offline.", comment: "Known iCloud Error")
case .notAuthenticated:
return NSLocalizedString("Not Authenticated: to use the iCloud account, you must enable iCloud Drive. Go to device Settings, sign in to iCloud, then in the app settings, be sure the iCloud Drive feature is enabled.", comment: "Known iCloud Error")
return NSLocalizedString("Not Authenticated: to use the iCloud account, sign in to iCloud in Settings and make sure iCloud is turned on for NetNewsWire.", comment: "Known iCloud Error")
case .operationCancelled:
return NSLocalizedString("Operation Cancelled: the operation was explicitly canceled.", comment: "Known iCloud Error")
case .partialFailure:
@@ -68,7 +68,7 @@ public final class CloudKitError: LocalizedError, Sendable {
case .participantMayNeedVerification:
return NSLocalizedString("Participant May Need Verification: you are not a member of the share.", comment: "Known iCloud Error")
case .permissionFailure:
return NSLocalizedString("Permission Failure: to use this app, you must enable iCloud Drive. Go to device Settings, sign in to iCloud, then in the app settings, be sure the iCloud Drive feature is enabled.", comment: "Known iCloud Error")
return NSLocalizedString("Permission Failure: to use the iCloud account, sign in to iCloud in Settings and make sure iCloud is turned on for NetNewsWire.", comment: "Known iCloud Error")
case .quotaExceeded:
return NSLocalizedString("Quota Exceeded: saving would exceed your current iCloud storage quota.", comment: "Known iCloud Error")
case .referenceViolation:
@@ -26,7 +26,7 @@ public enum CloudKitZoneError: LocalizedError, Sendable {
case .userDeletedZone:
return NSLocalizedString("The iCloud data was deleted. Please remove the application iCloud account and add it again to continue using the application's iCloud support.", comment: "User deleted zone.")
case .corruptAccount:
return NSLocalizedString("There is an unrecoverable problem with your application iCloud account. Please make sure you have iCloud and iCloud Drive enabled in System Preferences. Then remove the application iCloud account and add it again.", comment: "Corrupt account.")
return NSLocalizedString("There is an unrecoverable problem with your application iCloud account. Please make sure you’re signed in to iCloud and iCloud is turned on for NetNewsWire in Settings. Then remove the application iCloud account and add it again.", comment: "Corrupt account.")
default:
return NSLocalizedString("An unexpected CloudKit error occurred.", comment: "An unexpected CloudKit error occurred.")
}
+3 -3
View File
@@ -283,7 +283,7 @@
"comment" : "Feed finder"
},
"Can’t Add iCloud Account" : {
"comment" : "CloudKit account setup failure description — iCloud Drive not enabled."
"comment" : "CloudKit account setup failure description — iCloud not available."
},
"Can’t add this feed because of a download error: “%@”" : {
"comment" : "Feed finder"
@@ -1105,7 +1105,7 @@
"Open Settings" : {
"comment" : "Open Settings button"
},
"Open Settings to configure iCloud and enable iCloud Drive." : {
"Open Settings to sign in to iCloud and turn on iCloud for NetNewsWire." : {
"comment" : "CloudKit account setup recovery suggestion"
},
"Open System Preferences" : {
@@ -1114,7 +1114,7 @@
"Open System Settings" : {
"comment" : "Open System Settings button"
},
"Open System Settings to configure iCloud and enable iCloud Drive." : {
"Open System Settings to sign in to iCloud and turn on iCloud for NetNewsWire." : {
"comment" : "CloudKit account setup recovery suggestion"
},
"Open Theme Folder" : {
+4 -9
View File
@@ -13,20 +13,19 @@ import AppKit
#if canImport(UIKit)
import UIKit
#endif
import RSCore
enum AddCloudKitAccountError: LocalizedError, RecoverableError, Sendable {
case iCloudDriveMissing
case iCloudUnavailable
var errorDescription: String? {
NSLocalizedString("Can’t Add iCloud Account", comment: "CloudKit account setup failure description — iCloud Drive not enabled.")
NSLocalizedString("Can’t Add iCloud Account", comment: "CloudKit account setup failure description — iCloud not available.")
}
var recoverySuggestion: String? {
#if os(macOS)
NSLocalizedString("Open System Settings to configure iCloud and enable iCloud Drive.", comment: "CloudKit account setup recovery suggestion")
NSLocalizedString("Open System Settings to sign in to iCloud and turn on iCloud for NetNewsWire.", comment: "CloudKit account setup recovery suggestion")
#else
NSLocalizedString("Open Settings to configure iCloud and enable iCloud Drive.", comment: "CloudKit account setup recovery suggestion")
NSLocalizedString("Open Settings to sign in to iCloud and turn on iCloud for NetNewsWire.", comment: "CloudKit account setup recovery suggestion")
#endif
}
@@ -52,10 +51,6 @@ enum AddCloudKitAccountError: LocalizedError, RecoverableError, Sendable {
}
struct AddCloudKitAccountUtilities {
static var isiCloudDriveEnabled: Bool {
Platform.deviceHasiCloudAccount
}
@MainActor static func openiCloudSettings() {
#if os(macOS)
if let url = URL(string: "x-apple.systempreferences:com.apple.preferences.AppleIDPrefPane") {
+19 -10
View File
@@ -15,16 +15,20 @@ struct CloudKitAccountView: View {
let didAddAccount: () -> Void
@Environment(\.dismiss) private var dismiss
@State private var iCloudDriveError: AddCloudKitAccountError?
@State private var iCloudError: AddCloudKitAccountError?
@State private var isCheckingiCloud = false
@State private var isShowingHelp = false
var body: some View {
AccountSetupSheet(accountType: .cloudKit) {
Section {
Button(NSLocalizedString("Use iCloud", comment: "Use iCloud button")) {
addAccount()
Task {
await addAccount()
}
}
.frame(maxWidth: .infinity)
.disabled(isCheckingiCloud)
} header: {
AccountIconHeader(accountType: .cloudKit)
} footer: {
@@ -33,12 +37,12 @@ struct CloudKitAccountView: View {
}
}
}
.alert(isPresented: isShowingiCloudDriveError, error: iCloudDriveError) { _ in
.alert(isPresented: isShowingiCloudError, error: iCloudError) { _ in
Button(NSLocalizedString("Open Settings", comment: "Open Settings button")) {
AddCloudKitAccountUtilities.openiCloudSettings()
}
Button(NSLocalizedString("Cancel", comment: "Cancel button"), role: .cancel) {
iCloudDriveError = nil
iCloudError = nil
}
} message: { error in
Text(verbatim: error.recoverySuggestion ?? "")
@@ -48,19 +52,24 @@ struct CloudKitAccountView: View {
}
}
private var isShowingiCloudDriveError: Binding<Bool> {
private var isShowingiCloudError: Binding<Bool> {
Binding {
iCloudDriveError != nil
iCloudError != nil
} set: { isShowing in
if !isShowing {
iCloudDriveError = nil
iCloudError = nil
}
}
}
private func addAccount() {
guard AddCloudKitAccountUtilities.isiCloudDriveEnabled else {
iCloudDriveError = .iCloudDriveMissing
private func addAccount() async {
isCheckingiCloud = true
defer {
isCheckingiCloud = false
}
guard await AccountManager.shared.isiCloudAvailable() else {
iCloudError = .iCloudUnavailable
return
}