π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
add context check -2
AmanRajSinghMouryacdc7f8f2bb93
diff --git a/mobile/packages/accounts/lib/pages/recovery_key_page.dart b/mobile/packages/accounts/lib/pages/recovery_key_page.dartindex 5b63de94dd..f6aba10d32 100644--- a/mobile/packages/accounts/lib/pages/recovery_key_page.dart+++ b/mobile/packages/accounts/lib/pages/recovery_key_page.dart@@ -73,10 +73,12 @@ class _RecoveryKeyPageState extends State<RecoveryKeyPage> {Future<void> copy() async {await Clipboard.setData(ClipboardData(text: recoveryKey));- showShortToast(context, context.strings.recoveryKeyCopiedToClipboard);- setState(() {- _hasTriedToSave = true;- });+ if (context.mounted) {+ showShortToast(context, context.strings.recoveryKeyCopiedToClipboard);+ setState(() {+ _hasTriedToSave = true;+ });+ }}return Scaffold(@@ -296,7 +298,7 @@ class _RecoveryKeyPageState extends State<RecoveryKeyPage> {_recoveryKeyFile.writeAsStringSync(recoveryKey);await shareFiles([XFile(_recoveryKeyFile.path, mimeType: 'text/plain'),- ], context: context);+ ], context: mounted ? context : null);Future.delayed(const Duration(milliseconds: 500), () {if (mounted) {setState(() {diff --git a/mobile/packages/accounts/lib/pages/recovery_page.dart b/mobile/packages/accounts/lib/pages/recovery_page.dartindex 1db083139c..fc33070230 100644--- a/mobile/packages/accounts/lib/pages/recovery_page.dart+++ b/mobile/packages/accounts/lib/pages/recovery_page.dart@@ -32,6 +32,9 @@ class _RecoveryPageState extends State<RecoveryPage> {try {await widget.config.recover(_recoveryKey.text.trim());await dialog.hide();+ if (!mounted) {+ return;+ }showToast(context, "Recovery successful!");await Navigator.of(context).pushReplacement(MaterialPageRoute(@@ -53,12 +56,14 @@ class _RecoveryPageState extends State<RecoveryPage> {if (e is AssertionError) {errMessage = '$errMessage : ${e.message}';}- await showAlertBottomSheet(- context,- title: context.strings.incorrectRecoveryKey,- message: errMessage,- assetPath: 'assets/warning-grey.png',- );+ if (mounted) {+ await showAlertBottomSheet(+ context,+ title: context.strings.incorrectRecoveryKey,+ message: errMessage,+ assetPath: 'assets/warning-grey.png',+ );+ }}}diff --git a/mobile/packages/accounts/lib/pages/request_pwd_verification_page.dart b/mobile/packages/accounts/lib/pages/request_pwd_verification_page.dartindex 324a3f39e0..74d2fea526 100644--- a/mobile/packages/accounts/lib/pages/request_pwd_verification_page.dart+++ b/mobile/packages/accounts/lib/pages/request_pwd_verification_page.dart@@ -103,13 +103,15 @@ class _RequestPasswordVerificationPageState// popawait widget.onPasswordVerified(keyEncryptionKey);await dialog.hide();- Navigator.of(context).pop(true);+ if (context.mounted) {+ Navigator.of(context).pop(true);+ }} catch (e, s) {_logger.severe("Error while verifying password", e, s);await dialog.hide();if (widget.onPasswordError != null) {widget.onPasswordError!();- } else {+ } else if (context.mounted) {// ignore: unawaited_futuresshowErrorDialog(context,diff --git a/mobile/packages/accounts/lib/pages/sessions_page.dart b/mobile/packages/accounts/lib/pages/sessions_page.dartindex 3b53feda3c..531f8ee6fc 100644--- a/mobile/packages/accounts/lib/pages/sessions_page.dart+++ b/mobile/packages/accounts/lib/pages/sessions_page.dart@@ -28,7 +28,9 @@ class _SessionsPageState extends State<SessionsPage> {@overridevoid initState() {_fetchActiveSessions().onError((error, stackTrace) {- showToast(context, "Failed to fetch active sessions");+ if (mounted) {+ showToast(context, "Failed to fetch active sessions");+ }});super.initState();}@@ -117,12 +119,14 @@ class _SessionsPageState extends State<SessionsPage> {} catch (e) {await dialog.hide();_logger.severe('failed to terminate');- // ignore: unawaited_futures- showErrorDialog(- context,- context.strings.oops,- context.strings.somethingWentWrongPleaseTryAgain,- );+ if (mounted) {+ // ignore: unawaited_futures+ showErrorDialog(+ context,+ context.strings.oops,+ context.strings.somethingWentWrongPleaseTryAgain,+ );+ }}}diff --git a/mobile/packages/accounts/lib/services/passkey_service.dart b/mobile/packages/accounts/lib/services/passkey_service.dartindex 973b81baa4..9f9f743483 100644--- a/mobile/packages/accounts/lib/services/passkey_service.dart+++ b/mobile/packages/accounts/lib/services/passkey_service.dart@@ -43,7 +43,9 @@ class PasskeyService {await launchUrlString(url, mode: LaunchMode.externalApplication);} catch (e) {Logger('PasskeyService').severe("failed to open passkey page", e);- showGenericErrorDialog(context: context, error: e).ignore();+ if (context.mounted) {+ showGenericErrorDialog(context: context, error: e).ignore();+ }}}}diff --git a/mobile/packages/accounts/lib/services/user_service.dart b/mobile/packages/accounts/lib/services/user_service.dartindex 22b2b3979e..9ba2d3e8cd 100644--- a/mobile/packages/accounts/lib/services/user_service.dart+++ b/mobile/packages/accounts/lib/services/user_service.dart@@ -79,15 +79,17 @@ class UserService {}Future<void> sendOtt(- BuildContext context,+ BuildContext? context,String email, {bool isChangeEmail = false,bool isCreateAccountScreen = false,bool isResetPasswordScreen = false,String? purpose,}) async {- final dialog = createProgressDialog(context, context.strings.pleaseWait);- await dialog.show();+ final dialog = context != null && context.mounted+ ? createProgressDialog(context, context.strings.pleaseWait)+ : null;+ await dialog?.show();try {final response = await _dio.post("${_config.getHttpEndpoint()}/users/ott",@@ -97,7 +99,10 @@ class UserService {"mobile": Platform.isIOS || Platform.isAndroid,},);- await dialog.hide();+ await dialog?.hide();+ if (context == null || !context.mounted) {+ return;+ }if (response.statusCode == 200) {unawaited(Navigator.of(context).push(@@ -117,8 +122,11 @@ class UserService {}unawaited(showGenericErrorDialog(context: context, error: null));} on DioException catch (e) {- await dialog.hide();+ await dialog?.hide();_logger.info(e);+ if (context == null || !context.mounted) {+ return;+ }final responseData = e.response?.data;final Object? enteErrCode = responseData is Map? responseData["code"]@@ -163,9 +171,11 @@ class UserService {unawaited(showGenericErrorDialog(context: context, error: e));}} catch (e) {- await dialog.hide();+ await dialog?.hide();_logger.severe(e);- unawaited(showGenericErrorDialog(context: context, error: e));+ if (context != null && context.mounted) {+ unawaited(showGenericErrorDialog(context: context, error: e));+ }}}@@ -278,7 +288,7 @@ class UserService {try {final response = await _enteDio.post("/users/logout");if (response.statusCode == 200) {- await _logoutLocally(context);+ await _logoutLocally(context.mounted ? context : null);} else {throw Exception("Log out action failed");}@@ -295,28 +305,30 @@ class UserService {} else {_logger.info("Token already invalid, proceeding with local logout");}- await _logoutLocally(context);+ await _logoutLocally(context.mounted ? context : null);return;}_logger.severe(e);//This future is for waiting for the dialog from which logout() is called//to close and only then to show the error dialog.- Future.delayed(- const Duration(milliseconds: 150),- () => showGenericErrorDialog(context: context, error: e),- );+ Future.delayed(const Duration(milliseconds: 150), () {+ if (context.mounted) {+ unawaited(showGenericErrorDialog(context: context, error: e));+ }+ });rethrow;}}- Future<void> _logoutLocally(BuildContext context) async {+ Future<void> _logoutLocally(BuildContext? context) async {await _config.logout();- if (context.mounted) {- unawaited(- Navigator.of(context).pushNamedAndRemoveUntil('/', (route) => false),- );+ if (context == null || !context.mounted) {+ return;}+ unawaited(+ Navigator.of(context).pushNamedAndRemoveUntil('/', (route) => false),+ );}Future<dynamic> getTokenForPasskeySession(String sessionID) async {@@ -342,27 +354,21 @@ class UserService {}}- Future<void> onPassKeyVerified(BuildContext context, Map response) async {- final ProgressDialog dialog = createProgressDialog(- context,- context.strings.pleaseWait,- );- await dialog.show();+ Future<void> onPassKeyVerified(BuildContext? context, Map response) async {+ final ProgressDialog? dialog = context != null && context.mounted+ ? createProgressDialog(context, context.strings.pleaseWait)+ : null;+ await dialog?.show();try {final userPassword = _config.getVolatilePassword();await _saveConfiguration(response);- if (!context.mounted) {- await dialog.hide();- return;- }- final navigator = Navigator.of(context);if (userPassword == null) {- await dialog.hide();- if (!context.mounted) {+ await dialog?.hide();+ if (context == null || !context.mounted) {return;}// ignore: unawaited_futures- navigator.pushAndRemoveUntil(+ Navigator.of(context).pushAndRemoveUntil(MaterialPageRoute(builder: (BuildContext _) {return PasswordReentryPage(_config, _homePage);@@ -384,13 +390,13 @@ class UserService {} else {throw Exception("unexpected response during passkey verification");}- await dialog.hide();- if (!context.mounted) {+ await dialog?.hide();+ if (context == null || !context.mounted) {return;}// ignore: unawaited_futures- navigator.pushAndRemoveUntil(+ Navigator.of(context).pushAndRemoveUntil(MaterialPageRoute(builder: (BuildContext _) {return page;@@ -402,7 +408,7 @@ class UserService {}} catch (e) {_logger.severe(e);- await dialog.hide();+ await dialog?.hide();rethrow;}}@@ -458,6 +464,9 @@ class UserService {page = PasswordEntryPage(_config, PasswordEntryMode.set, _homePage);}}+ if (!context.mounted) {+ return;+ }// ignore: unawaited_futuresNavigator.of(context).pushAndRemoveUntil(MaterialPageRoute(@@ -474,6 +483,9 @@ class UserService {} on DioException catch (e) {_logger.info(e);await dialog.hide();+ if (!context.mounted) {+ return;+ }if (e.response != null && e.response!.statusCode == 410) {await showAlertBottomSheet(context,@@ -481,7 +493,9 @@ class UserService {message: context.strings.yourVerificationCodeHasExpired,assetPath: 'assets/warning-grey.png',);- Navigator.of(context).pop();+ if (context.mounted) {+ Navigator.of(context).pop();+ }} else {// ignore: unawaited_futuresshowAlertBottomSheet(@@ -494,13 +508,15 @@ class UserService {} catch (e) {await dialog.hide();_logger.severe(e);- // ignore: unawaited_futures- showAlertBottomSheet(- context,- title: context.strings.oops,- message: context.strings.verificationFailedPleaseTryAgain,- assetPath: 'assets/warning-grey.png',- );+ if (context.mounted) {+ // ignore: unawaited_futures+ showAlertBottomSheet(+ context,+ title: context.strings.oops,+ message: context.strings.verificationFailedPleaseTryAgain,+ assetPath: 'assets/warning-grey.png',+ );+ }}}@@ -523,10 +539,15 @@ class UserService {);await dialog.hide();if (response.statusCode == 200) {- showShortToast(context, context.strings.emailChangedTo(email));await setEmail(email);- Navigator.of(context).popUntil((route) => route.isFirst);Bus.instance.fire(UserDetailsChangedEvent());+ if (context.mounted) {+ showShortToast(context, context.strings.emailChangedTo(email));+ Navigator.of(context).popUntil((route) => route.isFirst);+ }+ return;+ }+ if (!context.mounted) {return;}// ignore: unawaited_futures@@ -537,6 +558,9 @@ class UserService {);} on DioException catch (e) {await dialog.hide();+ if (!context.mounted) {+ return;+ }if (e.response != null && e.response!.statusCode == 403) {// ignore: unawaited_futuresshowErrorDialog(@@ -555,12 +579,14 @@ class UserService {} catch (e) {await dialog.hide();_logger.severe(e);- // ignore: unawaited_futures- showErrorDialog(- context,- context.strings.oops,- context.strings.verificationFailedPleaseTryAgain,- );+ if (context.mounted) {+ // ignore: unawaited_futures+ showErrorDialog(+ context,+ context.strings.oops,+ context.strings.verificationFailedPleaseTryAgain,+ );+ }}}@@ -687,7 +713,7 @@ class UserService {}Future<void> verifyEmailViaPassword(- BuildContext context,+ BuildContext? context,SrpAttributes srpAttributes,String userPassword,ProgressDialog dialog,@@ -778,17 +804,19 @@ class UserService {}}await dialog.hide();- // ignore: unawaited_futures- Navigator.of(context).pushAndRemoveUntil(- MaterialPageRoute(- builder: (BuildContext context) {- return page!;- },- ),- identical(page, _homePage)- ? (route) => false- : (route) => route.isFirst,- );+ if (context != null && context.mounted) {+ // ignore: unawaited_futures+ Navigator.of(context).pushAndRemoveUntil(+ MaterialPageRoute(+ builder: (BuildContext context) {+ return page!;+ },+ ),+ identical(page, _homePage)+ ? (route) => false+ : (route) => route.isFirst,+ );+ }} else {// should never reach herethrow Exception("unexpected response during email verification");@@ -853,21 +881,26 @@ class UserService {);await dialog.hide();if (response.statusCode == 200) {- showShortToast(context, context.strings.authenticationSuccessful);await _saveConfiguration(response);- // ignore: unawaited_futures- Navigator.of(context).pushAndRemoveUntil(- MaterialPageRoute(- builder: (BuildContext context) {- return PasswordReentryPage(_config, _homePage);- },- ),- (route) => route.isFirst,- );+ if (context.mounted) {+ showShortToast(context, context.strings.authenticationSuccessful);+ // ignore: unawaited_futures+ Navigator.of(context).pushAndRemoveUntil(+ MaterialPageRoute(+ builder: (BuildContext context) {+ return PasswordReentryPage(_config, _homePage);+ },+ ),+ (route) => route.isFirst,+ );+ }}} on DioException catch (e) {await dialog.hide();_logger.severe(e);+ if (!context.mounted) {+ return;+ }if (e.response != null && e.response!.statusCode == 404) {showToast(context, "Session expired");// ignore: unawaited_futures@@ -891,13 +924,15 @@ class UserService {} catch (e) {await dialog.hide();_logger.severe(e);- // ignore: unawaited_futures- showAlertBottomSheet(- context,- title: context.strings.oops,- message: context.strings.authenticationFailedPleaseTryAgain,- assetPath: 'assets/warning-grey.png',- );+ if (context.mounted) {+ // ignore: unawaited_futures+ showAlertBottomSheet(+ context,+ title: context.strings.oops,+ message: context.strings.authenticationFailedPleaseTryAgain,+ assetPath: 'assets/warning-grey.png',+ );+ }}}@@ -918,24 +953,29 @@ class UserService {);await dialog.hide();if (response.statusCode == 200) {- // ignore: unawaited_futures- Navigator.of(context).pushAndRemoveUntil(- MaterialPageRoute(- builder: (BuildContext context) {- return TwoFactorRecoveryPage(- type,- sessionID,- response.data["encryptedSecret"],- response.data["secretDecryptionNonce"],- );- },- ),- (route) => route.isFirst,- );+ if (context.mounted) {+ // ignore: unawaited_futures+ Navigator.of(context).pushAndRemoveUntil(+ MaterialPageRoute(+ builder: (BuildContext context) {+ return TwoFactorRecoveryPage(+ type,+ sessionID,+ response.data["encryptedSecret"],+ response.data["secretDecryptionNonce"],+ );+ },+ ),+ (route) => route.isFirst,+ );+ }}} on DioException catch (e) {await dialog.hide();_logger.severe(e);+ if (!context.mounted) {+ return;+ }if (e.response != null && e.response!.statusCode == 404) {showToast(context, context.strings.sessionExpired);// ignore: unawaited_futures@@ -959,13 +999,15 @@ class UserService {} catch (e) {await dialog.hide();_logger.severe(e);- // ignore: unawaited_futures- showAlertBottomSheet(- context,- title: context.strings.oops,- message: context.strings.somethingWentWrongPleaseTryAgain,- assetPath: 'assets/warning-grey.png',- );+ if (context.mounted) {+ // ignore: unawaited_futures+ showAlertBottomSheet(+ context,+ title: context.strings.oops,+ message: context.strings.somethingWentWrongPleaseTryAgain,+ assetPath: 'assets/warning-grey.png',+ );+ }} finally {await dialog.hide();}@@ -1000,6 +1042,9 @@ class UserService {);} catch (e) {await dialog.hide();+ if (!context.mounted) {+ return;+ }await showAlertBottomSheet(context,title: context.strings.incorrectRecoveryKey,@@ -1019,24 +1064,29 @@ class UserService {);await dialog.hide();if (response.statusCode == 200) {- showShortToast(- context,- context.strings.twofactorAuthenticationSuccessfullyReset,- );await _saveConfiguration(response);- // ignore: unawaited_futures- Navigator.of(context).pushAndRemoveUntil(- MaterialPageRoute(- builder: (BuildContext context) {- return PasswordReentryPage(_config, _homePage);- },- ),- (route) => route.isFirst,- );+ if (context.mounted) {+ showShortToast(+ context,+ context.strings.twofactorAuthenticationSuccessfullyReset,+ );+ // ignore: unawaited_futures+ Navigator.of(context).pushAndRemoveUntil(+ MaterialPageRoute(+ builder: (BuildContext context) {+ return PasswordReentryPage(_config, _homePage);+ },+ ),+ (route) => route.isFirst,+ );+ }}} on DioException catch (e) {await dialog.hide();_logger.severe(e);+ if (!context.mounted) {+ return;+ }if (e.response != null && e.response!.statusCode == 404) {showToast(context, "Session expired");// ignore: unawaited_futures@@ -1060,13 +1110,15 @@ class UserService {} catch (e) {await dialog.hide();_logger.severe(e);- // ignore: unawaited_futures- showAlertBottomSheet(- context,- title: context.strings.oops,- message: context.strings.somethingWentWrongPleaseTryAgain,- assetPath: 'assets/warning-grey.png',- );+ if (context.mounted) {+ // ignore: unawaited_futures+ showAlertBottomSheet(+ context,+ title: context.strings.oops,+ message: context.strings.somethingWentWrongPleaseTryAgain,+ assetPath: 'assets/warning-grey.png',+ );+ }} finally {await dialog.hide();}diff --git a/mobile/packages/legacy/lib/pages/emergency_page.dart b/mobile/packages/legacy/lib/pages/emergency_page.dartindex f4ca237133..d0ad661c93 100644--- a/mobile/packages/legacy/lib/pages/emergency_page.dart+++ b/mobile/packages/legacy/lib/pages/emergency_page.dart@@ -598,6 +598,9 @@ class _EmergencyPageState extends State<EmergencyPage> {final result = await showTrustedContactSheet(context, contact: contact);if (result?.action == TrustedContactAction.revoke) {+ if (!context.mounted) {+ return;+ }final isPending = contact.isPendingInvite();final colorScheme = getEnteColorScheme(context);final confirmed = await showAlertBottomSheet<bool>(@@ -652,7 +655,7 @@ class _EmergencyPageState extends State<EmergencyPage> {setState(() {});}} else {- if (mounted) {+ if (context.mounted) {await showAlertBottomSheet(context,title: context.strings.cannotUpdateRecoveryTime,@@ -662,7 +665,7 @@ class _EmergencyPageState extends State<EmergencyPage> {}}} catch (e) {- if (mounted) {+ if (context.mounted) {showShortToast(context, context.strings.somethingWentWrong);}}diff --git a/mobile/packages/legacy/lib/pages/recover_others_account.dart b/mobile/packages/legacy/lib/pages/recover_others_account.dartindex a3190c927e..7e94ce86ea 100644--- a/mobile/packages/legacy/lib/pages/recover_others_account.dart+++ b/mobile/packages/legacy/lib/pages/recover_others_account.dart@@ -341,17 +341,21 @@ class _RecoverOthersAccountState extends State<RecoverOthersAccount> {widget.sessions,);await dialog.hide();- ScaffoldMessenger.of(context).showSnackBar(- SnackBar(- content: Text(context.strings.passwordChangedSuccessfully),- backgroundColor: Colors.green,- ),- );- Navigator.of(context).pop();+ if (mounted) {+ ScaffoldMessenger.of(context).showSnackBar(+ SnackBar(+ content: Text(context.strings.passwordChangedSuccessfully),+ backgroundColor: Colors.green,+ ),+ );+ Navigator.of(context).pop();+ }} catch (e, s) {_logger.severe("Failed to recover account", e, s);await dialog.hide();- await showGenericErrorDialog(context: context, error: e);+ if (mounted) {+ await showGenericErrorDialog(context: context, error: e);+ }}}diff --git a/mobile/packages/legacy/lib/pages/select_contact_page.dart b/mobile/packages/legacy/lib/pages/select_contact_page.dartindex dc88a1b4e2..199162099c 100644--- a/mobile/packages/legacy/lib/pages/select_contact_page.dart+++ b/mobile/packages/legacy/lib/pages/select_contact_page.dart@@ -337,7 +337,7 @@ class _AddContactSheetState extends State<AddContactSheet> {if (confirmed == true) {try {final success = await EmergencyContactService.instance.addContact(- context,+ mounted ? context : null,emailToAdd,_selectedRecoveryDays,);diff --git a/mobile/packages/legacy/lib/pages/share_legacy_kit_page.dart b/mobile/packages/legacy/lib/pages/share_legacy_kit_page.dartindex 86ac6e5fbf..c9a552badd 100644--- a/mobile/packages/legacy/lib/pages/share_legacy_kit_page.dart+++ b/mobile/packages/legacy/lib/pages/share_legacy_kit_page.dart@@ -401,6 +401,7 @@ class _ShareLegacyKitPageState extends State<ShareLegacyKitPage> {}Future<void> _editRecoveryWaitTime() async {+ final authReason = context.strings.authToManageLegacyKit;if (_kit.hasActiveRecoverySession) {await showAlertBottomSheet(context,@@ -417,7 +418,7 @@ class _ShareLegacyKitPageState extends State<ShareLegacyKitPage> {if (selectedDays == null || selectedDays * 24 == _kit.noticePeriodInHours) {return;}- if (!await _authenticate(context.strings.authToManageLegacyKit)) {+ if (!await _authenticate(authReason)) {return;}if (!mounted) {