mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-11-26 10:33:15 +03:00
Customize error messages for connection failures.
This commit is contained in:
parent
8674015f34
commit
f33087fd0f
@ -1,18 +1,46 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:yubico_authenticator/desktop/models.dart';
|
||||||
|
|
||||||
class AppFailureScreen extends StatelessWidget {
|
class AppFailureScreen extends StatelessWidget {
|
||||||
final String reason;
|
final Object reason;
|
||||||
const AppFailureScreen(this.reason, {super.key}) : super();
|
const AppFailureScreen(this.reason, {super.key}) : super();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final cause = reason;
|
||||||
|
if (cause is RpcError) {
|
||||||
|
if (cause.status == 'connection-error' &&
|
||||||
|
cause.body['connection'] == 'ccid') {
|
||||||
|
var msg = 'Failed to open smart card connection';
|
||||||
|
if (Platform.isMacOS) {
|
||||||
|
msg += '\nTry to remove and re-insert your YubiKey to regain access.';
|
||||||
|
} else if (Platform.isLinux) {
|
||||||
|
msg += '\nMake sure pcscd is running.';
|
||||||
|
}
|
||||||
return Center(
|
return Center(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
reason,
|
msg,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Center(
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
cause.toString(),
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
@ -10,6 +10,7 @@ import '../../app/views/app_loading_screen.dart';
|
|||||||
import '../../app/views/app_page.dart';
|
import '../../app/views/app_page.dart';
|
||||||
import '../../app/views/graphics.dart';
|
import '../../app/views/graphics.dart';
|
||||||
import '../../app/views/message_page.dart';
|
import '../../app/views/message_page.dart';
|
||||||
|
import '../../desktop/models.dart';
|
||||||
import '../../desktop/state.dart';
|
import '../../desktop/state.dart';
|
||||||
import '../../management/models.dart';
|
import '../../management/models.dart';
|
||||||
import '../../theme.dart';
|
import '../../theme.dart';
|
||||||
@ -52,9 +53,10 @@ class FidoScreen extends ConsumerWidget {
|
|||||||
'WebAuthn requires the FIDO2 application to be enabled on your YubiKey',
|
'WebAuthn requires the FIDO2 application to be enabled on your YubiKey',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (Platform.isWindows) {
|
if (Platform.isWindows && error is RpcError) {
|
||||||
if (!ref
|
if (error.status == 'connection-error' &&
|
||||||
.watch(rpcStateProvider.select((state) => state.isAdmin))) {
|
!ref.watch(
|
||||||
|
rpcStateProvider.select((state) => state.isAdmin))) {
|
||||||
return MessagePage(
|
return MessagePage(
|
||||||
title: const Text('WebAuthn'),
|
title: const Text('WebAuthn'),
|
||||||
graphic: noPermission,
|
graphic: noPermission,
|
||||||
@ -85,7 +87,7 @@ class FidoScreen extends ConsumerWidget {
|
|||||||
return AppPage(
|
return AppPage(
|
||||||
title: const Text('WebAuthn'),
|
title: const Text('WebAuthn'),
|
||||||
centered: true,
|
centered: true,
|
||||||
child: AppFailureScreen('$error'),
|
child: AppFailureScreen(error),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
data: (fidoState) {
|
data: (fidoState) {
|
||||||
|
@ -241,7 +241,7 @@ class _ManagementScreenState extends ConsumerState<ManagementScreen> {
|
|||||||
final child =
|
final child =
|
||||||
ref.watch(managementStateProvider(widget.deviceData.node.path)).when(
|
ref.watch(managementStateProvider(widget.deviceData.node.path)).when(
|
||||||
loading: () => const AppLoadingScreen(),
|
loading: () => const AppLoadingScreen(),
|
||||||
error: (error, _) => AppFailureScreen('$error'),
|
error: (error, _) => AppFailureScreen(error),
|
||||||
data: (info) {
|
data: (info) {
|
||||||
bool hasConfig = info.version.major > 4;
|
bool hasConfig = info.version.major > 4;
|
||||||
if (hasConfig) {
|
if (hasConfig) {
|
||||||
|
@ -34,7 +34,7 @@ class OathScreen extends ConsumerWidget {
|
|||||||
error: (error, _) => AppPage(
|
error: (error, _) => AppPage(
|
||||||
title: const Text('Authenticator'),
|
title: const Text('Authenticator'),
|
||||||
centered: true,
|
centered: true,
|
||||||
child: AppFailureScreen('$error'),
|
child: AppFailureScreen(error),
|
||||||
),
|
),
|
||||||
data: (oathState) => oathState.locked
|
data: (oathState) => oathState.locked
|
||||||
? _LockedView(devicePath, oathState)
|
? _LockedView(devicePath, oathState)
|
||||||
|
Loading…
Reference in New Issue
Block a user