π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Fix Locker upload progress handling
AmanRajSinghMourya66f83a20250e
diff --git a/mobile/apps/locker/lib/ui/pages/uploader_page.dart b/mobile/apps/locker/lib/ui/pages/uploader_page.dartindex 61282f9bd6..2e33165146 100644--- a/mobile/apps/locker/lib/ui/pages/uploader_page.dart+++ b/mobile/apps/locker/lib/ui/pages/uploader_page.dart@@ -2,6 +2,7 @@ import 'dart:io';import 'package:ente_components/ente_components.dart';import 'package:ente_events/event_bus.dart';+import 'package:ente_ui/components/progress_dialog.dart';import 'package:ente_ui/pages/base_home_page.dart';import 'package:ente_ui/utils/dialog_util.dart';import "package:ente_utils/email_util.dart";@@ -43,6 +44,10 @@ abstract class UploaderPageState<T extends UploaderPage> extends State<T> {allowMultiple: true,);+ if (!mounted) {+ return false;+ }+if (result != null && result.files.isNotEmpty) {final selectedFiles = result.files.where((file) => file.path != null)@@ -60,17 +65,20 @@ abstract class UploaderPageState<T extends UploaderPage> extends State<T> {Future<bool> uploadFiles(List<File> files) async {var didUpload = false;var hasUploadError = false;- final progressDialog = createProgressDialog(- context,- context.l10n.uploadedFilesProgress(0, files.length),- );+ var didShowDialog = false;+ final l10n = context.l10n;+ ProgressDialog? progressDialog;try {- final List<Future> futures = [];+ final futures = <Future<void>>[];final regularCollections = await CollectionService.instance.getCollectionsForUI();+ if (!mounted) {+ return false;+ }+// Navigate to upload screen to get collection selectionfinal uploadResult = await Navigator.of(context).push<FileUploadScreenResult>(@@ -98,7 +106,14 @@ abstract class UploaderPageState<T extends UploaderPage> extends State<T> {uploadResult.selectedCollections.add(uncategorizedCollection);}- await progressDialog.show();+ if (mounted) {+ final dialog = createProgressDialog(+ context,+ l10n.uploadedFilesProgress(0, files.length),+ );+ progressDialog = dialog;+ didShowDialog = await dialog.show();+ }int completedUploads = 0;for (final file in files) {@@ -107,64 +122,79 @@ abstract class UploaderPageState<T extends UploaderPage> extends State<T> {uploadResult.selectedCollections.first,);futures.add(- fileUploadFuture- .then((enteFile) async {- completedUploads++;- if (!hasUploadError && progressDialog.isShowing()) {- progressDialog.update(- message: context.l10n.uploadedFilesProgress(+ fileUploadFuture.then<void>(+ (enteFile) async {+ completedUploads++;+ if (didShowDialog &&+ mounted &&+ !hasUploadError &&+ progressDialog?.isShowing() == true) {+ try {+ progressDialog?.update(+ message: l10n.uploadedFilesProgress(completedUploads,files.length,),);+ } catch (e, s) {+ _logger.warning('Failed to update upload progress', e, s);}- // Add to additional collections if multiple were selected- for (- int cIndex = 1;- cIndex < uploadResult.selectedCollections.length;- cIndex++- ) {- // Don't trigger a sync for each additional collection β do one- // sync at the end after all files are processed.- futures.add(- CollectionService.instance.addToCollection(- uploadResult.selectedCollections[cIndex],- enteFile,- runSync: false,- ),- );- }+ }- if (uploadResult.note.isNotEmpty) {- futures.add(- MetadataUpdaterService.instance.editFileCaption(- enteFile,- uploadResult.note,- ),- );- }- })- .catchError((e) async {- completedUploads++;- _logger.severe('File upload failed', e);- if (hasUploadError) {- return;- }- hasUploadError = true;- if (progressDialog.isShowing()) {- await progressDialog.hide();- }- if (mounted) {- await _showUploadFailureError(e);- }- }),+ final postUploadFutures = <Future<dynamic>>[];+ // Add to additional collections if multiple were selected+ for (+ int cIndex = 1;+ cIndex < uploadResult.selectedCollections.length;+ cIndex+++ ) {+ // Don't trigger a sync for each additional collection β do one+ // sync at the end after all files are processed.+ postUploadFutures.add(+ CollectionService.instance.addToCollection(+ uploadResult.selectedCollections[cIndex],+ enteFile,+ runSync: false,+ ),+ );+ }++ if (uploadResult.note.isNotEmpty) {+ postUploadFutures.add(+ MetadataUpdaterService.instance.editFileCaption(+ enteFile,+ uploadResult.note,+ ),+ );+ }++ await Future.wait(postUploadFutures);+ },+ onError: (Object e, StackTrace s) async {+ completedUploads++;+ _logger.severe('File upload failed', e, s);+ if (hasUploadError) {+ return;+ }+ hasUploadError = true;+ if (didShowDialog && progressDialog?.isShowing() == true) {+ await progressDialog?.hide();+ didShowDialog = false;+ }+ if (mounted) {+ await _showUploadFailureError(e);+ }+ },+ ),);}if (futures.isNotEmpty) {await Future.wait(futures);- onFileUploadComplete();+ if (mounted) {+ onFileUploadComplete();+ }Bus.instance.fire(UserDetailsRefreshEvent());await CollectionService.instance.sync().catchError((e) {@@ -173,16 +203,18 @@ abstract class UploaderPageState<T extends UploaderPage> extends State<T> {}}} catch (e, s) {- _logger.severe('Failed to upload file', e, s);- if (progressDialog.isShowing()) {- await progressDialog.hide();+ _logger.severe('Failed to complete file upload', e, s);+ if (didShowDialog && progressDialog?.isShowing() == true) {+ await progressDialog?.hide();+ didShowDialog = false;}if (mounted) {await _showUploadFailureError(e);}} finally {- if (progressDialog.isShowing()) {- await progressDialog.hide();+ if (didShowDialog && progressDialog?.isShowing() == true) {+ await progressDialog?.hide();+ didShowDialog = false;}}