Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

fix error state while uploading

AmanRajSinghMourya013b9a35d915
diff --git a/mobile/apps/locker/lib/ui/mixins/search_mixin.dart b/mobile/apps/locker/lib/ui/mixins/search_mixin.dart
index 9e197b0f02..928d9fe1c3 100644
--- a/mobile/apps/locker/lib/ui/mixins/search_mixin.dart
+++ b/mobile/apps/locker/lib/ui/mixins/search_mixin.dart
@@ -195,7 +195,8 @@ mixin SearchMixin<T extends StatefulWidget> on State<T> {
});
try {
- if (query.isEmpty) {
+ final normalizedQuery = query.trim();
+ if (normalizedQuery.isEmpty) {
if (mounted) {
onSearchResultsChanged(allCollections, allFiles);
}
@@ -207,7 +208,8 @@ mixin SearchMixin<T extends StatefulWidget> on State<T> {
for (final collection in allCollections) {
if (!mounted) return;
- final searchResult = await _searchInCollection(collection, query);
+ final searchResult =
+ await _searchInCollection(collection, normalizedQuery);
if (searchResult.matches) {
filteredCollections.add(collection);
if (searchResult.nameMatches) {
@@ -222,7 +224,7 @@ mixin SearchMixin<T extends StatefulWidget> on State<T> {
if (addedFileIds.contains(file.uploadedFileID.toString())) {
return false;
}
- return _searchInFile(file, query);
+ return _searchInFile(file, normalizedQuery);
}).toList();
final List<EnteFile> allFilteredFiles = [
@@ -290,7 +292,8 @@ mixin SearchMixin<T extends StatefulWidget> on State<T> {
bool _containsQuery(String text, String query) {
if (text.isEmpty) return false;
final lowerText = text.toLowerCase();
- final lowerQuery = query.toLowerCase();
+ final lowerQuery = query.trim().toLowerCase();
+ if (lowerQuery.isEmpty) return false;
if (lowerText.contains(lowerQuery)) {
return true;
diff --git a/mobile/apps/locker/lib/ui/pages/home_page.dart b/mobile/apps/locker/lib/ui/pages/home_page.dart
index b4444d204d..76b36b6992 100644
--- a/mobile/apps/locker/lib/ui/pages/home_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/home_page.dart
@@ -7,6 +7,7 @@ import 'package:ente_events/event_bus.dart';
import "package:ente_ui/components/alert_bottom_sheet.dart";
import 'package:ente_ui/theme/ente_theme.dart';
import 'package:ente_ui/utils/dialog_util.dart';
+import "package:ente_utils/email_util.dart";
import 'package:flutter/material.dart';
import "package:flutter_svg/flutter_svg.dart";
import "package:hugeicons/hugeicons.dart";
@@ -446,10 +447,23 @@ class _HomePageState extends UploaderPageState<HomePage>
} catch (e) {
_logger.severe('Error handling shared files: $e');
if (mounted) {
- await showErrorDialog(
+ await showAlertBottomSheet(
context,
- context.l10n.uploadError,
- 'Failed to process shared files: $e',
+ title: context.l10n.uploadError,
+ message: context.l10n.somethingWentWrong,
+ assetPath: "assets/warning-grey.png",
+ buttons: [
+ GradientButton(
+ text: context.l10n.contactSupport,
+ onTap: () async {
+ await sendLogs(
+ context,
+ postShare: () {},
+ );
+ },
+ ),
+ ],
);
}
}
diff --git a/mobile/apps/locker/lib/ui/pages/uploader_page.dart b/mobile/apps/locker/lib/ui/pages/uploader_page.dart
index f257dc9bec..82df3f1f19 100644
--- a/mobile/apps/locker/lib/ui/pages/uploader_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/uploader_page.dart
@@ -59,6 +59,7 @@ 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),
@@ -103,14 +104,15 @@ abstract class UploaderPageState<T extends UploaderPage> extends State<T> {
for (final file in files) {
final fileUploadFuture = FileUploader.instance
.upload(file, uploadResult.selectedCollections.first);
- futures.add(fileUploadFuture);
futures.add(
fileUploadFuture.then((enteFile) async {
completedUploads++;
- progressDialog.update(
- message: context.l10n
- .uploadedFilesProgress(completedUploads, files.length),
- );
+ if (!hasUploadError && progressDialog.isShowing()) {
+ progressDialog.update(
+ message: context.l10n
+ .uploadedFilesProgress(completedUploads, files.length),
+ );
+ }
// Add to additional collections if multiple were selected
for (int cIndex = 1;
cIndex < uploadResult.selectedCollections.length;
@@ -132,16 +134,19 @@ abstract class UploaderPageState<T extends UploaderPage> extends State<T> {
.editFileCaption(enteFile, uploadResult.note),
);
}
- }).catchError((e) {
+ }).catchError((e) async {
completedUploads++;
_logger.severe('File upload failed', e);
- progressDialog.update(
- message: context.l10n.uploadedFilesProgressWithError(
- completedUploads,
- files.length,
- e.toString(),
- ),
- );
+ if (hasUploadError) {
+ return;
+ }
+ hasUploadError = true;
+ if (progressDialog.isShowing()) {
+ await progressDialog.hide();
+ }
+ if (mounted) {
+ await _showUploadFailureError(e);
+ }
}),
);
}
@@ -162,26 +167,8 @@ abstract class UploaderPageState<T extends UploaderPage> extends State<T> {
if (progressDialog.isShowing()) {
await progressDialog.hide();
}
- if (e is StorageLimitExceededError) {
- await _showUploadErrorSheet(
- context.l10n.uploadStorageLimitErrorTitle,
- context.l10n.uploadStorageLimitErrorBody,
- );
- } else if (e is FileLimitReachedError) {
- await _showUploadErrorSheet(
- context.l10n.uploadFileCountLimitErrorTitle,
- context.l10n.uploadFileCountLimitErrorBody,
- );
- } else if (e is FileTooLargeForPlanError) {
- await _showUploadErrorSheet(
- context.l10n.uploadFileTooLargeErrorTitle,
- context.l10n.uploadFileTooLargeErrorBody,
- );
- } else {
- await showGenericErrorDialog(
- context: context,
- error: e,
- );
+ if (mounted) {
+ await _showUploadFailureError(e);
}
} finally {
if (progressDialog.isShowing()) {
@@ -192,6 +179,35 @@ abstract class UploaderPageState<T extends UploaderPage> extends State<T> {
return didUpload;
}
+ Future<void> _showUploadFailureError(Object error) async {
+ if (error is StorageLimitExceededError) {
+ await _showUploadErrorSheet(
+ context.l10n.uploadStorageLimitErrorTitle,
+ context.l10n.uploadStorageLimitErrorBody,
+ );
+ return;
+ }
+ if (error is FileLimitReachedError) {
+ await _showUploadErrorSheet(
+ context.l10n.uploadFileCountLimitErrorTitle,
+ context.l10n.uploadFileCountLimitErrorBody,
+ );
+ return;
+ }
+ if (error is FileTooLargeForPlanError) {
+ await _showUploadErrorSheet(
+ context.l10n.uploadFileTooLargeErrorTitle,
+ context.l10n.uploadFileTooLargeErrorBody,
+ );
+ return;
+ }
+ await showGenericErrorBottomSheet(
+ context: context,
+ error: error,
+ surfaceError: false,
+ );
+ }
+
Future<void> _showUploadErrorSheet(String title, String message) async {
await showAlertBottomSheet(
context,
diff --git a/mobile/apps/locker/lib/utils/file_util.dart b/mobile/apps/locker/lib/utils/file_util.dart
index 5b985c99a0..8d9eff8a85 100644
--- a/mobile/apps/locker/lib/utils/file_util.dart
+++ b/mobile/apps/locker/lib/utils/file_util.dart
@@ -1,9 +1,11 @@
import "dart:io";
import "dart:typed_data";
+import "package:ente_ui/components/alert_bottom_sheet.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";
import "package:file_saver/file_saver.dart";
import "package:flutter/material.dart";
import "package:locker/l10n/l10n.dart";
@@ -13,6 +15,7 @@ import "package:locker/services/configuration.dart";
import "package:locker/services/files/download/file_downloader.dart";
import "package:locker/services/files/sync/models/file.dart";
import "package:locker/services/info_file_service.dart";
+import "package:locker/ui/components/gradient_button.dart";
import "package:locker/ui/pages/account_credentials_page.dart";
import "package:locker/ui/pages/base_info_page.dart";
import "package:locker/ui/pages/emergency_contact_page.dart";
@@ -77,18 +80,27 @@ class FileUtil {
if (decryptedFile != null) {
await _launchFile(context, decryptedFile, file.displayName);
} else {
- await showErrorDialog(
+ await showAlertBottomSheet(
context,
- context.l10n.downloadFailed,
- context.l10n.failedToDownloadOrDecrypt,
+ title: context.l10n.downloadFailed,
+ message: context.l10n.failedToDownloadOrDecrypt,
+ assetPath: "assets/warning-grey.png",
+ buttons: [
+ GradientButton(
+ text: context.l10n.contactSupport,
+ onTap: () async {
+ await sendLogs(context, "[email protected]", postShare: () {});
+ },
+ ),
+ ],
);
}
} catch (e) {
await dialog.hide();
- await showErrorDialog(
- context,
- context.l10n.errorOpeningFile,
- context.l10n.errorOpeningFileMessage(e.toString()),
+ await showGenericErrorBottomSheet(
+ context: context,
+ error: e,
+ surfaceError: false,
);
}
}
@@ -331,10 +343,19 @@ class FileUtil {
try {
final infoItem = InfoFileService.instance.extractInfoFromFile(file);
if (infoItem == null) {
- await showErrorDialog(
+ await showAlertBottomSheet(
context,
- context.l10n.errorOpeningFile,
- 'Unable to extract information from this file',
+ title: context.l10n.errorOpeningFile,
+ message: "Unable to extract information from this file",
+ assetPath: "assets/warning-grey.png",
+ buttons: [
+ GradientButton(
+ text: context.l10n.contactSupport,
+ onTap: () async {
+ await sendLogs(context, "[email protected]", postShare: () {});
+ },
+ ),
+ ],
);
return;
}
@@ -371,10 +392,10 @@ class FileUtil {
MaterialPageRoute(builder: (context) => page),
);
} catch (e) {
- await showErrorDialog(
- context,
- context.l10n.errorOpeningFile,
- 'Failed to open info file: ${e.toString()}',
+ await showGenericErrorBottomSheet(
+ context: context,
+ error: e,
+ surfaceError: false,
);
}
}
@@ -387,10 +408,10 @@ class FileUtil {
try {
await OpenFile.open(file.path);
} catch (e) {
- await showErrorDialog(
- context,
- context.l10n.errorOpeningFile,
- context.l10n.couldNotOpenFile(e.toString()),
+ await showGenericErrorBottomSheet(
+ context: context,
+ error: e,
+ surfaceError: false,
);
}
}