An open-source cross-platform alternative to AirDrop
fix: possible race condition leading to zero files (#659)
Tien Do Nam061630ffd0e1
diff --git a/assets/CHANGELOG.md b/assets/CHANGELOG.mdindex 85b5f48b..61fb1b1a 100644--- a/assets/CHANGELOG.md+++ b/assets/CHANGELOG.md@@ -2,6 +2,7 @@- feat: hide color setting when dynamic colors are not supported (@Tienisto)- feat(linux): use white icon for the linux tray (@GaryElshaw, @Tienisto)+- fix: possible race condition leading to zero total files (@Tienisto)- fix(android): navigation bar color on Android 9 and earlier (@Tienisto)- fix(android): add `requestLegacyExternalStorage` again (that was removed in 1.11.0) (@Tienisto)- fix(linux): do not use zenity dependency anymore for file picker (@Tienisto)diff --git a/lib/pages/progress_page.dart b/lib/pages/progress_page.dartindex 1ba025d0..c3765d27 100644--- a/lib/pages/progress_page.dart+++ b/lib/pages/progress_page.dart@@ -45,7 +45,7 @@ class _ProgressPageState extends State<ProgressPage> with Riverpie {int _lastRemainingTimeUpdate = 0; // millis since epochString? _remainingTime;List<FileDto> _files = []; // also contains declined files (files without token)- Set<String> _filesWithToken = {};+ Set<String> _selectedFiles = {};bool _advanced = false;@@ -56,23 +56,25 @@ class _ProgressPageState extends State<ProgressPage> with Riverpie {// initWidgetsBinding.instance.addPostFrameCallback((_) {try {- unawaited(WakelockPlus.enable());+ WakelockPlus.enable(); // ignore: discarded_futures} catch (_) {}setState(() {final receiveSession = ref.read(serverProvider)?.session;if (receiveSession != null) {_files = receiveSession.files.values.map((f) => f.file).toList();- _filesWithToken = receiveSession.files.values.where((f) => f.token != null).map((f) => f.file.id).toSet();++ // We previously used f.token != null here, but this may not work on very fast networks.+ _selectedFiles = receiveSession.files.values.where((f) => f.status != FileStatus.skipped).map((f) => f.file.id).toSet();} else {final sendSession = ref.read(sendProvider)[widget.sessionId];if (sendSession != null) {_files = sendSession.files.values.map((f) => f.file).toList();- _filesWithToken = sendSession.files.values.where((f) => f.token != null).map((f) => f.file.id).toSet();+ _selectedFiles = sendSession.files.values.where((f) => f.status != FileStatus.skipped).map((f) => f.file.id).toSet();}}- _totalBytes = _files.where((f) => _filesWithToken.contains(f.id)).fold(0, (prev, curr) => prev + curr.size);+ _totalBytes = _files.where((f) => _selectedFiles.contains(f.id)).fold(0, (prev, curr) => prev + curr.size);});});}@@ -361,7 +363,7 @@ class _ProgressPageState extends State<ProgressPage> with Riverpie {children: [Text(t.progressPage.total.count(curr: progressNotifier.getFinishedCount(widget.sessionId),- n: _filesWithToken.length,+ n: _selectedFiles.length,)),Text(t.progressPage.total.size(curr: currBytes.asReadableFileSize,