fix: preserve queued settings and recover interrupted or corrupt state

This commit is contained in:
Codex
2026-10-13 09:32:50 +08:00
parent 5ceab20b67
commit da5b8076a0
16 changed files with 373 additions and 50 deletions
+14
View File
@@ -46,4 +46,18 @@ class FileSnapshotStore extends SnapshotStore {
await temporary.rename(_file.path);
return previous;
}
@override
Future<AppSnapshot> startFresh() async {
await directory.create(recursive: true);
final stamp = DateTime.now().toUtc().microsecondsSinceEpoch;
for (final file in [_file, _backup]) {
if (await file.exists()) {
await file.rename('${file.path}.damaged-$stamp');
}
}
final fresh = AppSnapshot();
await save(fresh);
return fresh;
}
}
+1
View File
@@ -4,4 +4,5 @@ abstract class SnapshotStore {
Future<AppSnapshot?> load();
Future<void> save(AppSnapshot snapshot);
Future<AppSnapshot> restoreBackup() => Future.error(StateError('没有可恢复的备份'));
Future<AppSnapshot> startFresh() => Future.error(StateError('无法重新建立保存文件'));
}