Reflect watch-forwarded workout progress on the phone immediately
ingestFromWatch now upserts the SwiftData cache directly after writing the file, instead of relying on the NSMetadataQuery observer — a same-process file overwrite doesn't reliably emit a modified event, so watch progress never reached open iPhone screens. iCloud Drive stays the source of truth (file written first); the observer re-applies idempotently if it fires. Claude-Session: https://claude.ai/code/session_018gg69MaUetDNzWzBXisfMV
This commit is contained in:
@@ -112,10 +112,20 @@ final class SyncEngine {
|
||||
onCacheChanged?()
|
||||
}
|
||||
|
||||
/// Apply a workout received from the watch through the normal write path
|
||||
/// (file → observer → cache), keeping iCloud Drive the single source of truth.
|
||||
/// Apply a workout received from the watch. iCloud Drive stays the source of
|
||||
/// truth (we write the file), but we also upsert the cache directly here.
|
||||
///
|
||||
/// The phone's own edits drive a local view copy, so they don't need this — but a
|
||||
/// watch-originated change has nothing else refreshing the phone UI, and a
|
||||
/// same-process file overwrite doesn't reliably wake the `NSMetadataQuery`
|
||||
/// observer. Upserting the doc we just wrote keeps cache and file consistent (the
|
||||
/// observer re-applies idempotently if it does fire) and lets open phone screens
|
||||
/// reflect watch progress live.
|
||||
func ingestFromWatch(_ doc: WorkoutDocument) async {
|
||||
await save(workout: doc)
|
||||
CacheMapper.upsertWorkout(doc, relativePath: doc.relativePath, into: context)
|
||||
try? context.save()
|
||||
onCacheChanged?()
|
||||
}
|
||||
|
||||
// MARK: - Public CRUD (write path: files only)
|
||||
|
||||
Reference in New Issue
Block a user