From 79b9108a8ff387ff005b1bb2cac3292cca9e8e20 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 31 Dec 2022 11:24:42 -0500 Subject: [PATCH] Add CloudKit status indicator to advanced prefs --- .../Preferences/AdvancedPrefsView.swift | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Tusker/Screens/Preferences/AdvancedPrefsView.swift b/Tusker/Screens/Preferences/AdvancedPrefsView.swift index f691a658..32ee8d7f 100644 --- a/Tusker/Screens/Preferences/AdvancedPrefsView.swift +++ b/Tusker/Screens/Preferences/AdvancedPrefsView.swift @@ -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)