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';
|
|
|
|
|
|
|
|
import '../../desktop/models.dart';
|
|
|
|
import '../../desktop/state.dart';
|
2024-01-29 13:13:05 +03:00
|
|
|
import '../../management/models.dart';
|
2023-01-26 13:52:01 +03:00
|
|
|
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;
|
|
|
|
|
2023-12-20 17:09:31 +03:00
|
|
|
Widget? graphic =
|
|
|
|
Icon(Icons.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();
|
2024-01-29 13:13:05 +03:00
|
|
|
String? title;
|
|
|
|
bool centered = true;
|
|
|
|
List<Capability>? capabilities;
|
2022-05-20 18:19:39 +03:00
|
|
|
List<Widget> actions = [];
|
|
|
|
|
|
|
|
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) {
|
2023-03-02 14:45:55 +03:00
|
|
|
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))) {
|
2024-01-29 13:13:05 +03:00
|
|
|
final currentApp = ref.read(currentAppProvider);
|
|
|
|
title = currentApp.getDisplayName(l10n);
|
2024-02-03 18:12:51 +03:00
|
|
|
capabilities = currentApp.capabilities;
|
2024-01-29 13:13:05 +03:00
|
|
|
header = l10n.s_admin_privileges_required;
|
2023-02-28 17:02:12 +03:00
|
|
|
message = l10n.p_webauthn_elevated_permissions_required;
|
2024-01-29 13:13:05 +03:00
|
|
|
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
|
|
|
];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2023-02-28 17:02:12 +03:00
|
|
|
header = l10n.l_open_connection_failed;
|
2023-03-02 14:45:55 +03:00
|
|
|
message = l10n.p_try_reinsert_yk;
|
2022-05-20 18:19:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return MessagePage(
|
2024-01-29 13:13:05 +03:00
|
|
|
centered: centered,
|
|
|
|
title: title,
|
|
|
|
capabilities: capabilities,
|
2022-05-20 18:19:39 +03:00
|
|
|
graphic: graphic,
|
|
|
|
header: header,
|
|
|
|
message: message,
|
2024-01-26 16:20:29 +03:00
|
|
|
actionsBuilder: (context, expanded) => actions,
|
2022-05-20 18:19:39 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|