From 7810c2a2796190f204c8b223035c26744314a864 Mon Sep 17 00:00:00 2001 From: Inex Code Date: Tue, 31 May 2022 17:30:35 +0300 Subject: [PATCH] Fix recovery flow --- .../server_installation_cubit.dart | 3 ++- .../server_installation_repository.dart | 3 ++- lib/ui/pages/recovery_key/recovery_key.dart | 2 +- lib/ui/pages/setup/recovering/recovery_routing.dart | 13 ++++++++++--- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/logic/cubit/server_installation/server_installation_cubit.dart b/lib/logic/cubit/server_installation/server_installation_cubit.dart index 20a89a52..18367eb0 100644 --- a/lib/logic/cubit/server_installation/server_installation_cubit.dart +++ b/lib/logic/cubit/server_installation/server_installation_cubit.dart @@ -461,6 +461,7 @@ class ServerInstallationCubit extends Cubit { await repository.saveHasFinalChecked(true); await repository.saveIsRecoveringServer(false); final mainUser = await repository.getMainUser(); + await repository.saveRootUser(mainUser); final updatedState = (state as ServerInstallationRecovery).copyWith( backblazeCredential: backblazeCredential, rootUser: mainUser, @@ -502,7 +503,7 @@ class ServerInstallationCubit extends Cubit { if (state.serverDetails != null) { await repository.deleteServer(state.serverDomain!); } - await repository.deleteRecords(); + await repository.deleteServerRelatedRecords(); emit(ServerInstallationNotFinished( hetznerKey: state.hetznerKey, serverDomain: state.serverDomain, diff --git a/lib/logic/cubit/server_installation/server_installation_repository.dart b/lib/logic/cubit/server_installation/server_installation_repository.dart index f009f6ed..3152c39a 100644 --- a/lib/logic/cubit/server_installation/server_installation_repository.dart +++ b/lib/logic/cubit/server_installation/server_installation_repository.dart @@ -628,7 +628,7 @@ class ServerInstallationRepository { await cloudFlare.removeSimilarRecords(cloudFlareDomain: serverDomain); } - Future deleteRecords() async { + Future deleteServerRelatedRecords() async { await box.deleteAll([ BNames.serverDetails, BNames.isServerStarted, @@ -636,6 +636,7 @@ class ServerInstallationRepository { BNames.isServerResetedSecondTime, BNames.hasFinalChecked, BNames.isLoading, + BNames.isRecoveringServer, ]); getIt().init(); } diff --git a/lib/ui/pages/recovery_key/recovery_key.dart b/lib/ui/pages/recovery_key/recovery_key.dart index 81a50067..d170603b 100644 --- a/lib/ui/pages/recovery_key/recovery_key.dart +++ b/lib/ui/pages/recovery_key/recovery_key.dart @@ -24,7 +24,7 @@ class RecoveryKey extends StatefulWidget { class _RecoveryKeyState extends State { @override Widget build(BuildContext context) { - var keyStatus = context.watch().state; + final keyStatus = context.watch().state; final List widgets; final String? subtitle = diff --git a/lib/ui/pages/setup/recovering/recovery_routing.dart b/lib/ui/pages/setup/recovering/recovery_routing.dart index b43ff7e7..191ee1e6 100644 --- a/lib/ui/pages/setup/recovering/recovery_routing.dart +++ b/lib/ui/pages/setup/recovering/recovery_routing.dart @@ -60,9 +60,16 @@ class RecoveryRouting extends StatelessWidget { } } - return AnimatedSwitcher( - duration: const Duration(milliseconds: 300), - child: currentPage, + return BlocListener( + listener: (context, state) { + if (state is ServerInstallationFinished) { + Navigator.of(context).popUntil((route) => route.isFirst); + } + }, + child: AnimatedSwitcher( + duration: const Duration(milliseconds: 300), + child: currentPage, + ), ); } }