From 8dd74d7e8a275db6b446b732f0654248851a53ba Mon Sep 17 00:00:00 2001 From: ggurdin <46800240+ggurdin@users.noreply.github.com> Date: Tue, 4 Feb 2025 13:34:07 -0500 Subject: [PATCH] feat: use onInitStateChanged in login function to redirect to chat view quicker (#1696) --- lib/pages/login/login.dart | 36 ++++++++++------- .../user/controllers/user_controller.dart | 4 +- lib/widgets/future_loading_dialog.dart | 39 ++++++++++++------- 3 files changed, 50 insertions(+), 29 deletions(-) diff --git a/lib/pages/login/login.dart b/lib/pages/login/login.dart index 20c516108..d4f2c90a3 100644 --- a/lib/pages/login/login.dart +++ b/lib/pages/login/login.dart @@ -3,6 +3,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; +import 'package:go_router/go_router.dart'; import 'package:matrix/matrix.dart'; import 'package:fluffychat/pangea/common/constants/local.key.dart'; @@ -176,20 +177,27 @@ class LoginController extends State { // #Pangea // await matrix.getLoginClient().login( final loginRes = await matrix.getLoginClient().login( - // Pangea# - LoginType.mLoginPassword, - identifier: identifier, - // To stay compatible with older server versions - // ignore: deprecated_member_use - user: identifier.type == AuthenticationIdentifierTypes.userId - ? username - : null, - // #Pangea - // password: passwordController.text, - password: passwordController.text.trim(), - // Pangea# - initialDeviceDisplayName: PlatformInfos.clientName, - ); + // Pangea# + LoginType.mLoginPassword, + identifier: identifier, + // To stay compatible with older server versions + // ignore: deprecated_member_use + user: identifier.type == AuthenticationIdentifierTypes.userId + ? username + : null, + // #Pangea + // password: passwordController.text, + password: passwordController.text.trim(), + // Pangea# + initialDeviceDisplayName: PlatformInfos.clientName, + // #Pangea + onInitStateChanged: (state) { + if (state == InitState.settingUpEncryption) { + context.go("/rooms"); + } + }, + // Pangea# + ); MatrixState.pangeaController.pStoreService .save(PLocalKey.loginType, 'password'); // #Pangea diff --git a/lib/pangea/user/controllers/user_controller.dart b/lib/pangea/user/controllers/user_controller.dart index 269573751..d2d4dbebd 100644 --- a/lib/pangea/user/controllers/user_controller.dart +++ b/lib/pangea/user/controllers/user_controller.dart @@ -123,7 +123,9 @@ class UserController extends BaseController { data: {}, ); } finally { - _profileCompleter!.complete(); + if (!_profileCompleter!.isCompleted) { + _profileCompleter!.complete(); + } } return _profileCompleter!.future; diff --git a/lib/widgets/future_loading_dialog.dart b/lib/widgets/future_loading_dialog.dart index 61a137c25..bbc7247b2 100644 --- a/lib/widgets/future_loading_dialog.dart +++ b/lib/widgets/future_loading_dialog.dart @@ -37,21 +37,32 @@ Future> showFutureLoadingDialog({ } } - final result = await showAdaptiveDialog>( - context: context, - barrierDismissible: barrierDismissible, - builder: (BuildContext context) => LoadingDialog( - future: futureExec, - title: title, - backLabel: backLabel, - exceptionContext: exceptionContext, - ), + // #Pangea + if (context.mounted) { + // Pangea# + final result = await showAdaptiveDialog>( + context: context, + barrierDismissible: barrierDismissible, + builder: (BuildContext context) => LoadingDialog( + future: futureExec, + title: title, + backLabel: backLabel, + exceptionContext: exceptionContext, + ), + ); + return result ?? + Result.error( + Exception('FutureDialog canceled'), + StackTrace.current, + ); + } + + // #Pangea + return Result.error( + Exception('FutureDialog canceled'), + StackTrace.current, ); - return result ?? - Result.error( - Exception('FutureDialog canceled'), - StackTrace.current, - ); + // Pangea# } class LoadingDialog extends StatefulWidget {