diff --git a/lib/controllers/client.dart b/lib/controllers/client.dart index 3c16024..a044d25 100644 --- a/lib/controllers/client.dart +++ b/lib/controllers/client.dart @@ -200,14 +200,8 @@ class ClientController extends AsyncNotifier { Future setState(SetStateRequest request) async => await _sendCommand("set_state", request.toJson()); - Future verify(String recoveryKey) async { - try { - await _sendCommand("verify", {"recovery_key": recoveryKey}); - return null; - } catch (error) { - return error.toString(); - } - } + Future verify(String recoveryKey) => + _sendCommand("verify", {"recovery_key": recoveryKey}); Future generateRecoveryKey(String passphrase) async => .fromJson( await _sendCommand("generate_recovery_key", {"passphrase": passphrase}), diff --git a/lib/controllers/notification.dart b/lib/controllers/notification.dart index 47ecdf0..b251e26 100644 --- a/lib/controllers/notification.dart +++ b/lib/controllers/notification.dart @@ -169,7 +169,7 @@ class NotificationController if (Platform.isLinux) { final portal = await ref.read(PortalController.provider.future); - const escape = HtmlEscape(HtmlEscapeMode.element); + const escape = HtmlEscape(.element); await portal.notification.addNotification( id.toString(), diff --git a/lib/main.dart b/lib/main.dart index 8915339..66b253a 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -160,8 +160,8 @@ class const App({super.key}) extends StatelessWidget { MultiProviderController.provider( .new([ GomuksListenerController.provider, - NotificationController.provider, UnifiedPushController.provider, + NotificationController.provider, MemberListOpenedController.provider, KeyController.provider(KeyController.roomKey), KeyController.provider(KeyController.spaceKey), diff --git a/lib/widgets/pages/select_server.dart b/lib/widgets/pages/select_server.dart index 66c40a5..4a35a6c 100644 --- a/lib/widgets/pages/select_server.dart +++ b/lib/widgets/pages/select_server.dart @@ -60,6 +60,8 @@ class const SelectServerPage({super.key}) extends HookConsumerWidget { return; } + if (!context.mounted) return; + await ref.read(LaunchHelper.provider).launchUrl(codeResponse.url); AppLinks().uriLinkStream.listen((encodedUri) async { @@ -70,7 +72,7 @@ class const SelectServerPage({super.key}) extends HookConsumerWidget { try { final code = encodedUri.queryParameters["code"]; - if (code != null) { + if (code != null && context.mounted) { await ref .read(ClientController.provider.notifier) .exchangeToken( diff --git a/lib/widgets/pages/verify.dart b/lib/widgets/pages/verify.dart index 76bd94d..4858f8c 100644 --- a/lib/widgets/pages/verify.dart +++ b/lib/widgets/pages/verify.dart @@ -18,6 +18,7 @@ class const VerifyPage({super.key}) extends HookConsumerWidget { final isLoading = useState(false); final inputError = useState(null); final formKey = useRef(GlobalKey()); + final verificationState = ref.watch( ClientStateController.provider.select( (state) => state?.verificationState, @@ -25,18 +26,24 @@ class const VerifyPage({super.key}) extends HookConsumerWidget { ); Future verify() async { + if (isLoading.value) return; + + if (formKey.value.currentState?.validate() != true) { + return; + } + isLoading.value = true; try { - if (formKey.value.currentState?.validate() != true) { - return; - } - - inputError.value = await ref + await ref .read(ClientController.provider.notifier) .verify(passphraseController.text); + } catch (error) { + inputError.value = error.toString(); } finally { - isLoading.value = false; + if (context.mounted) { + isLoading.value = false; + } } } @@ -52,7 +59,8 @@ class const VerifyPage({super.key}) extends HookConsumerWidget { ), body: switch (verificationState) { null || VerificationState(stateChecked: false) => const Loading(), - // Nothing to verify with yet, so go straight to setting it up. + + // Nothing to verify yet, so go straight to setup. VerificationState(hasSecretStorage: false) => Dialog( insetPadding: const .symmetric(vertical: 12, horizontal: 32), child: ConstrainedBox( @@ -60,6 +68,7 @@ class const VerifyPage({super.key}) extends HookConsumerWidget { child: const ResetEncryptionSheet(isPage: true), ), ), + _ => AlertDialog( insetPadding: .symmetric(vertical: 12, horizontal: 32), scrollable: true, @@ -71,7 +80,9 @@ class const VerifyPage({super.key}) extends HookConsumerWidget { crossAxisAlignment: .start, children: [ Text( - "Enter your recovery key or passphrase below to unlock encrypted events.\nYour passphrase is usually not the same as your password.", + "Enter your recovery key or passphrase below to " + "unlock encrypted events.\nYour passphrase is usually " + "not the same as your password.", ), SizedBox(height: 12), TextFormField( @@ -94,9 +105,13 @@ class const VerifyPage({super.key}) extends HookConsumerWidget { ), actions: [ TextButton( - onPressed: () => context.showAdaptiveSheet( - (_) => const ResetEncryptionSheet(), - ), + onPressed: isLoading.value + ? null + : () { + context.showAdaptiveSheet( + (_) => const ResetEncryptionSheet(), + ); + }, style: TextButton.styleFrom( foregroundColor: Theme.of(context).colorScheme.error, ),