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';
|
|
|
|
import '../message.dart';
|
2023-01-26 13:52:01 +03:00
|
|
|
import '../state.dart';
|
2022-05-20 18:19:39 +03:00
|
|
|
import 'message_page.dart';
|
|
|
|
|
|
|
|
class AppFailurePage extends ConsumerWidget {
|
|
|
|
final Widget? title;
|
|
|
|
final Object cause;
|
|
|
|
const AppFailurePage({this.title, required this.cause, super.key}) : super();
|
|
|
|
|
|
|
|
@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();
|
|
|
|
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))) {
|
2023-12-20 17:09:31 +03:00
|
|
|
graphic = Icon(Icons.stop,
|
|
|
|
size: 96, color: Theme.of(context).colorScheme.primary);
|
2022-05-20 18:19:39 +03:00
|
|
|
header = null;
|
2023-02-28 17:02:12 +03:00
|
|
|
message = l10n.p_webauthn_elevated_permissions_required;
|
2022-05-20 18:19:39 +03:00
|
|
|
actions = [
|
2024-01-16 12:29:44 +03:00
|
|
|
FilledButton.icon(
|
2023-03-02 14:45:55 +03:00
|
|
|
label: Text(l10n.s_unlock),
|
2022-09-01 12:35:39 +03:00
|
|
|
icon: const Icon(Icons.lock_open),
|
|
|
|
onPressed: () async {
|
|
|
|
final closeMessage = showMessage(
|
2023-02-28 17:02:12 +03:00
|
|
|
context, l10n.l_elevating_permissions,
|
2022-09-01 12:35:39 +03:00
|
|
|
duration: const Duration(seconds: 30));
|
|
|
|
try {
|
2022-12-20 16:14:14 +03:00
|
|
|
if (await ref.read(rpcProvider).requireValue.elevate()) {
|
2022-11-30 17:27:32 +03:00
|
|
|
ref.invalidate(rpcProvider);
|
2022-09-01 12:35:39 +03:00
|
|
|
} else {
|
2023-01-26 13:52:01 +03:00
|
|
|
await ref.read(withContextProvider)(
|
|
|
|
(context) async {
|
2023-02-28 13:34:29 +03:00
|
|
|
showMessage(
|
|
|
|
context,
|
2023-03-02 14:45:55 +03:00
|
|
|
l10n.s_permission_denied,
|
2023-02-28 13:34:29 +03:00
|
|
|
);
|
2023-01-26 13:52:01 +03:00
|
|
|
},
|
|
|
|
);
|
2022-05-20 18:19:39 +03:00
|
|
|
}
|
2022-09-01 12:35:39 +03:00
|
|
|
} finally {
|
|
|
|
closeMessage();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
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(
|
|
|
|
title: title,
|
|
|
|
graphic: graphic,
|
|
|
|
header: header,
|
|
|
|
message: message,
|
|
|
|
actions: actions,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|