mirror of
https://github.com/kuhyx/diet-guard.git
synced 2026-11-10 19:07:15 +01:00
Some checks failed
dependency freshness / dependencies on newest stable (push) Has been cancelled
file-length / file length <= 250 lines (push) Has been cancelled
md-naming / markdown naming convention (push) Has been cancelled
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Has been cancelled
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Has been cancelled
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint) (push) Has been cancelled
Tests / test (push) Has been cancelled
release-apk / release (APK) (push) Has been cancelled
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
36 lines
1.4 KiB
Dart
36 lines
1.4 KiB
Dart
/// The Body document's part of a sync tick.
|
|
///
|
|
/// Its own file because `sync_service.dart` is near the repo's 250-line cap.
|
|
/// First ingests the wake-alarm weigh-ins (never throws), then pulls peers'
|
|
/// `body.json`, merges last-writer-wins per field, applies the result locally
|
|
/// and pushes. Mirrors `diet_guard/_sync_body.py`.
|
|
library;
|
|
|
|
import 'package:crdt_sync/crdt_sync.dart';
|
|
import 'package:diet_guard_app/services/body_service.dart';
|
|
import 'package:diet_guard_app/services/sync_device_id.dart';
|
|
import 'package:diet_guard_app/services/sync_merge_body.dart';
|
|
import 'package:diet_guard_app/services/wake_alarm_weights.dart';
|
|
|
|
/// Runs the Body sync against [client], under [devicesDir].
|
|
///
|
|
/// No-ops when [BodyService] is uninitialised (a widget test, or an isolate
|
|
/// that never loaded it), so it can neither publish nor clobber anything.
|
|
Future<void> syncBody(RemoteStore client, {required String devicesDir}) async {
|
|
if (!BodyService.isInitialized) return;
|
|
await ingestWakeAlarmWeights(client);
|
|
final merged = await syncLog(
|
|
client: client,
|
|
deviceId: currentSyncDeviceId,
|
|
legacyDeviceId: legacySyncDeviceId,
|
|
pathPrefix: devicesDir,
|
|
localLog: bodyToLog(BodyService.instance.document),
|
|
encode: encodeBodyForPush,
|
|
decode: parseRemoteBody,
|
|
filename: 'body.json',
|
|
commitMessage: 'diet_guard_app sync',
|
|
);
|
|
if (merged.isEmpty) return;
|
|
await BodyService.instance.applyMerged(logToBody(merged));
|
|
}
|