Skip to content

An open-source cross-platform alternative to AirDrop

feat: update progress every 100ms instead of 100kb

Tien Do Namb35ecc29c039
diff --git a/lib/util/file_saver.dart b/lib/util/file_saver.dart
index a617cf74..7fdec398 100644
--- a/lib/util/file_saver.dart
+++ b/lib/util/file_saver.dart
@@ -19,17 +19,17 @@ Future<void> saveFile({
final sink = File(destinationPath).openWrite();
try {
- int lastNotifyBytes = 0;
int savedBytes = 0;
- await stream.forEach((event) {
+ final stopwatch = Stopwatch()..start();
+ await for (final event in stream) {
sink.add(event);
savedBytes += event.length;
- if (savedBytes - lastNotifyBytes >= 100 * 1024) {
- lastNotifyBytes = savedBytes;
+ if (stopwatch.elapsedMilliseconds >= 100) {
+ stopwatch.reset();
onProgress(savedBytes);
}
- });
+ }
await sink.close();