Add CloudKit status indicator to advanced prefs

This commit is contained in:
Shadowfacts 2022-12-31 11:24:42 -05:00
parent 5ab22e742b
commit 79b9108a8f
1 changed files with 36 additions and 0 deletions

View File

@ -8,15 +8,18 @@
import SwiftUI
import Pachyderm
import CoreData
import CloudKit
struct AdvancedPrefsView : View {
@ObservedObject var preferences = Preferences.shared
@State private var imageCacheSize: Int64 = 0
@State private var mastodonCacheSize: Int64 = 0
@State private var cloudKitStatus: CKAccountStatus?
var body: some View {
List {
formattingSection
cloudKitSection
errorReportingSection
cachingSection
}
@ -49,6 +52,39 @@ struct AdvancedPrefsView : View {
}
}
var cloudKitSection: some View {
Section {
HStack {
Text("iCloud Status")
Spacer()
switch cloudKitStatus {
case nil:
EmptyView()
case .available:
Text("Available")
case .couldNotDetermine:
Text("Could not determine")
case .noAccount:
Text("No account")
case .restricted:
Text("Restricted")
case .temporarilyUnavailable:
Text("Temporarily Unavailable")
@unknown default:
Text(String(describing: cloudKitStatus!))
}
}
}.task {
CKContainer.default().accountStatus { status, error in
if let error {
Logging.general.error("Unable to get CloudKit status: \(String(describing: error))")
} else {
self.cloudKitStatus = status
}
}
}
}
var errorReportingSection: some View {
Section {
Toggle("Report Errors Automatically", isOn: $preferences.reportErrorsAutomatically)