import SwiftUI import IndieBackup /// App version, and backup/restore (indie-backup skill). struct SettingsTabView: View { @Environment(BoardIndexStore.self) private var index @Environment(\.backupController) private var backupController var body: some View { NavigationStack { Form { Section { LabeledContent("Version") { Text(Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "—") } } backupSection } .navigationTitle("Settings") } // Idempotent (BoardIndexStore.start()), and harmless if BoardsTabView already called it — // this tab can be the first one the user opens, and `backupController` only ever appears // once `index.home` resolves. .task { index.start() } } /// `backupController` is `nil` until `MobileApp` has a resolved `CloudHome` to build one from /// — which is also exactly the condition under which there is a `Documents/` folder to back /// up. Everything short of that gets the same quiet explanation rather than a section that /// looks broken or, worse, a crash on a nil root. @ViewBuilder private var backupSection: some View { if let backupController { BackupsSectionView(controller: backupController) } else { Section { switch index.phase { case .idle, .loading: LabeledContent("Backup") { ProgressView() } case .unavailable, .ready: // `.ready` can appear briefly here too: `backupController` lags one runloop // turn behind `index.home` resolving (MobileApp's `.task(id:)`). Label("Backup and restore need iCloud Drive.", systemImage: "icloud.slash") .foregroundStyle(.secondary) } } footer: { Text("Sign into iCloud in Settings, then come back here to back up your boards.") } } } }