diff --git a/lib/services/sync_service.dart b/lib/services/sync_service.dart index 6c590aea8daf7747ed5c3b002b09b96a0f3eb940..739b2d4cf968f854eac8dd43ed199a84c168809f 100644 --- a/lib/services/sync_service.dart +++ b/lib/services/sync_service.dart @@ -45,6 +45,7 @@ class SyncService { SyncService._privateConstructor() { Bus.instance.on().listen((event) { + _uploader.clearQueue(); sync(); }); diff --git a/lib/utils/file_uploader.dart b/lib/utils/file_uploader.dart index 41385fe64ca3c506a940b6049040616e62eaf3bd..c4100334e3525babd680fcf4648eda975740533a 100644 --- a/lib/utils/file_uploader.dart +++ b/lib/utils/file_uploader.dart @@ -106,17 +106,21 @@ class FileUploader { } } + void clearQueue() { + final uploadsToBeRemoved = List(); + _queue.entries + .where((entry) => entry.value.status == UploadStatus.not_started) + .forEach((pendingUpload) { + uploadsToBeRemoved.add(pendingUpload.key); + }); + for (final id in uploadsToBeRemoved) { + _queue.remove(id).completer.completeError(SyncStopRequestedError()); + } + } + void _pollQueue() { if (SyncService.instance.shouldStopSync()) { - final uploadsToBeRemoved = List(); - _queue.entries - .where((entry) => entry.value.status == UploadStatus.not_started) - .forEach((pendingUpload) { - uploadsToBeRemoved.add(pendingUpload.key); - }); - for (final id in uploadsToBeRemoved) { - _queue.remove(id).completer.completeError(SyncStopRequestedError()); - } + clearQueue(); } if (_queue.length > 0 && _currentlyUploading < _maximumConcurrentUploads) { final firstPendingEntry = _queue.entries