From 141fa419e44eecd2fddb18630cf107829a1048a2 Mon Sep 17 00:00:00 2001 From: Dain Nilsson Date: Fri, 10 Jun 2022 16:02:07 +0200 Subject: [PATCH 1/5] Pop dialogs by default when device changes. --- lib/about_page.dart | 10 ++++++---- lib/app/views/device_button.dart | 1 + lib/app/views/main_drawer.dart | 10 ++++++++-- lib/app/views/main_page.dart | 12 ++++++++++++ lib/fido/views/add_fingerprint_dialog.dart | 6 ------ lib/fido/views/delete_credential_dialog.dart | 5 ----- lib/fido/views/delete_fingerprint_dialog.dart | 5 ----- lib/fido/views/pin_dialog.dart | 5 ----- lib/fido/views/rename_fingerprint_dialog.dart | 5 ----- lib/fido/views/reset_dialog.dart | 6 ------ lib/management/views/management_screen.dart | 5 ----- lib/oath/views/add_account_page.dart | 6 ------ lib/oath/views/delete_account_dialog.dart | 5 ----- lib/oath/views/manage_password_dialog.dart | 5 ----- lib/oath/views/rename_account_dialog.dart | 5 ----- lib/oath/views/reset_dialog.dart | 5 ----- 16 files changed, 27 insertions(+), 69 deletions(-) diff --git a/lib/about_page.dart b/lib/about_page.dart index 8b2b47b6..d80d368c 100755 --- a/lib/about_page.dart +++ b/lib/about_page.dart @@ -77,10 +77,12 @@ class AboutPage extends ConsumerWidget { style: TextStyle(decoration: TextDecoration.underline), ), onPressed: () { - showLicensePage( - context: context, - applicationVersion: version, - ); + Navigator.of(context).push(MaterialPageRoute( + builder: (BuildContext context) => const LicensePage( + applicationVersion: version, + ), + settings: const RouteSettings(name: 'licenses'), + )); }, ), const Padding( diff --git a/lib/app/views/device_button.dart b/lib/app/views/device_button.dart index ad74e2a2..50dbbb40 100755 --- a/lib/app/views/device_button.dart +++ b/lib/app/views/device_button.dart @@ -48,6 +48,7 @@ class DeviceButton extends ConsumerWidget { showDialog( context: context, builder: (context) => const DevicePickerDialog(), + routeSettings: const RouteSettings(name: 'device_picker'), ); }, ), diff --git a/lib/app/views/main_drawer.dart b/lib/app/views/main_drawer.dart index c3d9f5ef..d16c12a4 100755 --- a/lib/app/views/main_drawer.dart +++ b/lib/app/views/main_drawer.dart @@ -93,7 +93,10 @@ class MainPageDrawer extends ConsumerWidget { final nav = Navigator.of(context); if (shouldPop) nav.pop(); showDialog( - context: context, builder: (context) => const SettingsPage()); + context: context, + builder: (context) => const SettingsPage(), + routeSettings: const RouteSettings(name: 'settings'), + ); }, ), DrawerItem( @@ -103,7 +106,10 @@ class MainPageDrawer extends ConsumerWidget { final nav = Navigator.of(context); if (shouldPop) nav.pop(); showDialog( - context: context, builder: (context) => const AboutPage()); + context: context, + builder: (context) => const AboutPage(), + routeSettings: const RouteSettings(name: 'about'), + ); }, ), ], diff --git a/lib/app/views/main_page.dart b/lib/app/views/main_page.dart index dcf9f837..885ad718 100755 --- a/lib/app/views/main_page.dart +++ b/lib/app/views/main_page.dart @@ -20,6 +20,18 @@ class MainPage extends ConsumerWidget { next?.call(context); }, ); + // If the current device changes, we need to pop any open dialogs. + ref.listen(currentDeviceProvider, (_, __) { + Navigator.of(context).popUntil((route) { + return route.isFirst || + [ + 'device_picker', + 'settings', + 'about', + 'licenses', + ].contains(route.settings.name); + }); + }); final deviceData = ref.watch(currentDeviceDataProvider); if (deviceData == null) { final node = ref.watch(currentDeviceProvider); diff --git a/lib/fido/views/add_fingerprint_dialog.dart b/lib/fido/views/add_fingerprint_dialog.dart index 70e6f418..78c50030 100755 --- a/lib/fido/views/add_fingerprint_dialog.dart +++ b/lib/fido/views/add_fingerprint_dialog.dart @@ -119,12 +119,6 @@ class _AddFingerprintDialogState extends ConsumerState @override Widget build(BuildContext context) { - // If current device changes, we need to pop back to the main Page. - ref.listen(currentDeviceProvider, (previous, next) { - // Prevent over-popping if reset causes currentDevice to change. - Navigator.of(context).popUntil((route) => route.isFirst); - }); - final progress = _samples == 0 ? 0.0 : _samples / (_samples + _remaining); return ResponsiveDialog( diff --git a/lib/fido/views/delete_credential_dialog.dart b/lib/fido/views/delete_credential_dialog.dart index 873b8c39..53835a90 100755 --- a/lib/fido/views/delete_credential_dialog.dart +++ b/lib/fido/views/delete_credential_dialog.dart @@ -17,11 +17,6 @@ class DeleteCredentialDialog extends ConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { - // If current device changes, we need to pop back to the main Page. - ref.listen(currentDeviceProvider, (previous, next) { - Navigator.of(context).pop(false); - }); - final label = credential.userName; return ResponsiveDialog( diff --git a/lib/fido/views/delete_fingerprint_dialog.dart b/lib/fido/views/delete_fingerprint_dialog.dart index 624538af..f0a04232 100755 --- a/lib/fido/views/delete_fingerprint_dialog.dart +++ b/lib/fido/views/delete_fingerprint_dialog.dart @@ -15,11 +15,6 @@ class DeleteFingerprintDialog extends ConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { - // If current device changes, we need to pop back to the main Page. - ref.listen(currentDeviceProvider, (previous, next) { - Navigator.of(context).pop(false); - }); - final label = fingerprint.label; return ResponsiveDialog( diff --git a/lib/fido/views/pin_dialog.dart b/lib/fido/views/pin_dialog.dart index 08d11a02..989a4c5b 100755 --- a/lib/fido/views/pin_dialog.dart +++ b/lib/fido/views/pin_dialog.dart @@ -28,11 +28,6 @@ class _FidoPinDialogState extends ConsumerState { @override Widget build(BuildContext context) { - // If current device changes, we need to pop back to the main Page. - ref.listen(currentDeviceProvider, (previous, next) { - Navigator.of(context).pop(); - }); - final hasPin = widget.state.hasPin; final isValid = _newPin.isNotEmpty && _newPin == _confirmPin && diff --git a/lib/fido/views/rename_fingerprint_dialog.dart b/lib/fido/views/rename_fingerprint_dialog.dart index e5c43ac7..f2ca438b 100755 --- a/lib/fido/views/rename_fingerprint_dialog.dart +++ b/lib/fido/views/rename_fingerprint_dialog.dart @@ -39,11 +39,6 @@ class _RenameAccountDialogState extends ConsumerState { @override Widget build(BuildContext context) { - // If current device changes, we need to pop back to the main Page. - ref.listen(currentDeviceProvider, (previous, next) { - Navigator.of(context).pop(); - }); - return ResponsiveDialog( title: const Text('Rename fingerprint'), actions: [ diff --git a/lib/fido/views/reset_dialog.dart b/lib/fido/views/reset_dialog.dart index f86b207d..7c93c376 100755 --- a/lib/fido/views/reset_dialog.dart +++ b/lib/fido/views/reset_dialog.dart @@ -47,12 +47,6 @@ class _ResetDialogState extends ConsumerState { @override Widget build(BuildContext context) { - // If current device changes, we need to pop back to the main Page. - ref.listen(currentDeviceProvider, (previous, next) { - // Prevent over-popping if reset causes currentDevice to change. - Navigator.of(context).popUntil((route) => route.isFirst); - }); - return ResponsiveDialog( title: const Text('Factory reset'), onCancel: () { diff --git a/lib/management/views/management_screen.dart b/lib/management/views/management_screen.dart index 126bd516..31a94d75 100755 --- a/lib/management/views/management_screen.dart +++ b/lib/management/views/management_screen.dart @@ -232,11 +232,6 @@ class _ManagementScreenState extends ConsumerState { @override Widget build(BuildContext context) { - ref.listen(currentDeviceProvider, (_, __) { - //TODO: This can probably be checked better to make sure it's the main page. - Navigator.of(context).popUntil((route) => route.isFirst); - }); - var canSave = false; final child = ref.watch(managementStateProvider(widget.deviceData.node.path)).when( diff --git a/lib/oath/views/add_account_page.dart b/lib/oath/views/add_account_page.dart index c9504b9b..11dc864d 100755 --- a/lib/oath/views/add_account_page.dart +++ b/lib/oath/views/add_account_page.dart @@ -96,12 +96,6 @@ class _OathAddAccountPageState extends ConsumerState { @override Widget build(BuildContext context) { - // If current device changes, we need to pop back to the main Page. - ref.listen(currentDeviceProvider, (previous, next) { - //TODO: This can probably be checked better to make sure it's the main page. - Navigator.of(context).popUntil((route) => route.isFirst); - }); - final period = int.tryParse(_periodController.text) ?? -1; final remaining = getRemainingKeySpace( oathType: _oathType, diff --git a/lib/oath/views/delete_account_dialog.dart b/lib/oath/views/delete_account_dialog.dart index a2dcff13..2b565c55 100755 --- a/lib/oath/views/delete_account_dialog.dart +++ b/lib/oath/views/delete_account_dialog.dart @@ -15,11 +15,6 @@ class DeleteAccountDialog extends ConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { - // If current device changes, we need to pop back to the main Page. - ref.listen(currentDeviceProvider, (previous, next) { - Navigator.of(context).pop(false); - }); - final label = credential.issuer != null ? '${credential.issuer} (${credential.name})' : credential.name; diff --git a/lib/oath/views/manage_password_dialog.dart b/lib/oath/views/manage_password_dialog.dart index 9074917a..5c3b3748 100755 --- a/lib/oath/views/manage_password_dialog.dart +++ b/lib/oath/views/manage_password_dialog.dart @@ -41,11 +41,6 @@ class _ManagePasswordDialogState extends ConsumerState { @override Widget build(BuildContext context) { - // If current device changes, we need to pop back to the main Page. - ref.listen(currentDeviceProvider, (previous, next) { - Navigator.of(context).pop(); - }); - final isValid = _newPassword.isNotEmpty && _newPassword == _confirmPassword && (!widget.state.hasKey || _currentPassword.isNotEmpty); diff --git a/lib/oath/views/rename_account_dialog.dart b/lib/oath/views/rename_account_dialog.dart index 2697e792..bae85e8e 100755 --- a/lib/oath/views/rename_account_dialog.dart +++ b/lib/oath/views/rename_account_dialog.dart @@ -32,11 +32,6 @@ class _RenameAccountDialogState extends ConsumerState { @override Widget build(BuildContext context) { - // If current device changes, we need to pop back to the main Page. - ref.listen(currentDeviceProvider, (previous, next) { - Navigator.of(context).pop(); - }); - final credential = widget.credential; final label = credential.issuer != null diff --git a/lib/oath/views/reset_dialog.dart b/lib/oath/views/reset_dialog.dart index 8b5030ed..874d58e4 100755 --- a/lib/oath/views/reset_dialog.dart +++ b/lib/oath/views/reset_dialog.dart @@ -13,11 +13,6 @@ class ResetDialog extends ConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { - // If current device changes, we need to pop back to the main Page. - ref.listen(currentDeviceProvider, (previous, next) { - Navigator.of(context).pop(); - }); - return ResponsiveDialog( title: const Text('Factory reset'), actions: [ From e34dbece2de1c52193036a2de7bf2f901edd02da Mon Sep 17 00:00:00 2001 From: Dain Nilsson Date: Fri, 10 Jun 2022 16:02:29 +0200 Subject: [PATCH 2/5] Fix red screen of death for OATH code dialog when device removed. --- lib/oath/views/account_dialog.dart | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/oath/views/account_dialog.dart b/lib/oath/views/account_dialog.dart index bc000e3e..de359218 100755 --- a/lib/oath/views/account_dialog.dart +++ b/lib/oath/views/account_dialog.dart @@ -93,6 +93,13 @@ class AccountDialog extends ConsumerWidget with AccountMixin { @override Widget build(BuildContext context, WidgetRef ref) { + // TODO: Solve this in a cleaner way + if (ref.watch(currentDeviceProvider) == null) { + // The rest of this method assumes there is a device, and will throw an exception if not. + // This will never be shown, as the dialog will be immediately closed + return const SizedBox(); + } + final code = getCode(ref); if (code == null) { if (isDesktop) { From 60ee8c2f1ed96ec04fade899c5c274ea930d2be1 Mon Sep 17 00:00:00 2001 From: Dain Nilsson Date: Fri, 10 Jun 2022 16:08:23 +0200 Subject: [PATCH 3/5] Remove unused imports. --- lib/fido/views/add_fingerprint_dialog.dart | 1 - lib/fido/views/pin_dialog.dart | 1 - lib/fido/views/rename_fingerprint_dialog.dart | 1 - lib/fido/views/reset_dialog.dart | 1 - lib/management/views/management_screen.dart | 1 - lib/oath/views/manage_password_dialog.dart | 1 - lib/oath/views/rename_account_dialog.dart | 1 - 7 files changed, 7 deletions(-) diff --git a/lib/fido/views/add_fingerprint_dialog.dart b/lib/fido/views/add_fingerprint_dialog.dart index 78c50030..4d7a8288 100755 --- a/lib/fido/views/add_fingerprint_dialog.dart +++ b/lib/fido/views/add_fingerprint_dialog.dart @@ -12,7 +12,6 @@ import '../../widgets/responsive_dialog.dart'; import '../state.dart'; import '../../fido/models.dart'; import '../../app/models.dart'; -import '../../app/state.dart'; final _log = Logger('fido.views.add_fingerprint_dialog'); diff --git a/lib/fido/views/pin_dialog.dart b/lib/fido/views/pin_dialog.dart index 989a4c5b..96cc2b43 100755 --- a/lib/fido/views/pin_dialog.dart +++ b/lib/fido/views/pin_dialog.dart @@ -3,7 +3,6 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../../app/message.dart'; import '../../app/models.dart'; -import '../../app/state.dart'; import '../../widgets/responsive_dialog.dart'; import '../models.dart'; import '../state.dart'; diff --git a/lib/fido/views/rename_fingerprint_dialog.dart b/lib/fido/views/rename_fingerprint_dialog.dart index f2ca438b..81e9a098 100755 --- a/lib/fido/views/rename_fingerprint_dialog.dart +++ b/lib/fido/views/rename_fingerprint_dialog.dart @@ -6,7 +6,6 @@ import '../../widgets/responsive_dialog.dart'; import '../models.dart'; import '../state.dart'; import '../../app/models.dart'; -import '../../app/state.dart'; class RenameFingerprintDialog extends ConsumerStatefulWidget { final DevicePath devicePath; diff --git a/lib/fido/views/reset_dialog.dart b/lib/fido/views/reset_dialog.dart index 7c93c376..bb5942d9 100755 --- a/lib/fido/views/reset_dialog.dart +++ b/lib/fido/views/reset_dialog.dart @@ -11,7 +11,6 @@ import '../../widgets/responsive_dialog.dart'; import '../state.dart'; import '../../fido/models.dart'; import '../../app/models.dart'; -import '../../app/state.dart'; final _log = Logger('fido.views.reset_dialog'); diff --git a/lib/management/views/management_screen.dart b/lib/management/views/management_screen.dart index 31a94d75..f8f80349 100755 --- a/lib/management/views/management_screen.dart +++ b/lib/management/views/management_screen.dart @@ -4,7 +4,6 @@ import 'package:collection/collection.dart'; import '../../app/message.dart'; import '../../app/models.dart'; -import '../../app/state.dart'; import '../../app/views/app_loading_screen.dart'; import '../../core/models.dart'; import '../../widgets/custom_icons.dart'; diff --git a/lib/oath/views/manage_password_dialog.dart b/lib/oath/views/manage_password_dialog.dart index 5c3b3748..ce25ffb3 100755 --- a/lib/oath/views/manage_password_dialog.dart +++ b/lib/oath/views/manage_password_dialog.dart @@ -3,7 +3,6 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../../app/message.dart'; import '../../app/models.dart'; -import '../../app/state.dart'; import '../../widgets/responsive_dialog.dart'; import '../models.dart'; import '../state.dart'; diff --git a/lib/oath/views/rename_account_dialog.dart b/lib/oath/views/rename_account_dialog.dart index bae85e8e..3ccb5de0 100755 --- a/lib/oath/views/rename_account_dialog.dart +++ b/lib/oath/views/rename_account_dialog.dart @@ -6,7 +6,6 @@ import '../../widgets/responsive_dialog.dart'; import '../models.dart'; import '../state.dart'; import '../../app/models.dart'; -import '../../app/state.dart'; import 'utils.dart'; class RenameAccountDialog extends ConsumerStatefulWidget { From c091bb5c18cbfe66010b926eab71b9c40443560c Mon Sep 17 00:00:00 2001 From: Dain Nilsson Date: Fri, 10 Jun 2022 16:24:33 +0200 Subject: [PATCH 4/5] Listen for cahnges to data instead of node to handle NFC correctly. --- lib/app/views/main_page.dart | 2 +- lib/oath/views/account_dialog.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/app/views/main_page.dart b/lib/app/views/main_page.dart index 885ad718..36f87eea 100755 --- a/lib/app/views/main_page.dart +++ b/lib/app/views/main_page.dart @@ -21,7 +21,7 @@ class MainPage extends ConsumerWidget { }, ); // If the current device changes, we need to pop any open dialogs. - ref.listen(currentDeviceProvider, (_, __) { + ref.listen(currentDeviceDataProvider, (_, __) { Navigator.of(context).popUntil((route) { return route.isFirst || [ diff --git a/lib/oath/views/account_dialog.dart b/lib/oath/views/account_dialog.dart index de359218..ce4974c2 100755 --- a/lib/oath/views/account_dialog.dart +++ b/lib/oath/views/account_dialog.dart @@ -94,7 +94,7 @@ class AccountDialog extends ConsumerWidget with AccountMixin { @override Widget build(BuildContext context, WidgetRef ref) { // TODO: Solve this in a cleaner way - if (ref.watch(currentDeviceProvider) == null) { + if (ref.watch(currentDeviceDataProvider) == null) { // The rest of this method assumes there is a device, and will throw an exception if not. // This will never be shown, as the dialog will be immediately closed return const SizedBox(); From 7a59db7d639c6f391adb82055a8d8373b38eaee5 Mon Sep 17 00:00:00 2001 From: Rikard Braathen Date: Mon, 13 Jun 2022 08:16:09 +0200 Subject: [PATCH 5/5] fix for obscure password on submit --- lib/oath/views/add_account_page.dart | 2 +- lib/oath/views/oath_screen.dart | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/oath/views/add_account_page.dart b/lib/oath/views/add_account_page.dart index c9504b9b..80650039 100755 --- a/lib/oath/views/add_account_page.dart +++ b/lib/oath/views/add_account_page.dart @@ -203,7 +203,7 @@ class _OathAddAccountPageState extends ConsumerState { border: OutlineInputBorder(), labelText: 'Account name', helperText: '', // Prevents dialog resizing when enabled = false - prefixIcon: Icon(Icons.people_alt_outlined), + prefixIcon: Icon(Icons.person_outline), ), onChanged: (value) { setState(() { diff --git a/lib/oath/views/oath_screen.dart b/lib/oath/views/oath_screen.dart index 43a3b525..0be28141 100755 --- a/lib/oath/views/oath_screen.dart +++ b/lib/oath/views/oath_screen.dart @@ -257,7 +257,6 @@ class _UnlockFormState extends ConsumerState<_UnlockForm> { void _submit() async { setState(() { _passwordIsWrong = false; - _isObscure = false; }); final result = await ref .read(oathStateProvider(widget._devicePath).notifier)