mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-11-27 06:14:58 +03:00
Merge PR #1149.
This commit is contained in:
commit
425dbf941b
@ -22,11 +22,12 @@ import '../../android/state.dart';
|
||||
import '../../exception/cancellation_exception.dart';
|
||||
import '../../core/state.dart';
|
||||
import '../../fido/views/fido_screen.dart';
|
||||
import '../../oath/state.dart';
|
||||
import '../../oath/views/add_account_page.dart';
|
||||
import '../../oath/views/oath_screen.dart';
|
||||
import '../../oath/views/utils.dart';
|
||||
import '../../piv/views/piv_screen.dart';
|
||||
import '../../widgets/custom_icons.dart';
|
||||
import '../message.dart';
|
||||
import '../models.dart';
|
||||
import '../state.dart';
|
||||
import 'device_error_screen.dart';
|
||||
@ -98,19 +99,33 @@ class MainPage extends ConsumerWidget {
|
||||
icon: const Icon(Icons.person_add_alt_1),
|
||||
tooltip: l10n.s_add_account,
|
||||
onPressed: () async {
|
||||
final withContext = ref.read(withContextProvider);
|
||||
final scanner = ref.read(qrScannerProvider);
|
||||
if (scanner != null) {
|
||||
try {
|
||||
final uri = await scanner.scanQr();
|
||||
final credentials = ref.read(credentialsProvider);
|
||||
final withContext = ref.read(withContextProvider);
|
||||
await withContext((context) =>
|
||||
handleUri(context, credentials, uri, null, null, l10n));
|
||||
final qrData = await scanner.scanQr();
|
||||
if (qrData != null) {
|
||||
await withContext((context) =>
|
||||
handleUri(context, null, qrData, null, null, l10n));
|
||||
return;
|
||||
}
|
||||
} on CancellationException catch (_) {
|
||||
// ignored - user cancelled
|
||||
return;
|
||||
}
|
||||
}
|
||||
await withContext((context) => showBlurDialog(
|
||||
context: context,
|
||||
routeSettings:
|
||||
const RouteSettings(name: 'oath_add_account'),
|
||||
builder: (context) {
|
||||
return const OathAddAccountPage(
|
||||
null,
|
||||
null,
|
||||
credentials: null,
|
||||
);
|
||||
},
|
||||
));
|
||||
},
|
||||
),
|
||||
);
|
||||
|
@ -57,9 +57,17 @@ class _AddAccountDialogState extends ConsumerState<AddAccountDialog> {
|
||||
Navigator.of(context).pop();
|
||||
if (qrScanner != null) {
|
||||
final b64Image = base64Encode(fileData);
|
||||
final uri = await qrScanner.scanQr(b64Image);
|
||||
await withContext((context) => handleUri(context, credentials,
|
||||
uri, widget.devicePath, widget.state, l10n));
|
||||
final qrData = await qrScanner.scanQr(b64Image);
|
||||
await withContext(
|
||||
(context) async {
|
||||
if (qrData != null) {
|
||||
await handleUri(context, credentials, qrData,
|
||||
widget.devicePath, widget.state, l10n);
|
||||
} else {
|
||||
showMessage(context, l10n.l_qr_not_found);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Column(
|
||||
@ -76,16 +84,19 @@ class _AddAccountDialogState extends ConsumerState<AddAccountDialog> {
|
||||
avatar: const Icon(Icons.qr_code_scanner_outlined),
|
||||
label: Text(l10n.s_qr_scan),
|
||||
onPressed: () async {
|
||||
Navigator.of(context).pop();
|
||||
if (qrScanner != null) {
|
||||
final uri = await qrScanner.scanQr();
|
||||
await withContext((context) => handleUri(
|
||||
context,
|
||||
credentials,
|
||||
uri,
|
||||
widget.devicePath,
|
||||
widget.state,
|
||||
l10n));
|
||||
final qrData = await qrScanner.scanQr();
|
||||
await withContext(
|
||||
(context) async {
|
||||
if (qrData != null) {
|
||||
Navigator.of(context).pop();
|
||||
await handleUri(context, credentials, qrData,
|
||||
widget.devicePath, widget.state, l10n);
|
||||
} else {
|
||||
showMessage(context, l10n.l_qr_not_found);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
|
@ -29,6 +29,7 @@ import '../../core/state.dart';
|
||||
import '../models.dart';
|
||||
import '../keys.dart' as keys;
|
||||
import '../state.dart';
|
||||
import 'add_account_page.dart';
|
||||
import 'manage_password_dialog.dart';
|
||||
import 'reset_dialog.dart';
|
||||
import 'utils.dart';
|
||||
@ -64,10 +65,32 @@ Widget oathBuildActions(
|
||||
if (isAndroid) {
|
||||
final qrScanner = ref.read(qrScannerProvider);
|
||||
if (qrScanner != null) {
|
||||
final uri = await qrScanner.scanQr();
|
||||
await withContext((context) => handleUri(context,
|
||||
credentials, uri, devicePath, oathState, l10n));
|
||||
final qrData = await qrScanner.scanQr();
|
||||
if (qrData != null) {
|
||||
await withContext((context) => handleUri(
|
||||
context,
|
||||
credentials,
|
||||
qrData,
|
||||
devicePath,
|
||||
oathState,
|
||||
l10n,
|
||||
));
|
||||
return;
|
||||
}
|
||||
}
|
||||
await withContext((context) => showBlurDialog(
|
||||
context: context,
|
||||
routeSettings:
|
||||
const RouteSettings(name: 'oath_add_account'),
|
||||
builder: (context) {
|
||||
return OathAddAccountPage(
|
||||
devicePath,
|
||||
oathState,
|
||||
credentials: credentials,
|
||||
credentialData: null,
|
||||
);
|
||||
},
|
||||
));
|
||||
} else {
|
||||
await showBlurDialog(
|
||||
context: context,
|
||||
|
@ -65,13 +65,12 @@ String getTextName(OathCredential credential) {
|
||||
Future<void> handleUri(
|
||||
BuildContext context,
|
||||
List<OathCredential>? credentials,
|
||||
String? uri,
|
||||
String qrData,
|
||||
DevicePath? devicePath,
|
||||
OathState? state,
|
||||
AppLocalizations l10n,
|
||||
) async {
|
||||
List<CredentialData> creds =
|
||||
uri != null ? CredentialData.fromUri(Uri.parse(uri)) : [];
|
||||
List<CredentialData> creds = CredentialData.fromUri(Uri.parse(qrData));
|
||||
if (creds.isEmpty) {
|
||||
showMessage(context, l10n.l_qr_not_found);
|
||||
} else if (creds.length == 1) {
|
||||
|
Loading…
Reference in New Issue
Block a user