Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Improve UX when adding account on devices without NFC #1692

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions lib/android/oath/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import '../../exception/platform_exception_decoder.dart';
import '../../oath/models.dart';
import '../../oath/state.dart';
import '../../widgets/toast.dart';
import '../app_methods.dart';
import '../overlay/nfc/method_channel_notifier.dart';
import '../overlay/nfc/nfc_overlay.dart';

Expand Down Expand Up @@ -192,7 +191,6 @@ final addCredentialToAnyProvider =
Provider((ref) => (Uri credentialUri, {bool requireTouch = false}) async {
final oath = ref.watch(_oathMethodsProvider.notifier);
try {
await preserveConnectedDeviceWhenPaused();
var result = jsonDecode(await oath.invoke('addAccountToAny', {
'uri': credentialUri.toString(),
'requireTouch': requireTouch
Expand All @@ -208,7 +206,6 @@ final addCredentialsToAnyProvider = Provider(
(ref) => (List<String> credentialUris, List<bool> touchRequired) async {
final oath = ref.read(_oathMethodsProvider.notifier);
try {
await preserveConnectedDeviceWhenPaused();
_log.debug(
'Calling android with ${credentialUris.length} credentials to be added');
var result = jsonDecode(await oath.invoke('addAccountsToAny',
Expand Down
9 changes: 5 additions & 4 deletions lib/android/overlay/nfc/nfc_overlay.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ final nfcOverlay =
class _NfcOverlayNotifier extends Notifier<int> {
Timer? processingViewTimeout;
late final l10n = ref.read(l10nProvider);
late final eventNotifier = ref.read(nfcEventNotifier.notifier);

@override
int build() {
Expand Down Expand Up @@ -76,10 +77,9 @@ class _NfcOverlayNotifier extends Notifier<int> {
});

_channel.setMethodCallHandler((call) async {
final notifier = ref.read(nfcEventNotifier.notifier);
switch (call.method) {
case 'show':
notifier.send(showTapYourYubiKey());
eventNotifier.send(showTapYourYubiKey());
break;

case 'close':
Expand All @@ -97,12 +97,13 @@ class _NfcOverlayNotifier extends Notifier<int> {
}

NfcEvent showTapYourYubiKey() {
final nfcAvailable = ref.watch(androidNfcAdapterState);
ref.read(nfcOverlayWidgetProperties.notifier).update(hasCloseButton: true);
return NfcSetViewEvent(
child: NfcContentWidget(
title: l10n.s_nfc_ready_to_scan,
subtitle: l10n.s_nfc_tap_your_yubikey,
icon: const NfcIconProgressBar(false),
subtitle: nfcAvailable ? l10n.s_nfc_tap_your_yubikey : l10n.l_insert_yk,
icon: nfcAvailable ? const NfcIconProgressBar(false) : const UsbIcon(),
));
}

Expand Down
11 changes: 11 additions & 0 deletions lib/android/overlay/nfc/views/nfc_overlay_icons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ class NfcIconProgressBar extends StatelessWidget {
);
}

class UsbIcon extends StatelessWidget {
const UsbIcon({super.key});

@override
Widget build(BuildContext context) => Icon(
Symbols.usb,
size: 64,
color: Theme.of(context).colorScheme.primary,
);
}

class NfcIconSuccess extends StatelessWidget {
const NfcIconSuccess({super.key});

Expand Down
Loading