feat(settings): how many changes wait to sync

The Sync card in Settings says how many changes made on this device
haven't reached the server yet: "3 changes wait to sync", in place of
"Everything synced" until a sync takes them, and beside a failure.

The sync engine can't tell, since the server only says what it has at
the start of each sync, so the app counts: every save asks for a sync,
and a sync that goes through takes the saves made before it started.
The count is kept in the person's folder, so it outlives the app.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MMm7usAo6q9ZZRoPkWjoxi
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
Tizian 「ティツィアーン」 2026-10-10 05:29:43 +02:00
commit ab4542f143
Signed by: raisondetredev
GPG key ID: 07F6FCF405488B64
2 changed files with 318 additions and 19 deletions

View file

@ -0,0 +1,16 @@
import 'package:halkyon_learn_flutter/src/core/sync/pending_changes_store.dart';
/// Keeps the count of changes not on the server yet in memory.
class MemoryPendingChangesStore([int initial = 0])
implements PendingChangesStore {
var _count = initial;
/// The count kept now.
int get kept => _count;
@override
Future<int> read() async => _count;
@override
Future<void> write(int count) async => _count = count;
}

View file

@ -12,6 +12,7 @@ import 'package:halkyon_learn_flutter/src/core/device_settings/data/device_setti
import 'package:halkyon_learn_flutter/src/core/device_settings/model/device_settings.dart';
import 'package:halkyon_learn_flutter/src/core/files/file_picker.dart';
import 'package:halkyon_learn_flutter/src/core/files/file_saver.dart';
import 'package:halkyon_learn_flutter/src/core/sync/pending_changes_store.dart';
import 'package:halkyon_learn_flutter/src/core/sync/sync_service.dart';
import 'package:halkyon_learn_flutter/src/core/version/app_version.dart';
import 'package:halkyon_learn_flutter/src/core/video/youtube_videos.dart';
@ -143,6 +144,7 @@ Dependencies testDependencies({
FeedbackWriteGateway? feedbackWriteGateway,
FeedbackServerGateway? feedbackServerGateway,
SyncOnce? syncOnce,
PendingChangesStore? pendingChanges,
OpenPerson? openPerson,
}) => Dependencies(
serverName: 'learn.example.org',
@ -168,7 +170,10 @@ Dependencies testDependencies({
openPerson:
openPerson ??
(person) async {
final sync = SyncService(syncOnce ?? ({required onMerge}) async {});
final sync = SyncService(
syncOnce ?? ({required onMerge}) async {},
pendingChanges: pendingChanges,
);
if (syncOnce != null) {
sync.syncNow();
}