diff --git a/lib/services/sync_service.dart b/lib/services/sync_service.dart index 6c590aea8..739b2d4cf 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 41385fe64..c4100334e 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