Fix initial sync not starting on first run

This commit is contained in:
Ming Ming 2024-05-11 19:16:06 +08:00
parent 9e3ec0bfc3
commit bc3c480223
2 changed files with 12 additions and 11 deletions

View file

@ -551,9 +551,7 @@ class FilesController {
excludeRelativeRoots: [remote_storage_util.remoteStorageDirRelativePath],
mimes: file_util.supportedFormatMimes,
);
_summaryStreamController.addWithValue((value) => value.copyWith(
summary: results,
));
_summaryStreamController.add(FilesSummaryStreamEvent(summary: results));
}
_MockResult _mockRemove({
@ -645,11 +643,7 @@ class FilesController {
);
var _isSummaryStreamInited = false;
final _summaryStreamController = BehaviorSubject.seeded(
const FilesSummaryStreamEvent(
summary: DbFilesSummary(items: {}),
),
);
final _summaryStreamController = BehaviorSubject<FilesSummaryStreamEvent>();
final _timelineStreamController = BehaviorSubject.seeded(
const TimelineStreamEvent(data: {}, isDummy: true),

View file

@ -130,9 +130,16 @@ class _Bloc extends Bloc<_Event, _State> with BlocLogger {
await Future.wait([
emit.forEach<FilesSummaryStreamEvent>(
filesController.summaryStream,
onData: (data) => state.copyWith(
onData: (data) {
if (data.summary.items.isEmpty && _isInitialLoad) {
// no data, initial sync
_isInitialLoad = false;
_syncRemote();
}
return state.copyWith(
filesSummary: data.summary,
),
);
},
onError: (e, stackTrace) {
_log.severe("[_onLoad] Uncaught exception", e, stackTrace);
return state.copyWith(