yubioath-flutter/lib/app/views/app_failure_page.dart

101 lines
3.2 KiB
Dart
Raw Normal View History

2022-10-04 13:12:54 +03:00
/*
* Copyright (C) 2022 Yubico.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
2022-05-20 18:19:39 +03:00
import 'dart:io';
import 'package:flutter/material.dart';
2022-07-27 13:00:31 +03:00
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
2022-05-20 18:19:39 +03:00
import 'package:flutter_riverpod/flutter_riverpod.dart';
2024-03-08 11:30:47 +03:00
import 'package:material_symbols_icons/symbols.dart';
2022-05-20 18:19:39 +03:00
import '../../core/state.dart';
2022-05-20 18:19:39 +03:00
import '../../desktop/models.dart';
import '../../desktop/state.dart';
import '../../management/models.dart';
import '../state.dart';
2024-02-06 15:54:47 +03:00
import 'elevate_fido_buttons.dart';
2022-05-20 18:19:39 +03:00
import 'message_page.dart';
class AppFailurePage extends ConsumerWidget {
final Object cause;
2024-01-15 17:58:40 +03:00
const AppFailurePage({required this.cause, super.key}) : super();
2022-05-20 18:19:39 +03:00
@override
Widget build(BuildContext context, WidgetRef ref) {
2023-02-28 13:34:29 +03:00
final l10n = AppLocalizations.of(context)!;
2022-05-20 18:19:39 +03:00
final reason = cause;
2024-03-08 11:30:47 +03:00
Widget? graphic = Icon(Symbols.error,
size: 96, color: Theme.of(context).colorScheme.error);
2024-01-08 20:51:55 +03:00
String? header = l10n.l_error_occurred;
2022-05-20 18:19:39 +03:00
String? message = reason.toString();
String? title;
bool centered = true;
List<Capability>? capabilities;
2022-05-20 18:19:39 +03:00
List<Widget> actions = [];
2024-02-06 16:36:29 +03:00
String? footnote;
2022-05-20 18:19:39 +03:00
if (reason is RpcError) {
if (reason.status == 'connection-error') {
switch (reason.body['connection']) {
case 'ccid':
2023-02-28 17:02:12 +03:00
header = l10n.l_ccid_connection_failed;
2022-05-20 18:19:39 +03:00
if (Platform.isMacOS) {
message = l10n.p_try_reinsert_yk;
2022-05-20 18:19:39 +03:00
} else if (Platform.isLinux) {
2023-02-28 17:02:12 +03:00
message = l10n.p_pcscd_unavailable;
2022-05-20 18:19:39 +03:00
} else {
2023-02-28 17:02:12 +03:00
message = l10n.p_ccid_service_unavailable;
2022-05-20 18:19:39 +03:00
}
break;
case 'fido':
if (Platform.isWindows &&
!ref.watch(rpcStateProvider.select((state) => state.isAdmin))) {
final currentSection = ref.read(currentSectionProvider);
title = currentSection.getDisplayName(l10n);
capabilities = currentSection.capabilities;
2024-02-06 17:27:12 +03:00
header = l10n.l_admin_privileges_required;
2023-02-28 17:02:12 +03:00
message = l10n.p_webauthn_elevated_permissions_required;
centered = false;
graphic = null;
2022-05-20 18:19:39 +03:00
actions = [
2024-02-06 15:54:47 +03:00
const ElevateFidoButtons(),
2022-05-20 18:19:39 +03:00
];
if (isMicrosoftStore) {
footnote = l10n.l_ms_store_permission_note;
}
2022-05-20 18:19:39 +03:00
}
break;
default:
2023-02-28 17:02:12 +03:00
header = l10n.l_open_connection_failed;
message = l10n.p_try_reinsert_yk;
2022-05-20 18:19:39 +03:00
}
}
}
return MessagePage(
centered: centered,
title: title,
capabilities: capabilities,
2022-05-20 18:19:39 +03:00
graphic: graphic,
header: header,
message: message,
2024-02-06 16:36:29 +03:00
footnote: footnote,
actionsBuilder: (context, expanded) => actions,
2022-05-20 18:19:39 +03:00
);
}
}