diff --git a/lib/config/routes.dart b/lib/config/routes.dart index 231f7872a..9871a013f 100644 --- a/lib/config/routes.dart +++ b/lib/config/routes.dart @@ -44,13 +44,17 @@ abstract class AppRoutes { BuildContext context, GoRouterState state, ) => - Matrix.of(context).client.isLogged() ? '/rooms' : null; + Matrix.of(context).widget.clients.any((client) => client.isLogged()) + ? '/rooms' + : null; static FutureOr loggedOutRedirect( BuildContext context, GoRouterState state, ) => - Matrix.of(context).client.isLogged() ? null : '/home'; + Matrix.of(context).widget.clients.any((client) => client.isLogged()) + ? null + : '/home'; AppRoutes(); @@ -58,7 +62,9 @@ abstract class AppRoutes { GoRoute( path: '/', redirect: (context, state) => - Matrix.of(context).client.isLogged() ? '/rooms' : '/home', + Matrix.of(context).widget.clients.any((client) => client.isLogged()) + ? '/rooms' + : '/home', ), GoRoute( path: '/home', diff --git a/lib/pages/homeserver_picker/homeserver_picker_view.dart b/lib/pages/homeserver_picker/homeserver_picker_view.dart index c1878b8a4..4161f1f9a 100644 --- a/lib/pages/homeserver_picker/homeserver_picker_view.dart +++ b/lib/pages/homeserver_picker/homeserver_picker_view.dart @@ -25,7 +25,8 @@ class HomeserverPickerView extends StatelessWidget { final theme = Theme.of(context); return LoginScaffold( - enforceMobileMode: Matrix.of(context).client.isLogged(), + enforceMobileMode: + Matrix.of(context).widget.clients.any((client) => client.isLogged()), appBar: AppBar( centerTitle: true, title: Text( diff --git a/lib/pages/login/login.dart b/lib/pages/login/login.dart index 5ac743eb8..8dee4ba38 100644 --- a/lib/pages/login/login.dart +++ b/lib/pages/login/login.dart @@ -70,7 +70,7 @@ class LoginController extends State { identifier = AuthenticationUserIdentifier(user: username); } final client = await matrix.getLoginClient(); - client.login( + await client.login( LoginType.mLoginPassword, identifier: identifier, // To stay compatible with older server versions diff --git a/lib/pages/login/login_view.dart b/lib/pages/login/login_view.dart index 71129bd6b..a82b5054f 100644 --- a/lib/pages/login/login_view.dart +++ b/lib/pages/login/login_view.dart @@ -21,7 +21,8 @@ class LoginView extends StatelessWidget { final titleParts = title.split(homeserver); return LoginScaffold( - enforceMobileMode: Matrix.of(context).client.isLogged(), + enforceMobileMode: + Matrix.of(context).widget.clients.any((client) => client.isLogged()), appBar: AppBar( leading: controller.loading ? null : const Center(child: BackButton()), automaticallyImplyLeading: !controller.loading, diff --git a/lib/widgets/matrix.dart b/lib/widgets/matrix.dart index 54b26aee3..1115e8756 100644 --- a/lib/widgets/matrix.dart +++ b/lib/widgets/matrix.dart @@ -174,6 +174,7 @@ class MatrixState extends State with WidgetsBindingObserver { _loginClientCandidate = null; FluffyChatApp.router.go('/rooms'); }); + if (widget.clients.isEmpty) widget.clients.add(candidate); return candidate; } @@ -282,12 +283,12 @@ class MatrixState extends State with WidgetsBindingObserver { onLoginStateChanged[name] ??= c.onLoginStateChanged.stream.listen((state) { final loggedInWithMultipleClients = widget.clients.length > 1; if (state == LoginState.loggedOut) { - InitWithRestoreExtension.deleteSessionBackup(name); - } - if (loggedInWithMultipleClients && state != LoginState.loggedIn) { _cancelSubs(c.clientName); widget.clients.remove(c); ClientManager.removeClientNameFromStore(c.clientName, store); + InitWithRestoreExtension.deleteSessionBackup(name); + } + if (loggedInWithMultipleClients && state != LoginState.loggedIn) { ScaffoldMessenger.of( FluffyChatApp.router.routerDelegate.navigatorKey.currentContext ?? context, @@ -379,12 +380,14 @@ class MatrixState extends State with WidgetsBindingObserver { Logs().v('AppLifecycleState = $state'); final foreground = state != AppLifecycleState.inactive && state != AppLifecycleState.paused; - client.syncPresence = - state == AppLifecycleState.resumed ? null : PresenceType.unavailable; - if (PlatformInfos.isMobile) { - client.backgroundSync = foreground; - client.requestHistoryOnLimitedTimeline = !foreground; - Logs().v('Set background sync to', foreground); + for (final client in widget.clients) { + client.syncPresence = + state == AppLifecycleState.resumed ? null : PresenceType.unavailable; + if (PlatformInfos.isMobile) { + client.backgroundSync = foreground; + client.requestHistoryOnLimitedTimeline = !foreground; + Logs().v('Set background sync to', foreground); + } } }