π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Fix free-up-space success confirmation
ashilknb02688f0a990
diff --git a/mobile/apps/photos/changes/free-space-success-confirmation.md b/mobile/apps/photos/changes/free-space-success-confirmation.mdnew file mode 100644index 0000000000..d0f6f13807--- /dev/null+++ b/mobile/apps/photos/changes/free-space-success-confirmation.md@@ -0,0 +1 @@+- Fixed the Free Up Space screen remaining open without a success confirmation after files were deleted.diff --git a/mobile/apps/photos/lib/ui/common/progress_dialog.dart b/mobile/apps/photos/lib/ui/common/progress_dialog.dartindex 41da14956f..79f89966a3 100644--- a/mobile/apps/photos/lib/ui/common/progress_dialog.dart+++ b/mobile/apps/photos/lib/ui/common/progress_dialog.dart@@ -1,5 +1,3 @@-import "dart:async";-import 'package:flutter/material.dart';enum ProgressDialogType { normal, download }@@ -15,7 +13,6 @@ Alignment _progressWidgetAlignment = Alignment.centerLeft;TextDirection _direction = TextDirection.ltr;bool _isShowing = false;-BuildContext? _context, _dismissingContext;ProgressDialogType? _progressDialogType;bool _barrierDismissible = true, _showLogs = false;Color? _barrierColor;@@ -42,7 +39,11 @@ Widget _progressWidget = Image.asset();class ProgressDialog {+ final BuildContext _context;_Body? _dialog;+ Future<void>? _dialogPopped;+ ModalRoute<void>? _dialogRoute;+ NavigatorState? _navigator;bool get _isThisDialogShowing => _isShowing && _dialog != null;@@ -54,8 +55,7 @@ class ProgressDialog {TextDirection? textDirection,Widget? customBody,Color? barrierColor,- }) {- _context = context;+ }) : _context = context {_progressDialogType = type ?? ProgressDialogType.normal;_barrierDismissible = isDismissible ?? true;_showLogs = showLogs ?? false;@@ -129,23 +129,30 @@ class ProgressDialog {}Future<bool> hide() async {+ if (!_isThisDialogShowing) {+ if (_showLogs) debugPrint('ProgressDialog already dismissed');+ return false;+ }+try {- if (_isThisDialogShowing) {- _isShowing = false;- if (_dismissingContext != null) {- Navigator.of(_dismissingContext!).pop();+ final navigator = _navigator;+ if (navigator != null) {+ navigator.pop();+ final dialogRoute = _dialogRoute;+ if (dialogRoute != null) {+ await dialogRoute.completed;+ } else {+ await _dialogPopped;}- _dialog = null;- if (_showLogs) debugPrint('ProgressDialog dismissed');- return Future.value(true);- } else {- if (_showLogs) debugPrint('ProgressDialog already dismissed');- return Future.value(false);}+ if (_showLogs) debugPrint('ProgressDialog dismissed');+ return true;} catch (err) {debugPrint('Seems there is an issue hiding dialog');debugPrint(err.toString());- return Future.value(false);+ return false;+ } finally {+ _clearDialogState();}}@@ -154,31 +161,30 @@ class ProgressDialog {if (!_isShowing) {_isShowing = true;_dialog = _Body();- unawaited(- showDialog<dynamic>(- context: _context!,- barrierDismissible: _barrierDismissible,- barrierColor: _barrierColor,- useRootNavigator: false,- builder: (BuildContext context) {- _dismissingContext = context;- return PopScope(- canPop: _barrierDismissible,- child: Dialog(- backgroundColor: _backgroundColor,- insetAnimationCurve: _insetAnimCurve,- insetAnimationDuration: const Duration(milliseconds: 100),- elevation: _dialogElevation,- shape: RoundedRectangleBorder(- borderRadius: BorderRadius.all(- Radius.circular(_borderRadius),- ),+ _navigator = Navigator.of(_context);+ _dialogPopped = showDialog<void>(+ context: _context,+ barrierDismissible: _barrierDismissible,+ barrierColor: _barrierColor,+ useRootNavigator: false,+ builder: (context) {+ _dialogRoute = ModalRoute.of<void>(context);+ return PopScope(+ canPop: _barrierDismissible,+ child: Dialog(+ backgroundColor: _backgroundColor,+ insetAnimationCurve: _insetAnimCurve,+ insetAnimationDuration: const Duration(milliseconds: 100),+ elevation: _dialogElevation,+ shape: RoundedRectangleBorder(+ borderRadius: BorderRadius.all(+ Radius.circular(_borderRadius),),- child: _dialog,),- );- },- ),+ child: _dialog,+ ),+ );+ },);// Delaying the function for 200 milliseconds// [Default transitionDuration of DialogRoute]@@ -190,13 +196,20 @@ class ProgressDialog {return false;}} catch (err) {- _isShowing = false;- _dialog = null;+ _clearDialogState();debugPrint('Exception while showing the dialog');debugPrint(err.toString());return false;}}++ void _clearDialogState() {+ _isShowing = false;+ _dialog = null;+ _dialogPopped = null;+ _dialogRoute = null;+ _navigator = null;+ }}// ignore: must_be_immutablediff --git a/mobile/apps/photos/test/ui/common/progress_dialog_test.dart b/mobile/apps/photos/test/ui/common/progress_dialog_test.dartindex 05253a77f5..28c4018222 100644--- a/mobile/apps/photos/test/ui/common/progress_dialog_test.dart+++ b/mobile/apps/photos/test/ui/common/progress_dialog_test.dart@@ -39,7 +39,69 @@ void main() {await tester.pump(const Duration(milliseconds: 200));expect(await firstShow, isTrue);- await firstDialog.hide();+ final hideFuture = firstDialog.hide();await tester.pumpAndSettle();+ expect(await hideFuture, isTrue);});++ testWidgets("waits for sequential dismissals before the page is popped", (+ tester,+ ) async {+ bool? routeResult;++ await tester.pumpWidget(+ MaterialApp(+ home: Builder(+ builder: (context) => Scaffold(+ body: TextButton(+ onPressed: () async {+ routeResult = await Navigator.of(context).push<bool>(+ MaterialPageRoute(builder: (_) => const _DeletionPage()),+ );+ },+ child: const Text("Open"),+ ),+ ),+ ),+ ),+ );++ await tester.tap(find.text("Open"));+ await tester.pumpAndSettle();+ await tester.tap(find.text("Delete"));+ for (var index = 0; index < 12; index++) {+ await tester.pump(const Duration(milliseconds: 250));+ }+ await tester.pumpAndSettle();++ expect(find.text("Delete"), findsNothing);+ expect(routeResult, isTrue);+ });+}++class _DeletionPage extends StatelessWidget {+ const _DeletionPage();++ @override+ Widget build(BuildContext context) {+ return Scaffold(+ body: TextButton(+ onPressed: () async {+ for (final message in ["Deleting", "Loading", "Deleting again"]) {+ final dialog = ProgressDialog(context, isDismissible: false);+ dialog.style(+ message: message,+ progressWidget: const SizedBox.shrink(),+ );+ await dialog.show();+ await dialog.hide();+ }+ if (context.mounted) {+ Navigator.of(context).pop(true);+ }+ },+ child: const Text("Delete"),+ ),+ );+ }}