Files
NetNewsWire/Shared/Settings/AddCloudKitAccount.swift

66 lines
1.8 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//
// AddCloudKitAccount.swift
// NetNewsWire
//
// Created by Brent Simmons on 9/22/25.
// Copyright © 2025 Ranchero Software. All rights reserved.
//
import Foundation
#if canImport(AppKit)
import AppKit
#endif
#if canImport(UIKit)
import UIKit
#endif
enum AddCloudKitAccountError: LocalizedError, RecoverableError, Sendable {
case iCloudUnavailable
var errorDescription: String? {
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 sign in to iCloud and turn on iCloud for NetNewsWire.", comment: "CloudKit account setup recovery suggestion")
#else
NSLocalizedString("Open Settings to sign in to iCloud and turn on iCloud for NetNewsWire.", comment: "CloudKit account setup recovery suggestion")
#endif
}
var recoveryOptions: [String] {
#if os(macOS)
[NSLocalizedString("Open System Settings", comment: "Open System Settings button"), NSLocalizedString("Cancel", comment: "Cancel button")]
#else
[NSLocalizedString("Open Settings", comment: "Open Settings button"), NSLocalizedString("Cancel", comment: "Cancel button")]
#endif
}
func attemptRecovery(optionIndex recoveryOptionIndex: Int) -> Bool {
guard recoveryOptionIndex == 0 else {
return false
}
Task { @MainActor in
AddCloudKitAccountUtilities.openiCloudSettings()
}
return true
}
}
struct AddCloudKitAccountUtilities {
@MainActor static func openiCloudSettings() {
#if os(macOS)
if let url = URL(string: "x-apple.systempreferences:com.apple.preferences.AppleIDPrefPane") {
NSWorkspace.shared.open(url)
}
#else
if let url = URL(string: "App-prefs:APPLE_ACCOUNT") {
UIApplication.shared.open(url)
}
#endif
}
}