This commit is contained in:
Adam Velebil 2023-08-02 16:55:23 +02:00
commit 23316ab7c0
No known key found for this signature in database
GPG Key ID: C9B1E4A3CBBD2E10
5 changed files with 39 additions and 6 deletions

View File

@ -154,18 +154,17 @@ class MainActivity : FlutterFragmentActivity() {
@SuppressLint("WrongConstant")
override fun onStart() {
super.onStart()
val receiverFlags = ContextCompat.RECEIVER_NOT_EXPORTED
ContextCompat.registerReceiver(
this,
qrScannerCameraClosedBR,
QRScannerCameraClosedBR.intentFilter,
receiverFlags
ContextCompat.RECEIVER_NOT_EXPORTED
)
ContextCompat.registerReceiver(
this,
nfcAdapterStateChangeBR,
NfcAdapterStateChangedBR.intentFilter,
receiverFlags
ContextCompat.RECEIVER_EXPORTED
)
}
@ -329,11 +328,15 @@ class MainActivity : FlutterFragmentActivity() {
* this receiver restarts the YubiKit NFC discovery when the QR Scanner camera is closed.
*/
class QRScannerCameraClosedBR : BroadcastReceiver() {
private val logger = LoggerFactory.getLogger(QRScannerCameraClosedBR::class.java)
companion object {
val intentFilter = IntentFilter("com.yubico.authenticator.QRScannerView.CameraClosed")
}
override fun onReceive(context: Context?, intent: Intent?) {
logger.debug("Restarting nfc discovery after camera was closed.")
(context as? MainActivity)?.startNfcDiscovery()
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Yubico.
* Copyright (C) 2022-2023 Yubico.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -37,6 +37,7 @@ import '../../desktop/models.dart';
import '../../management/models.dart';
import '../../widgets/choice_filter_chip.dart';
import '../../widgets/file_drop_target.dart';
import '../../widgets/focus_utils.dart';
import '../../widgets/responsive_dialog.dart';
import '../../widgets/utf8_utils.dart';
import '../keys.dart' as keys;
@ -175,6 +176,9 @@ class _OathAddAccountPageState extends ConsumerState<OathAddAccountPage> {
{DevicePath? devicePath, required Uri credUri}) async {
final l10n = AppLocalizations.of(context)!;
try {
FocusUtils.unfocus(context);
if (devicePath == null) {
assert(isAndroid, 'devicePath is only optional for Android');
await ref

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Yubico.
* Copyright (C) 2022-2023 Yubico.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -20,6 +20,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../app/message.dart';
import '../../app/models.dart';
import '../../widgets/focus_utils.dart';
import '../../widgets/responsive_dialog.dart';
import '../models.dart';
import '../state.dart';
@ -42,6 +43,9 @@ class _ManagePasswordDialogState extends ConsumerState<ManagePasswordDialog> {
bool _currentIsWrong = false;
_submit() async {
FocusUtils.unfocus(context);
final result = await ref
.read(oathStateProvider(widget.path).notifier)
.setPassword(_currentPassword, _newPassword);

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Yubico.
* Copyright (C) 2022-2023 Yubico.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -24,6 +24,7 @@ import '../../app/message.dart';
import '../../app/models.dart';
import '../../exception/cancellation_exception.dart';
import '../../desktop/models.dart';
import '../../widgets/focus_utils.dart';
import '../../widgets/responsive_dialog.dart';
import '../../widgets/utf8_utils.dart';
import '../models.dart';
@ -60,6 +61,9 @@ class _RenameAccountDialogState extends ConsumerState<RenameAccountDialog> {
void _submit() async {
final l10n = AppLocalizations.of(context)!;
try {
FocusUtils.unfocus(context);
// Rename credentials
final renamed = await ref
.read(credentialListProvider(widget.device.path).notifier)

View File

@ -0,0 +1,18 @@
import 'package:flutter/cupertino.dart';
import 'package:logging/logging.dart';
import '../app/logging.dart';
final _log = Logger('FocusUtils');
class FocusUtils {
static void unfocus(BuildContext context) {
FocusScopeNode currentFocus = FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus) {
_log.debug('Removing focus...');
currentFocus.unfocus();
}
}
}