Reconcile starter seeds on connect and add restore + duplicate cleanup

Seeding now covers existing installs, not just empty containers: after the
same settle delay as auto-seed, connect() branches to reconcileSeeds(),
driven by a pure tested planner — upgrade an older seed revision in place
(safe: clone-on-edit guarantees no user content at seed ULIDs), skip
up-to-date/quarantined files, respect delete-veto stubs, and write missing
seeds unless a same-name legacy split exists. Settings gains Restore
Starter Splits (the one deliberate veto lift, writing current bundle
bytes) and a dev duplicate-cleanup tool backed by a fail-closed scanner.
The HealthKit estimate now follows the clone redirect when resolving a
workout's split.

Claude-Session: https://claude.ai/code/session_01LEoff8bXGBS83tK1c55Mf7
This commit is contained in:
2026-07-06 16:29:59 -04:00
parent 2c1e4759ae
commit 7586edd878
10 changed files with 1344 additions and 152 deletions
+56 -62
View File
@@ -6,20 +6,18 @@
//
import SwiftUI
import SwiftData
import IndieAbout
struct SettingsView: View {
@Environment(SyncEngine.self) private var sync
@Environment(\.modelContext) private var modelContext
@Environment(AppServices.self) private var services
@Query(sort: \Split.order) private var splits: [Split]
@AppStorage("restSeconds") private var restSeconds: Int = 45
@AppStorage("doneCountdownSeconds") private var doneCountdownSeconds: Int = 5
@AppStorage("weightUnit") private var weightUnit: WeightUnit = .lb
@State private var showingAddSplitSheet = false
@State private var isRestoringSeeds = false
@State private var restoreSeedsMessage: String?
var body: some View {
NavigationStack {
@@ -53,62 +51,50 @@ struct SettingsView: View {
Text("How long the watch waits on the finish screen before completing an exercise automatically.")
}
// MARK: - Splits Section
Section(header: Text("Splits")) {
if splits.isEmpty {
HStack {
Spacer()
VStack(spacing: 8) {
Image(systemName: "dumbbell.fill")
.font(.largeTitle)
.foregroundColor(.secondary)
Text("No Splits Yet")
.font(.headline)
.foregroundColor(.secondary)
Text("Create a split to organize your workout routine.")
.font(.caption)
.foregroundColor(.secondary)
.multilineTextAlignment(.center)
}
.padding(.vertical)
Spacer()
// MARK: - Library Section
Section(header: Text("Library")) {
NavigationLink {
SplitListView()
} label: {
Label("Splits", systemImage: "dumbbell.fill")
}
NavigationLink {
ExerciseLibraryView()
} label: {
Label("Exercises", systemImage: "figure.strengthtraining.traditional")
}
}
// MARK: - Starter Splits Section
Section {
Button {
Task {
isRestoringSeeds = true
restoreSeedsMessage = nil
let n = await sync.restoreSeeds()
isRestoringSeeds = false
restoreSeedsMessage = n == 0
? "All starter splits are already present."
: "Restored \(n) starter split\(n == 1 ? "" : "s")."
}
} label: {
HStack {
Label("Restore Starter Splits", systemImage: "arrow.counterclockwise")
if isRestoringSeeds {
Spacer()
ProgressView()
}
}
}
.disabled(isRestoringSeeds || sync.iCloudStatus != .available)
} header: {
Text("Starter Splits")
} footer: {
if let restoreSeedsMessage {
Text(restoreSeedsMessage)
} else {
ForEach(splits) { split in
NavigationLink {
SplitDetailView(split: split)
} label: {
HStack {
Image(systemName: split.systemImage)
.foregroundColor(Color.color(from: split.color))
.frame(width: 24)
Text(split.name)
Spacer()
Text("\(split.exercisesArray.count)")
.foregroundColor(.secondary)
}
}
}
}
Button {
showingAddSplitSheet = true
} label: {
HStack {
Image(systemName: "plus.circle.fill")
.foregroundColor(.accentColor)
Text("Add Split")
}
}
Button {
Task { await SplitSeeder.seedDefaults(into: modelContext, using: sync) }
} label: {
HStack {
Image(systemName: "wand.and.sparkles")
.foregroundColor(.accentColor)
Text("Add Starter Splits")
}
Text("Brings back the bundled starter splits you've deleted. Splits you've edited or created are never touched.")
}
}
@@ -133,6 +119,17 @@ struct SettingsView: View {
Text("iCloud Sync")
}
// MARK: - Developer Section
Section {
NavigationLink {
DuplicateCleanupView()
} label: {
Label("Clean Up Duplicates", systemImage: "wrench.and.screwdriver")
}
} header: {
Text("Developer")
}
// MARK: - About Section
Section {
IndieAbout(configuration: AppInfoConfiguration(
@@ -144,9 +141,6 @@ struct SettingsView: View {
}
}
.navigationTitle("Settings")
.sheet(isPresented: $showingAddSplitSheet) {
SplitAddEditView(split: nil)
}
.onChange(of: restSeconds) { _, _ in services.watchBridge.pushAll() }
.onChange(of: doneCountdownSeconds) { _, _ in services.watchBridge.pushAll() }
.onChange(of: weightUnit) { _, _ in services.watchBridge.pushAll() }