Skip to content

armgit / ente

Public Imported from GitHub
0

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

Fix legacy kit wait and download cancellation

Neeraj Gupta99336a747640
diff --git a/mobile/packages/legacy/lib/pages/create_legacy_kit_sheet.dart b/mobile/packages/legacy/lib/pages/create_legacy_kit_sheet.dart
index 3ba61447c6..0715ce8718 100644
--- a/mobile/packages/legacy/lib/pages/create_legacy_kit_sheet.dart
+++ b/mobile/packages/legacy/lib/pages/create_legacy_kit_sheet.dart
@@ -45,6 +45,7 @@ Future<int?> showLegacyKitRecoveryWaitTimeSheet(
BuildContext context, {
required int selectedDays,
bool showCancellationWarning = true,
+ bool requireChange = true,
}) {
final colorScheme = getEnteColorScheme(context);
final textTheme = getEnteTextTheme(context);
@@ -66,6 +67,7 @@ Future<int?> showLegacyKitRecoveryWaitTimeSheet(
child: _LegacyKitRecoveryWaitSheet(
selectedDays: selectedDays,
showCancellationWarning: showCancellationWarning,
+ requireChange: requireChange,
),
);
}
@@ -183,6 +185,7 @@ class _CreateLegacyKitPageState extends State<CreateLegacyKitPage> {
context,
selectedDays: _selectedDays,
showCancellationWarning: false,
+ requireChange: false,
);
if (selectedDays != null && mounted) {
setState(() {
@@ -321,10 +324,12 @@ class CreateLegacyKitSheet extends StatefulWidget {
class _LegacyKitRecoveryWaitSheet extends StatefulWidget {
final int selectedDays;
final bool showCancellationWarning;
+ final bool requireChange;
const _LegacyKitRecoveryWaitSheet({
required this.selectedDays,
required this.showCancellationWarning,
+ required this.requireChange,
});
@override
@@ -335,7 +340,8 @@ class _LegacyKitRecoveryWaitSheet extends StatefulWidget {
class _LegacyKitRecoveryWaitSheetState
extends State<_LegacyKitRecoveryWaitSheet> {
late int _selectedDays = widget.selectedDays;
- bool get _hasChanges => _selectedDays != widget.selectedDays;
+ bool get _canContinue =>
+ !widget.requireChange || _selectedDays != widget.selectedDays;
@override
Widget build(BuildContext context) {
@@ -380,7 +386,7 @@ class _LegacyKitRecoveryWaitSheetState
height: 52,
textStyle: textTheme.small.copyWith(height: 20 / 14),
disabledTextColor: colorScheme.textFaint,
- onTap: _hasChanges
+ onTap: _canContinue
? () => Navigator.of(context).pop(_selectedDays)
: null,
),
diff --git a/mobile/packages/legacy/lib/pages/legacy_kit_page.dart b/mobile/packages/legacy/lib/pages/legacy_kit_page.dart
index 1a25627653..f085026892 100644
--- a/mobile/packages/legacy/lib/pages/legacy_kit_page.dart
+++ b/mobile/packages/legacy/lib/pages/legacy_kit_page.dart
@@ -319,7 +319,11 @@ class _LegacyKitPageState extends State<LegacyKitPage> {
share: share,
allShares: shares,
);
- await _savePdf(bytes, _kit, part: _partForShare(share));
+ final saved = await _savePdf(bytes, _kit, part: _partForShare(share));
+ if (!saved) {
+ await dialog.hide();
+ return;
+ }
}
await dialog.hide();
if (mounted) {
@@ -353,8 +357,11 @@ class _LegacyKitPageState extends State<LegacyKitPage> {
share: share,
allShares: shares,
);
- await _savePdf(bytes, _kit, part: part);
+ final saved = await _savePdf(bytes, _kit, part: part);
await dialog.hide();
+ if (!saved) {
+ return;
+ }
if (mounted) {
showShortToast(context, context.strings.legacyKitSheetDownloaded);
}
@@ -453,7 +460,7 @@ class _LegacyKitPageState extends State<LegacyKitPage> {
return authenticator(context, reason);
}
- Future<void> _savePdf(
+ Future<bool> _savePdf(
Uint8List bytes,
LegacyKit kit, {
LegacyKitPart? part,
diff --git a/mobile/packages/utils/lib/file_saver_util.dart b/mobile/packages/utils/lib/file_saver_util.dart
index f3dd9d8356..fb4f641f47 100644
--- a/mobile/packages/utils/lib/file_saver_util.dart
+++ b/mobile/packages/utils/lib/file_saver_util.dart
@@ -4,7 +4,7 @@ import 'package:file_saver/file_saver.dart';
import 'package:flutter/foundation.dart';
class FileSaverUtil {
- static Future<void> saveFile(
+ static Future<bool> saveFile(
String fileName,
String extension,
Uint8List bytes,
@@ -12,12 +12,13 @@ class FileSaverUtil {
) async {
try {
if (Platform.isAndroid || Platform.isIOS) {
- await FileSaver.instance.saveAs(
+ final savedPath = await FileSaver.instance.saveAs(
name: fileName,
fileExtension: extension,
bytes: bytes,
mimeType: type,
);
+ return savedPath != null;
} else {
await FileSaver.instance.saveFile(
name: fileName,
@@ -25,7 +26,10 @@ class FileSaverUtil {
bytes: bytes,
mimeType: type,
);
+ return true;
}
- } catch (_) {}
+ } catch (_) {
+ return false;
+ }
}
}