diff --git a/lib/pages/chat_list/chat_list.dart b/lib/pages/chat_list/chat_list.dart index 27db1d7d..0b9e082f 100644 --- a/lib/pages/chat_list/chat_list.dart +++ b/lib/pages/chat_list/chat_list.dart @@ -211,19 +211,6 @@ class ChatListController extends State } final selectedRoomIds = {}; - bool? crossSigningCached; - bool showChatBackupBanner = false; - - void firstRunBootstrapAction() async { - setState(() { - showChatBackupBanner = false; - }); - - await BootstrapDialog( - client: Matrix.of(context).client, - ).show(context); - VRouter.of(context).to('/rooms'); - } String? get activeChat => VRouter.of(context).pathParameters['roomid']; @@ -314,24 +301,6 @@ class ChatListController extends State super.initState(); } - void checkBootstrap() async { - if (!Matrix.of(context).client.encryptionEnabled) return; - await Matrix.of(context).client.accountDataLoading; - await Matrix.of(context).client.userDeviceKeysLoading; - final crossSigning = - await Matrix.of(context).client.encryption?.crossSigning.isCached() ?? - false; - final needsBootstrap = - Matrix.of(context).client.encryption?.crossSigning.enabled == false || - crossSigning == false; - final isUnknownSession = Matrix.of(context).client.isUnknownSession; - if (needsBootstrap || isUnknownSession) { - setState(() { - showChatBackupBanner = true; - }); - } - } - @override void dispose() { _intentDataStreamSubscription?.cancel(); @@ -538,7 +507,17 @@ class ChatListController extends State await client.accountDataLoading; if (client.prevBatch == null) { await client.onSync.stream.first; + + // Display first login bootstrap if enabled + if (client.encryption?.keyManager.enabled == true) { + if (await client.encryption?.keyManager.isCached() == false || + await client.encryption?.crossSigning.isCached() == false || + client.isUnknownSession) { + await BootstrapDialog(client: client).show(context); + } + } } + // Load space members to display DM rooms final spaceId = activeSpaceId; if (spaceId != null) { @@ -553,7 +532,6 @@ class ChatListController extends State setState(() { waitForFirstSync = true; }); - WidgetsBinding.instance.addPostFrameCallback((_) => checkBootstrap()); return; } diff --git a/lib/pages/chat_list/chat_list_body.dart b/lib/pages/chat_list/chat_list_body.dart index 2dcd5da2..26fa86db 100644 --- a/lib/pages/chat_list/chat_list_body.dart +++ b/lib/pages/chat_list/chat_list_body.dart @@ -146,44 +146,6 @@ class _ChatListViewBodyState extends State { StoriesHeader( filter: widget.controller.searchController.text, ), - AnimatedContainer( - height: !widget.controller.isSearchMode && - widget.controller.showChatBackupBanner - ? 54 - : 0, - duration: const Duration(milliseconds: 300), - clipBehavior: Clip.hardEdge, - curve: Curves.bounceInOut, - decoration: const BoxDecoration(), - child: Material( - color: Theme.of(context).colorScheme.surface, - child: ListTile( - leading: CircleAvatar( - radius: Avatar.defaultSize / 2, - backgroundColor: - Theme.of(context).colorScheme.surfaceVariant, - foregroundColor: - Theme.of(context).colorScheme.onSurfaceVariant, - child: const Icon(Icons.enhanced_encryption_outlined), - ), - title: Text( - (Matrix.of(context) - .client - .encryption - ?.keyManager - .enabled == - true) - ? L10n.of(context)!.unlockOldMessages - : L10n.of(context)!.enableAutoBackups, - style: TextStyle( - color: Theme.of(context).colorScheme.onSurface, - ), - ), - trailing: const Icon(Icons.chevron_right_outlined), - onTap: widget.controller.firstRunBootstrapAction, - ), - ), - ), AnimatedContainer( height: widget.controller.isTorBrowser ? 64 : 0, duration: const Duration(milliseconds: 300), diff --git a/lib/pages/settings/settings.dart b/lib/pages/settings/settings.dart index 098756d4..ddeea37a 100644 --- a/lib/pages/settings/settings.dart +++ b/lib/pages/settings/settings.dart @@ -11,6 +11,7 @@ import 'package:matrix/matrix.dart'; import 'package:fluffychat/utils/platform_infos.dart'; import '../../widgets/matrix.dart'; +import '../bootstrap/bootstrap_dialog.dart'; import 'settings_view.dart'; class Settings extends StatefulWidget { @@ -21,10 +22,6 @@ class Settings extends StatefulWidget { } class SettingsController extends State { - Future? crossSigningCachedFuture; - bool? crossSigningCached; - Future? megolmBackupCachedFuture; - bool? megolmBackupCached; Future? profileFuture; Profile? profile; bool profileUpdated = false; @@ -106,6 +103,43 @@ class SettingsController extends State { } } + @override + void initState() { + WidgetsBinding.instance.addPostFrameCallback((_) => checkBootstrap()); + + super.initState(); + } + + void checkBootstrap() async { + final client = Matrix.of(context).client; + if (!client.encryptionEnabled) return; + await client.accountDataLoading; + await client.userDeviceKeysLoading; + if (client.prevBatch == null) { + await client.onSync.stream.first; + } + final crossSigning = + await client.encryption?.crossSigning.isCached() ?? false; + final needsBootstrap = + await client.encryption?.keyManager.isCached() == false || + client.encryption?.crossSigning.enabled == false || + crossSigning == false; + final isUnknownSession = client.isUnknownSession; + setState(() { + showChatBackupBanner = needsBootstrap || isUnknownSession; + }); + } + + bool? crossSigningCached; + bool showChatBackupBanner = false; + + void firstRunBootstrapAction() async { + await BootstrapDialog( + client: Matrix.of(context).client, + ).show(context); + checkBootstrap(); + } + @override Widget build(BuildContext context) { final client = Matrix.of(context).client; @@ -119,18 +153,6 @@ class SettingsController extends State { if (mounted) setState(() => profile = p); return p; }); - if (client.encryption != null) { - crossSigningCachedFuture ??= - client.encryption?.crossSigning.isCached().then((c) { - if (mounted) setState(() => crossSigningCached = c); - return c; - }); - megolmBackupCachedFuture ??= - client.encryption?.keyManager.isCached().then((c) { - if (mounted) setState(() => megolmBackupCached = c); - return c; - }); - } return SettingsView(this); } } diff --git a/lib/pages/settings/settings_view.dart b/lib/pages/settings/settings_view.dart index e3abe277..6ca7d681 100644 --- a/lib/pages/settings/settings_view.dart +++ b/lib/pages/settings/settings_view.dart @@ -39,6 +39,23 @@ class SettingsView extends StatelessWidget { iconColor: Theme.of(context).colorScheme.onBackground, child: ListView( children: [ + AnimatedContainer( + height: controller.showChatBackupBanner ? 54 : 0, + duration: const Duration(milliseconds: 300), + clipBehavior: Clip.hardEdge, + curve: Curves.bounceInOut, + decoration: const BoxDecoration(), + child: ListTile( + leading: const Icon(Icons.backup_outlined), + title: Text(L10n.of(context)!.enableAutoBackups), + trailing: const Icon( + Icons.warning_outlined, + color: Colors.orange, + ), + onTap: controller.firstRunBootstrapAction, + ), + ), + const Divider(thickness: 1), ListTile( leading: const Icon(Icons.format_paint_outlined), title: Text(L10n.of(context)!.changeTheme),