π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Keep Locker operations running after widget disposal
AmanRajSinghMourya8f331ea582e7
diff --git a/mobile/apps/locker/lib/l10n/app_en.arb b/mobile/apps/locker/lib/l10n/app_en.arbindex 4cfd91a6a9..e90b76d505 100644--- a/mobile/apps/locker/lib/l10n/app_en.arb+++ b/mobile/apps/locker/lib/l10n/app_en.arb@@ -1049,6 +1049,7 @@"editNotSupportedForSharedFiles": "Edit is not supported for shared files","deleteNotSupportedForSharedFiles": "Delete is not supported for shared files","importantNotSupportedForSharedFiles": "Important is not supported for shared files",+ "canOnlyRemoveFilesOwnedByYou": "Can only remove files owned by you","sharingSection": "Sharing","sharingEnabledToggle": "Sharing enabled","publicLinkSection": "Public Link",diff --git a/mobile/apps/locker/lib/services/collections/collections_service.dart b/mobile/apps/locker/lib/services/collections/collections_service.dartindex a4c15a8b15..d615f72608 100644--- a/mobile/apps/locker/lib/services/collections/collections_service.dart+++ b/mobile/apps/locker/lib/services/collections/collections_service.dart@@ -14,6 +14,7 @@ import "package:flutter/material.dart";import 'package:locker/core/errors.dart';import 'package:locker/events/collections_updated_event.dart';import 'package:locker/events/user_details_refresh_event.dart';+import 'package:locker/l10n/l10n.dart';import "package:locker/services/collections/collections_api_client.dart";import 'package:locker/services/collections/models/collection.dart';import "package:locker/services/collections/models/files_split.dart";@@ -475,7 +476,7 @@ class CollectionService {}Future<void> trashCollection(- BuildContext context,+ BuildContext? context,Collection collection, {bool keepFiles = true,}) async {@@ -487,14 +488,18 @@ class CollectionService {}Future<void> trashCollectionKeepingFiles(- BuildContext context,+ BuildContext? context,Collection collection,) async {try {final files = await _db.getFilesInCollection(collection);if (files.isNotEmpty) {- await moveFilesFromCurrentCollection(context, collection, files);+ await moveFilesFromCurrentCollection(+ context != null && context.mounted ? context : null,+ collection,+ files,+ );}await _apiClient.trashCollection(collection, keepFiles: true);@@ -558,7 +563,7 @@ class CollectionService {}Future<void> moveFilesFromCurrentCollection(- BuildContext context,+ BuildContext? context,Collection collection,Iterable<EnteFile> files, {bool isHidden = false,@@ -585,7 +590,9 @@ class CollectionService {}if (!isCollectionOwner && split.ownedByOtherUsers.isNotEmpty) {- showShortToast(context, "Can only remove files owned by you");+ if (context != null && context.mounted) {+ showShortToast(context, context.l10n.canOnlyRemoveFilesOwnedByYou);+ }return;}diff --git a/mobile/apps/locker/lib/services/favorites_service.dart b/mobile/apps/locker/lib/services/favorites_service.dartindex 5f66978968..284066816a 100644--- a/mobile/apps/locker/lib/services/favorites_service.dart+++ b/mobile/apps/locker/lib/services/favorites_service.dart@@ -1,7 +1,6 @@import 'dart:async';import 'package:ente_events/event_bus.dart';-import 'package:flutter/material.dart';import 'package:locker/events/collections_updated_event.dart';import 'package:locker/services/collections/collections_service.dart';import 'package:locker/services/collections/models/collection.dart';@@ -134,7 +133,7 @@ class FavoritesService {}}- Future<void> addToFavorites(BuildContext context, EnteFile file) async {+ Future<void> addToFavorites(EnteFile file) async {final collectionID = await _getOrCreateFavoriteCollectionID();final List<EnteFile> files = [file];@@ -154,11 +153,7 @@ class FavoritesService {_collectionService.sync().ignore();}- Future<void> updateFavorites(- BuildContext context,- List<EnteFile> files,- bool favFlag,- ) async {+ Future<void> updateFavorites(List<EnteFile> files, bool favFlag) async {final int currentUserID = Configuration.instance.getUserID()!;if (files.any((f) => f.uploadedFileID == null)) {throw AssertionError("Can only favorite uploaded items");@@ -201,7 +196,7 @@ class FavoritesService {_updateFavoriteFilesCache(files, favFlag: favFlag);}- Future<void> removeFromFavorites(BuildContext context, EnteFile file) async {+ Future<void> removeFromFavorites(EnteFile file) async {final inUploadID = file.uploadedFileID;if (inUploadID == null) {// Do nothing, ignorediff --git a/mobile/apps/locker/lib/services/files/offline/offline_files_service.dart b/mobile/apps/locker/lib/services/files/offline/offline_files_service.dartindex 9f0f6f5a76..bcbec75c6c 100644--- a/mobile/apps/locker/lib/services/files/offline/offline_files_service.dart+++ b/mobile/apps/locker/lib/services/files/offline/offline_files_service.dart@@ -64,24 +64,25 @@ class OfflineFilesService {'Mark offline requested for ${eligibleFiles.length} eligible files',);- if (eligibleFiles.isEmpty || !context.mounted) {+ if (eligibleFiles.isEmpty) {_logger.fine('No eligible files to mark offline');return false;}final total = eligibleFiles.length;- final dialog = createProgressDialog(- context,- total == 1- ? context.l10n.savingOffline- : '${context.l10n.savingOffline} 0/$total',- isDismissible: false,- );+ final savingOffline = context.mounted ? context.l10n.savingOffline : null;+ final dialog = savingOffline == null+ ? null+ : createProgressDialog(+ context,+ total == 1 ? savingOffline : '$savingOffline 0/$total',+ isDismissible: false,+ );var successCount = 0;var failureCount = 0;- await dialog.show();+ await dialog?.show();try {for (var index = 0; index < eligibleFiles.length; index++) {@@ -89,11 +90,13 @@ class OfflineFilesService {final fileID = file.uploadedFileID!;final currentStep = index + 1;- dialog.update(- message: total == 1- ? context.l10n.savingOffline- : '${context.l10n.savingOffline} $currentStep/$total',- );+ if (context.mounted && dialog != null) {+ dialog.update(+ message: total == 1+ ? savingOffline+ : '$savingOffline $currentStep/$total',+ );+ }final alreadyHasOfflineCopy =LockerDB.instance.isFileMarkedOffline(file) &&@@ -125,7 +128,7 @@ class OfflineFilesService {}} finally {try {- await dialog.hide();+ await dialog?.hide();} catch (_) {}}diff --git a/mobile/apps/locker/lib/ui/pages/base_info_page.dart b/mobile/apps/locker/lib/ui/pages/base_info_page.dartindex dbb660fb0c..0424ce2294 100644--- a/mobile/apps/locker/lib/ui/pages/base_info_page.dart+++ b/mobile/apps/locker/lib/ui/pages/base_info_page.dart@@ -300,6 +300,8 @@ abstract class BaseInfoPageState<T extends InfoData, W extends BaseInfoPage<T>>// Handle collection membership changesawait _updateCollectionMembership();+ if (!mounted) return;+// Update the local data to reflect the changes in the UI// Use the infoItem data directly since it contains the updated valuessetState(() {@@ -336,15 +338,9 @@ abstract class BaseInfoPageState<T extends InfoData, W extends BaseInfoPage<T>>);if (wasFavorite && !isFavoriteNow) {- await FavoritesService.instance.removeFromFavorites(- context,- widget.existingFile!,- );+ await FavoritesService.instance.removeFromFavorites(widget.existingFile!);} else if (!wasFavorite && isFavoriteNow) {- await FavoritesService.instance.addToFavorites(- context,- widget.existingFile!,- );+ await FavoritesService.instance.addToFavorites(widget.existingFile!);}// Only favorites is special-cased; Uncategorized is treated as a normal@@ -371,7 +367,7 @@ abstract class BaseInfoPageState<T extends InfoData, W extends BaseInfoPage<T>>(c) => c.id == collectionId,);await CollectionService.instance.moveFilesFromCurrentCollection(- context,+ mounted ? context : null,collection,[widget.existingFile!],);@@ -405,7 +401,7 @@ abstract class BaseInfoPageState<T extends InfoData, W extends BaseInfoPage<T>>(c) => c.id == collectionId,);await CollectionService.instance.moveFilesFromCurrentCollection(- context,+ mounted ? context : null,collection,[widget.existingFile!],);@@ -450,6 +446,8 @@ abstract class BaseInfoPageState<T extends InfoData, W extends BaseInfoPage<T>>await CollectionService.instance.sync();Bus.instance.fire(UserDetailsRefreshEvent());+ if (!mounted) return;+// Show success messagefinal collectionCount = selectedCollections.length;final message = collectionCount == 1diff --git a/mobile/apps/locker/lib/utils/collection_actions.dart b/mobile/apps/locker/lib/utils/collection_actions.dartindex 7bc04a9c36..acab215283 100644--- a/mobile/apps/locker/lib/utils/collection_actions.dart+++ b/mobile/apps/locker/lib/utils/collection_actions.dart@@ -74,31 +74,31 @@ class CollectionActions {Collection collection, {VoidCallback? onSuccess,}) async {+ final l10n = context.l10n;if (!collection.type.canEdit) {- showToast(context, context.l10n.collectionCannotBeEdited);+ showToast(context, l10n.collectionCannotBeEdited);return;}await showTextInputSheet(context,- title: context.l10n.renameCollection,+ title: l10n.renameCollection,initialValue: collection.name ?? '',- hintText: context.l10n.documentsHint,- submitButtonLabel: context.l10n.save,+ hintText: l10n.documentsHint,+ submitButtonLabel: l10n.save,onSubmit: (String newName) async {if (newName.isEmpty || newName == collection.name) return;- final progressDialog = createProgressDialog(- context,- context.l10n.pleaseWait,- );+ final progressDialog = createProgressDialog(context, l10n.pleaseWait);await progressDialog.show();try {await CollectionService.instance.rename(collection, newName);await progressDialog.hide();- showToast(context, context.l10n.collectionRenamedSuccessfully);+ if (context.mounted) {+ showToast(context, l10n.collectionRenamedSuccessfully);+ }// Update the collection name locallycollection.setName(newName);@@ -108,7 +108,9 @@ class CollectionActions {} catch (error) {await progressDialog.hide();- await showLockerErrorSheet(context, error);+ if (context.mounted) {+ await showLockerErrorSheet(context, error);+ }}},);@@ -120,31 +122,31 @@ class CollectionActions {VoidCallback? onSuccess,}) async {if (collections.isEmpty) return;+ final l10n = context.l10n;final dialogChoice = await showDeleteConfirmationSheet(context,- title: context.l10n.areYouSure,- body: context.l10n.deleteMultipleCollectionsDialogBody(- collections.length,- ),- deleteButtonLabel: context.l10n.yesDeleteCollections(collections.length),+ title: l10n.areYouSure,+ body: l10n.deleteMultipleCollectionsDialogBody(collections.length),+ deleteButtonLabel: l10n.yesDeleteCollections(collections.length),illustration: LockerBottomSheetIllustration.collectionDelete,showDeleteFromAllCollectionsOption: true,);if (dialogChoice?.buttonResult.action != ButtonAction.first) return;- final progressDialog = createProgressDialog(- context,- context.l10n.pleaseWait,- );- await progressDialog.show();+ ProgressDialog? progressDialog;+ if (context.mounted) {+ progressDialog = createProgressDialog(context, l10n.pleaseWait);+ await progressDialog.show();+ }bool isFavoriteCollection = false;final bool keepFiles = !(dialogChoice?.deleteFromAllCollections ?? false);final List<Collection> emptyCollections = [];final List<Collection> nonEmptyCollections = [];final List<dynamic> errors = [];+ var deletedCount = 0;try {for (final collection in collections) {@@ -173,6 +175,7 @@ class CollectionActions {collection,isBulkDelete: true,);+ deletedCount++;} catch (e, s) {_logger.severe("Failed to trash empty collection", e, s);errors.add(e);@@ -187,36 +190,42 @@ class CollectionActions {for (final collection in nonEmptyCollections) {try {await CollectionService.instance.trashCollection(- context,+ context.mounted ? context : null,collection,keepFiles: keepFiles,);+ deletedCount++;} catch (e, s) {_logger.severe("Failed to trash collection", e, s);errors.add(e);}}- await progressDialog.hide();+ await progressDialog?.hide();++ if (deletedCount > 0) {+ onSuccess?.call();+ }- if (errors.isNotEmpty) {+ if (errors.isNotEmpty && context.mounted) {await showLockerErrorSheet(context, errors.first);}- showToast(- context,- context.l10n.collectionsDeletedSuccessfully(collections.length),- );+ if (context.mounted) {+ if (deletedCount > 0) {+ showToast(context, l10n.collectionsDeletedSuccessfully(deletedCount));+ }- if (isFavoriteCollection) {- showToast(context, context.l10n.actionNotSupportedOnFavouritesAlbum);+ if (isFavoriteCollection) {+ showToast(context, l10n.actionNotSupportedOnFavouritesAlbum);+ }}-- onSuccess?.call();} catch (error) {- await progressDialog.hide();+ await progressDialog?.hide();- await showLockerErrorSheet(context, error);+ if (context.mounted) {+ await showLockerErrorSheet(context, error);+ }}}@@ -235,13 +244,16 @@ class CollectionActions {final fileCount = await CollectionService.instance.getFileCount(collection);if (fileCount == 0) {- final progressDialog = createProgressDialog(context, l10n.pleaseWait);- await progressDialog.show();+ ProgressDialog? progressDialog;+ if (context.mounted) {+ progressDialog = createProgressDialog(context, l10n.pleaseWait);+ await progressDialog.show();+ }try {await CollectionService.instance.trashEmptyCollection(collection);- await progressDialog.hide();+ await progressDialog?.hide();if (context.mounted) {showToast(context, l10n.collectionDeletedSuccessfully);@@ -250,7 +262,7 @@ class CollectionActions {// Call success callback if providedonSuccess?.call();} catch (error) {- await progressDialog.hide();+ await progressDialog?.hide();if (context.mounted) {await showLockerErrorSheet(context, error);@@ -260,6 +272,7 @@ class CollectionActions {}final collectionName = collection.name ?? 'this collection';+ if (!context.mounted) return;final result = await showDeleteConfirmationSheet(context,@@ -270,23 +283,26 @@ class CollectionActions {showDeleteFromAllCollectionsOption: true,);- if (result?.buttonResult.action != ButtonAction.first && context.mounted) {+ if (result?.buttonResult.action != ButtonAction.first) {return;}- final progressDialog = createProgressDialog(context, l10n.pleaseWait);- await progressDialog.show();+ ProgressDialog? progressDialog;+ if (context.mounted) {+ progressDialog = createProgressDialog(context, l10n.pleaseWait);+ await progressDialog.show();+ }try {// If deleteFromAllCollections is true β keepFiles should be false (move files to trash)// If deleteFromAllCollections is false β keepFiles should be true (keep files in other collections)await CollectionService.instance.trashCollection(- context,+ context.mounted ? context : null,collection,keepFiles: !(result?.deleteFromAllCollections ?? false),);- await progressDialog.hide();+ await progressDialog?.hide();if (context.mounted) {showToast(context, l10n.collectionDeletedSuccessfully);@@ -295,7 +311,7 @@ class CollectionActions {// Call success callback if providedonSuccess?.call();} catch (error) {- await progressDialog.hide();+ await progressDialog?.hide();if (context.mounted) {await showLockerErrorSheet(context, error);@@ -325,8 +341,8 @@ class CollectionActions {if (confirmed == true) {try {await CollectionApiClient.instance.leaveCollection(collection);+ onSuccess?.call();if (context.mounted) {- onSuccess?.call();showToast(context, context.l10n.leaveCollectionSuccessfully);}} catch (e) {@@ -362,8 +378,8 @@ class CollectionActions {for (final col in collections) {await CollectionApiClient.instance.leaveCollection(col);}+ onSuccess?.call();if (context.mounted) {- onSuccess?.call();showToast(context,context.l10n.leftCollectionsSuccessfully(collections.length),@@ -390,11 +406,15 @@ class CollectionActions {);return true;} catch (e) {- if (e is SharingNotPermittedForFreeAccountsError) {- await showSubscriptionRequiredSheet(context);- } else {+ if (e is! SharingNotPermittedForFreeAccountsError) {_logger.severe("Failed to update shareUrl collection", e);- await showLockerErrorSheet(context, e);+ }+ if (context.mounted) {+ if (e is SharingNotPermittedForFreeAccountsError) {+ await showSubscriptionRequiredSheet(context);+ } else {+ await showLockerErrorSheet(context, e);+ }}return false;}@@ -457,7 +477,9 @@ class CollectionActions {} catch (e) {await dialog?.hide();_logger.severe("Failed to get public key", e);- await showLockerErrorSheet(context, e);+ if (context.mounted) {+ await showLockerErrorSheet(context, e);+ }return false;}// getPublicKey can return null when no user is associated with given@@ -465,7 +487,9 @@ class CollectionActions {if (publicKey == null || publicKey == '') {// todo: neeraj replace this as per the design where a new screen// is used for error. Do this change along with handling of network errors- await showInviteSheet(context, email: email);+ if (context.mounted) {+ await showInviteSheet(context, email: email);+ }return false;} else {return true;@@ -474,37 +498,41 @@ class CollectionActions {// addEmailToCollection returns true if add operation was successfulFuture<bool> addEmailToCollection(- BuildContext context,+ BuildContext? context,Collection collection,String email,CollectionParticipantRole role, {bool showProgress = false,}) async {if (!isValidEmail(email)) {- await showBottomSheetComponent(- context: context,- builder: (_) => BottomSheetComponent(- title: context.l10n.invalidEmailAddress,- message: context.l10n.enterValidEmail,- illustration: LockerBottomSheetIllustration.warningBlue,- ),- );+ if (context != null && context.mounted) {+ await showBottomSheetComponent(+ context: context,+ builder: (_) => BottomSheetComponent(+ title: context.l10n.invalidEmailAddress,+ message: context.l10n.enterValidEmail,+ illustration: LockerBottomSheetIllustration.warningBlue,+ ),+ );+ }return false;} else if (email.trim() == Configuration.instance.getEmail()) {- await showBottomSheetComponent(- context: context,- builder: (_) => BottomSheetComponent(- title: context.l10n.oops,- message: context.l10n.youCannotShareWithYourself,- illustration: LockerBottomSheetIllustration.warningBlue,- ),- );+ if (context != null && context.mounted) {+ await showBottomSheetComponent(+ context: context,+ builder: (_) => BottomSheetComponent(+ title: context.l10n.oops,+ message: context.l10n.youCannotShareWithYourself,+ illustration: LockerBottomSheetIllustration.warningBlue,+ ),+ );+ }return false;}ProgressDialog? dialog;String? publicKey;- if (showProgress) {+ if (showProgress && context != null && context.mounted) {dialog = createProgressDialog(context,context.l10n.sharing,@@ -518,14 +546,18 @@ class CollectionActions {} catch (e) {await dialog?.hide();_logger.severe("Failed to get public key", e);- await showLockerErrorSheet(context, e);+ if (context != null && context.mounted) {+ await showLockerErrorSheet(context, e);+ }return false;}// getPublicKey can return null when no user is associated with given// email idif (publicKey == null || publicKey == '') {await dialog?.hide();- await showInviteSheet(context, email: email);+ if (context != null && context.mounted) {+ await showInviteSheet(context, email: email);+ }return false;} else {try {@@ -540,11 +572,15 @@ class CollectionActions {return true;} catch (e) {await dialog?.hide();- if (e is SharingNotPermittedForFreeAccountsError) {- await showSubscriptionRequiredSheet(context);- } else {+ if (e is! SharingNotPermittedForFreeAccountsError) {_logger.severe("failed to share collection", e);- await showLockerErrorSheet(context, e);+ }+ if (context != null && context.mounted) {+ if (e is SharingNotPermittedForFreeAccountsError) {+ await showSubscriptionRequiredSheet(context);+ } else {+ await showLockerErrorSheet(context, e);+ }}return false;}@@ -566,7 +602,9 @@ class CollectionActions {return true;} catch (e) {_logger.severe("Failed to remove participant", e);- await showLockerErrorSheet(context, e);+ if (context.mounted) {+ await showLockerErrorSheet(context, e);+ }return false;}}diff --git a/mobile/apps/locker/lib/utils/file_actions.dart b/mobile/apps/locker/lib/utils/file_actions.dartindex eb13eb8c9b..e2feba6952 100644--- a/mobile/apps/locker/lib/utils/file_actions.dart+++ b/mobile/apps/locker/lib/utils/file_actions.dart@@ -61,13 +61,14 @@ class FileActions {final currentCollectionIds = currentCollections.map((c) => c.id).toSet();+ if (!context.mounted) return;final result = await showFileEditSheet(context,file: file,collections: editableCollections,);- if (result == null || !context.mounted) {+ if (result == null) {return;}@@ -75,12 +76,14 @@ class FileActions {final updatedAllCollections = await CollectionService.instance.getCollections();- final dialog = createProgressDialog(- context,- context.l10n.pleaseWait,- isDismissible: false,- );- await dialog.show();+ final dialog = context.mounted+ ? createProgressDialog(+ context,+ context.l10n.pleaseWait,+ isDismissible: false,+ )+ : null;+ await dialog?.show();try {final currentTitle = file.displayName;@@ -92,7 +95,7 @@ class FileActions {.editFileName(file, result.title);if (!metadataUpdateSuccess) {- await dialog.hide();+ await dialog?.hide();if (!context.mounted) {return;}@@ -113,9 +116,9 @@ class FileActions {);if (wasFavorite && !isFavoriteNow) {- await FavoritesService.instance.removeFromFavorites(context, file);+ await FavoritesService.instance.removeFromFavorites(file);} else if (!wasFavorite && isFavoriteNow) {- await FavoritesService.instance.addToFavorites(context, file);+ await FavoritesService.instance.addToFavorites(file);}final regularCurrentIds = currentCollectionIds@@ -140,7 +143,7 @@ class FileActions {(c) => c.id == collectionId,);await CollectionService.instance.moveFilesFromCurrentCollection(- context,+ context.mounted ? context : null,collection,[file],);@@ -177,7 +180,7 @@ class FileActions {(c) => c.id == collectionId,);await CollectionService.instance.moveFilesFromCurrentCollection(- context,+ context.mounted ? context : null,collection,[file],);@@ -185,17 +188,16 @@ class FileActions {}await CollectionService.instance.sync();- await dialog.hide();+ await dialog?.hide();+ onSuccess?.call();if (!context.mounted) {return;}showToast(context, context.l10n.fileUpdatedSuccessfully);-- onSuccess?.call();} catch (e) {- await dialog.hide();+ await dialog?.hide();_logger.severe('Failed to update file collections: $e');if (!context.mounted) {@@ -296,14 +298,16 @@ class FileActions {return;}- final dialog = createProgressDialog(- context,- context.l10n.deletingFile,- isDismissible: false,- );+ final dialog = context.mounted+ ? createProgressDialog(+ context,+ context.l10n.deletingFile,+ isDismissible: false,+ )+ : null;try {- await dialog.show();+ await dialog?.show();final collections = await CollectionService.instance.getCollectionsForFile(file);@@ -311,7 +315,7 @@ class FileActions {await CollectionService.instance.trashFile(file, collections.first);}- await dialog.hide();+ await dialog?.hide();if (context.mounted) {showToast(context, context.l10n.fileDeletedSuccessfully);@@ -319,7 +323,7 @@ class FileActions {onSuccess?.call();} catch (e) {- await dialog.hide();+ await dialog?.hide();if (context.mounted) {await showLockerErrorSheet(context, e);@@ -349,14 +353,16 @@ class FileActions {return;}- final dialog = createProgressDialog(- context,- context.l10n.deletingFile,- isDismissible: false,- );+ final dialog = context.mounted+ ? createProgressDialog(+ context,+ context.l10n.deletingFile,+ isDismissible: false,+ )+ : null;try {- await dialog.show();+ await dialog?.show();for (final file in files) {final collections = await CollectionService.instance@@ -374,7 +380,7 @@ class FileActions {await CollectionService.instance.sync();await TrashService.instance.syncTrash();- await dialog.hide();+ await dialog?.hide();if (context.mounted) {showToast(context, context.l10n.fileDeletedSuccessfully);@@ -382,7 +388,7 @@ class FileActions {onSuccess?.call();} catch (e, stackTrace) {- await dialog.hide();+ await dialog?.hide();_logger.severe('Failed to delete files: $e', e, stackTrace);if (!context.mounted) {@@ -416,9 +422,9 @@ class FileActions {await dialog.show();if (isCurrentlyImportant) {- await FavoritesService.instance.removeFromFavorites(context, file);+ await FavoritesService.instance.removeFromFavorites(file);} else {- await FavoritesService.instance.addToFavorites(context, file);+ await FavoritesService.instance.addToFavorites(file);}await dialog.hide();@@ -470,11 +476,7 @@ class FileActions {return;}- await FavoritesService.instance.updateFavorites(- context,- filesToMark,- true,- );+ await FavoritesService.instance.updateFavorites(filesToMark, true);await dialog.hide();diff --git a/mobile/apps/locker/lib/utils/file_util.dart b/mobile/apps/locker/lib/utils/file_util.dartindex cd1667651a..a14651c250 100644--- a/mobile/apps/locker/lib/utils/file_util.dart+++ b/mobile/apps/locker/lib/utils/file_util.dart@@ -2,7 +2,6 @@ import "dart:io";import "dart:typed_data";import "package:ente_components/ente_components.dart";-import "package:ente_ui/components/progress_dialog.dart";import "package:ente_ui/utils/dialog_util.dart";import "package:ente_ui/utils/toast_util.dart";import "package:ente_utils/email_util.dart";@@ -31,15 +30,29 @@ class FileUtil {static final Logger _logger = Logger("FileUtil");static Future<void> openFile(BuildContext context, EnteFile file) async {+ final l10n = context.l10n;++ Future<void> showOpenFileError({+ required String error,+ ResultType? resultType,+ }) async {+ if (!context.mounted) {+ return;+ }+ await _showOpenFileError(+ context,+ error: error,+ resultType: resultType,+ lockerFile: file,+ );+ }+if (InfoFileService.instance.isInfoFile(file)) {return _openInfoFile(context, file);}if (file.uploadedFileID == null) {- await showLockerErrorSheet(- context,- Exception(context.l10n.errorOpeningFile),- );+ await showLockerErrorSheet(context, Exception(l10n.errorOpeningFile));return;}@@ -48,31 +61,32 @@ class FileUtil {final cachedSize = await cachedDecryptedFile.length();if (cachedSize > 0) {await _launchFile(- context,cachedDecryptedFile,displayName: file.displayName,lockerFile: file,+ showError: showOpenFileError,);return;}await cachedDecryptedFile.delete();}- final dialog = createProgressDialog(- context,- context.l10n.downloading,- isDismissible: false,- );+ final dialog = context.mounted+ ? createProgressDialog(context, l10n.downloading, isDismissible: false)+ : null;try {- await dialog.show();+ await dialog?.show();final fileKey = await CollectionService.instance.getFileKey(file);void progressCallback(int downloaded, int total) {+ if (!context.mounted) {+ return;+ }if (total > 0 && downloaded >= 0) {final percentage = ((downloaded / total) * 100).clamp(0, 100).round();- dialog.update(message: context.l10n.downloadingProgress(percentage));+ dialog?.update(message: l10n.downloadingProgress(percentage));} else {- dialog.update(message: context.l10n.downloading);+ dialog?.update(message: l10n.downloading);}}@@ -82,25 +96,25 @@ class FileUtil {progressCallback: progressCallback,);- await dialog.hide();+ await dialog?.hide();if (decryptedFile != null) {await _launchFile(- context,decryptedFile,displayName: file.displayName,lockerFile: file,+ showError: showOpenFileError,);- } else {+ } else if (context.mounted) {await showBottomSheetComponent(context: context,builder: (_) => BottomSheetComponent(- title: context.l10n.downloadFailed,- message: context.l10n.failedToDownloadOrDecrypt,+ title: l10n.downloadFailed,+ message: l10n.failedToDownloadOrDecrypt,illustration: LockerBottomSheetIllustration.warningGrey,actions: [ButtonComponent(- label: context.l10n.contactSupport,+ label: l10n.contactSupport,onTap: () async {await sendLogs(context, "[email protected]", postShare: () {});},@@ -110,8 +124,10 @@ class FileUtil {);}} catch (e) {- await dialog.hide();- await showLockerErrorSheet(context, e);+ await dialog?.hide();+ if (context.mounted) {+ await showLockerErrorSheet(context, e);+ }}}@@ -135,9 +151,10 @@ class FileUtil {}final total = files.length;+ final l10n = context.l10n;final dialog = createProgressDialog(context,- "${context.l10n.downloading} 0/$total",+ "${l10n.downloading} 0/$total",isDismissible: false,);@@ -151,17 +168,18 @@ class FileUtil {try {for (final file in files) {index += 1;- dialog.update(- message:- '${context.l10n.downloading} ${file.displayName} ($index/$total)',- );+ if (context.mounted) {+ dialog.update(+ message: '${l10n.downloading} ${file.displayName} ($index/$total)',+ );+ }// Skip info items for now; they are meant to be viewed in-app.if (InfoFileService.instance.isInfoFile(file)) {_logger.fine('Skipping info file download (ID: ${file.uploadedFileID})',);- if (!hasShownInfoSkipToast) {+ if (!hasShownInfoSkipToast && context.mounted) {hasShownInfoSkipToast = true;showToast(context,@@ -180,11 +198,15 @@ class FileUtil {targetFileName: fileExtension.isEmpty? baseName: "$baseName.$fileExtension",- context: context,- progressDialog: dialog,- currentIndex: index,- totalCount: total,fileExtension: fileExtension,+ onProgress: (percentage) {+ if (context.mounted) {+ dialog.update(+ message:+ '${l10n.downloadingProgress(percentage)} ($index/$total)',+ );+ }+ },);savedNames.add(file.displayName);@@ -210,7 +232,7 @@ class FileUtil {if (e is UnsupportedError) {showToast(context, 'This file type is not supported for download');} else {- showToast(context, context.l10n.failedToDownloadOrDecrypt);+ showToast(context, l10n.failedToDownloadOrDecrypt);}}return false;@@ -226,11 +248,8 @@ class FileUtil {static Future<String?> _saveRegularFile({required EnteFile file,required String targetFileName,- required BuildContext context,- required ProgressDialog progressDialog,- required int currentIndex,- required int totalCount,required String fileExtension,+ required ValueChanged<int> onProgress,}) async {final fileKey = await CollectionService.instance.getFileKey(file);@@ -241,10 +260,7 @@ class FileUtil {progressCallback: (downloaded, total) {if (total > 0 && downloaded >= 0) {final percentage = ((downloaded / total) * 100).clamp(0, 100).round();- progressDialog.update(- message:- '${context.l10n.downloadingProgress(percentage)} ($currentIndex/$totalCount)',- );+ onProgress(percentage);}},);@@ -268,18 +284,10 @@ class FileUtil {throw Exception('Failed to save file');}- // After FileSaver returns, the context might be unmounted due to- // app lifecycle changes (e.g., LockScreen overlay appearing).- // Safely update the progress dialog if possible.- if (context.mounted) {- try {- progressDialog.update(- message:- '${context.l10n.downloadingProgress(100)} ($currentIndex/$totalCount)',- );- } catch (e) {- _logger.fine('Unable to update progress dialog after save: $e');- }+ try {+ onProgress(100);+ } catch (e) {+ _logger.fine('Unable to update progress dialog after save: $e');}return savedPath;} finally {@@ -394,15 +402,21 @@ class FileUtil {context,).push(MaterialPageRoute(builder: (context) => page));} catch (e) {- await showLockerErrorSheet(context, e);+ if (context.mounted) {+ await showLockerErrorSheet(context, e);+ }}}static Future<void> _launchFile(- BuildContext context,File file, {String? displayName,EnteFile? lockerFile,+ required Future<void> Function({+ required String error,+ ResultType? resultType,+ })+ showError,}) async {File fileToOpen = file;@@ -419,23 +433,10 @@ class FileUtil {final result = await OpenFile.open(fileToOpen.path);if (result.type != ResultType.done) {- if (context.mounted) {- await _showOpenFileError(- context,- resultType: result.type,- error: result.message,- lockerFile: lockerFile,- );- }+ await showError(error: result.message, resultType: result.type);}} catch (e) {- if (context.mounted) {- await _showOpenFileError(- context,- error: e.toString(),- lockerFile: lockerFile,- );- }+ await showError(error: e.toString());}}