From bc3c4802236e667dd593fdb42d7c45ef273ca795 Mon Sep 17 00:00:00 2001 From: Ming Ming Date: Sat, 11 May 2024 19:16:06 +0800 Subject: [PATCH] Fix initial sync not starting on first run --- app/lib/controller/files_controller.dart | 10 ++-------- app/lib/widget/home_photos/bloc.dart | 13 ++++++++++--- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/app/lib/controller/files_controller.dart b/app/lib/controller/files_controller.dart index d49c1714..ba0770ec 100644 --- a/app/lib/controller/files_controller.dart +++ b/app/lib/controller/files_controller.dart @@ -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(); final _timelineStreamController = BehaviorSubject.seeded( const TimelineStreamEvent(data: {}, isDummy: true), diff --git a/app/lib/widget/home_photos/bloc.dart b/app/lib/widget/home_photos/bloc.dart index 587ccdb7..87092f0f 100644 --- a/app/lib/widget/home_photos/bloc.dart +++ b/app/lib/widget/home_photos/bloc.dart @@ -130,9 +130,16 @@ class _Bloc extends Bloc<_Event, _State> with BlocLogger { await Future.wait([ emit.forEach( filesController.summaryStream, - onData: (data) => state.copyWith( - filesSummary: data.summary, - ), + 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(