π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mobile][photos] Guard progress dialog dismissal
ashilkna132b060fac5
diff --git a/mobile/apps/photos/lib/ui/common/progress_dialog.dart b/mobile/apps/photos/lib/ui/common/progress_dialog.dartindex 79f89966a3..9749c07887 100644--- a/mobile/apps/photos/lib/ui/common/progress_dialog.dart+++ b/mobile/apps/photos/lib/ui/common/progress_dialog.dart@@ -45,7 +45,12 @@ class ProgressDialog {ModalRoute<void>? _dialogRoute;NavigatorState? _navigator;- bool get _isThisDialogShowing => _isShowing && _dialog != null;+ bool get _isThisDialogShowing {+ final dialogRoute = _dialogRoute;+ return _isShowing &&+ _dialog != null &&+ (dialogRoute == null || dialogRoute.isActive);+ }ProgressDialog(BuildContext context, {@@ -125,28 +130,38 @@ class ProgressDialog {}bool isShowing() {- return _isShowing;+ return _isThisDialogShowing;}Future<bool> hide() async {- if (!_isThisDialogShowing) {+ if (_dialog == null) {if (_showLogs) debugPrint('ProgressDialog already dismissed');return false;}+ var dismissed = false;try {final navigator = _navigator;if (navigator != null) {- navigator.pop();final dialogRoute = _dialogRoute;if (dialogRoute != null) {+ if (dialogRoute.isActive) {+ if (dialogRoute.isCurrent) {+ navigator.pop();+ } else {+ navigator.removeRoute(dialogRoute);+ }+ dismissed = true;+ }await dialogRoute.completed;} else {+ navigator.pop();+ dismissed = true;await _dialogPopped;}}- if (_showLogs) debugPrint('ProgressDialog dismissed');- return true;+ if (_showLogs && dismissed) debugPrint('ProgressDialog dismissed');+ return dismissed;} catch (err) {debugPrint('Seems there is an issue hiding dialog');debugPrint(err.toString());diff --git a/mobile/apps/photos/test/ui/common/progress_dialog_test.dart b/mobile/apps/photos/test/ui/common/progress_dialog_test.dartindex 28c4018222..5880796b7f 100644--- a/mobile/apps/photos/test/ui/common/progress_dialog_test.dart+++ b/mobile/apps/photos/test/ui/common/progress_dialog_test.dart@@ -1,3 +1,5 @@+import "dart:async";+import "package:flutter/material.dart";import "package:flutter_test/flutter_test.dart";import "package:photos/ui/common/progress_dialog.dart";@@ -77,6 +79,76 @@ void main() {expect(find.text("Delete"), findsNothing);expect(routeResult, isTrue);});++ testWidgets("does not pop the page when barrier dismissal races with hide", (+ tester,+ ) async {+ final work = Completer<void>();++ await _pumpActionPage(+ tester,+ onPressed: (context) async {+ final dialog = ProgressDialog(context);+ dialog.style(progressWidget: const SizedBox.shrink());+ await dialog.show();+ await work.future;+ await dialog.hide();+ },+ );++ await tester.tap(find.text("Run"));+ await tester.pumpAndSettle();+ expect(find.byType(Dialog), findsOneWidget);++ await tester.tapAt(const Offset(10, 10));+ await tester.pump();+ work.complete();+ await tester.pumpAndSettle();++ expect(find.text("Run"), findsOneWidget);+ expect(find.text("Open"), findsNothing);+ });+}++Future<void> _pumpActionPage(+ WidgetTester tester, {+ required Future<void> Function(BuildContext) onPressed,+}) async {+ await tester.pumpWidget(+ MaterialApp(+ home: Builder(+ builder: (context) => Scaffold(+ body: TextButton(+ onPressed: () => Navigator.of(context).push<void>(+ MaterialPageRoute(+ builder: (_) => _ActionPage(onPressed: onPressed),+ ),+ ),+ child: const Text("Open"),+ ),+ ),+ ),+ ),+ );++ await tester.tap(find.text("Open"));+ await tester.pumpAndSettle();+}++class _ActionPage extends StatelessWidget {+ const _ActionPage({required this.onPressed});++ final Future<void> Function(BuildContext) onPressed;++ @override+ Widget build(BuildContext context) {+ return Scaffold(+ body: TextButton(+ onPressed: () => onPressed(context),+ child: const Text("Run"),+ ),+ );+ }}class _DeletionPage extends StatelessWidget {