Add HealthKit backfill to sync all existing moods
When user enables HealthKit integration, automatically syncs all previously recorded mood entries to Apple Health. Features: - Progress tracking with visual indicator in Settings - Batched saves with throttling to avoid overwhelming HealthKit - Success/failure logging with EventLogger 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -238,6 +238,8 @@ struct SettingsContentView: View {
|
||||
// Request write permissions for State of Mind sync
|
||||
do {
|
||||
try await HealthKitManager.shared.requestAuthorization()
|
||||
// Sync all existing moods to HealthKit
|
||||
await HealthKitManager.shared.syncAllMoods()
|
||||
} catch {
|
||||
print("HealthKit write authorization failed: \(error)")
|
||||
}
|
||||
@@ -259,6 +261,19 @@ struct SettingsContentView: View {
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
|
||||
// Show sync progress
|
||||
if HealthKitManager.shared.isSyncing {
|
||||
VStack(spacing: 8) {
|
||||
ProgressView(value: HealthKitManager.shared.syncProgress)
|
||||
.tint(.red)
|
||||
Text("Syncing moods to Health... \(HealthKitManager.shared.syncedCount)/\(HealthKitManager.shared.totalToSync)")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
.padding(.horizontal)
|
||||
.padding(.bottom, 8)
|
||||
}
|
||||
}
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
.cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
|
||||
@@ -708,6 +723,8 @@ struct SettingsView: View {
|
||||
// Request write permissions for State of Mind sync
|
||||
do {
|
||||
try await HealthKitManager.shared.requestAuthorization()
|
||||
// Sync all existing moods to HealthKit
|
||||
await HealthKitManager.shared.syncAllMoods()
|
||||
} catch {
|
||||
print("HealthKit write authorization failed: \(error)")
|
||||
}
|
||||
@@ -729,6 +746,19 @@ struct SettingsView: View {
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
|
||||
// Show sync progress
|
||||
if HealthKitManager.shared.isSyncing {
|
||||
VStack(spacing: 8) {
|
||||
ProgressView(value: HealthKitManager.shared.syncProgress)
|
||||
.tint(.red)
|
||||
Text("Syncing moods to Health... \(HealthKitManager.shared.syncedCount)/\(HealthKitManager.shared.totalToSync)")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
.padding(.horizontal)
|
||||
.padding(.bottom, 8)
|
||||
}
|
||||
}
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
.cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
|
||||
|
||||
Reference in New Issue
Block a user