2024-03-06 23:06:48 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2024 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
2024-03-08 17:50:19 +03:00
|
|
|
import 'package:material_symbols_icons/material_symbols_icons.dart';
|
|
|
|
import 'package:material_symbols_icons/symbols.dart';
|
2024-03-06 23:06:48 +03:00
|
|
|
|
|
|
|
import '../../app/features.dart' as features;
|
|
|
|
import '../../app/message.dart';
|
|
|
|
import '../../app/models.dart';
|
|
|
|
import '../../app/shortcuts.dart';
|
|
|
|
import '../../app/views/action_list.dart';
|
2024-04-15 13:06:10 +03:00
|
|
|
import '../../app/views/keys.dart';
|
2024-03-06 23:06:48 +03:00
|
|
|
import '../../app/views/reset_dialog.dart';
|
2024-03-08 19:35:50 +03:00
|
|
|
import '../../core/models.dart';
|
2024-03-06 23:06:48 +03:00
|
|
|
import '../../core/state.dart';
|
|
|
|
import '../../management/views/management_screen.dart';
|
|
|
|
|
|
|
|
Widget homeBuildActions(
|
|
|
|
BuildContext context, YubiKeyData? deviceData, WidgetRef ref) {
|
|
|
|
final l10n = AppLocalizations.of(context)!;
|
|
|
|
final hasFeature = ref.watch(featureProvider);
|
2024-07-14 20:51:14 +03:00
|
|
|
final interfacesLocked = deviceData?.info.resetBlocked != 0;
|
2024-03-08 19:35:50 +03:00
|
|
|
final managementAvailability = hasFeature(features.management) &&
|
|
|
|
switch (deviceData?.info.version) {
|
|
|
|
Version version => (version.major > 4 || // YK5 and up
|
|
|
|
(version.major == 4 && version.minor >= 1) || // YK4.1 and up
|
|
|
|
version.major == 3), // NEO,
|
|
|
|
null => false,
|
|
|
|
};
|
2024-03-06 23:06:48 +03:00
|
|
|
|
|
|
|
return Column(
|
|
|
|
children: [
|
|
|
|
if (deviceData != null)
|
|
|
|
ActionListSection(
|
|
|
|
l10n.s_device,
|
|
|
|
children: [
|
2024-03-08 19:35:50 +03:00
|
|
|
if (managementAvailability)
|
2024-03-06 23:06:48 +03:00
|
|
|
ActionListItem(
|
|
|
|
feature: features.management,
|
2024-03-08 17:50:19 +03:00
|
|
|
icon: const Icon(Symbols.construction),
|
2024-03-06 23:06:48 +03:00
|
|
|
actionStyle: ActionStyle.primary,
|
|
|
|
title: deviceData.info.version.major > 4
|
|
|
|
? l10n.s_toggle_applications
|
|
|
|
: l10n.s_toggle_interfaces,
|
2024-07-14 20:51:14 +03:00
|
|
|
subtitle: interfacesLocked
|
2024-08-19 11:55:49 +03:00
|
|
|
? l10n.l_factory_reset_required
|
2024-07-14 20:51:14 +03:00
|
|
|
: (deviceData.info.version.major > 4
|
|
|
|
? l10n.l_toggle_applications_desc
|
|
|
|
: l10n.l_toggle_interfaces_desc),
|
|
|
|
onTap: interfacesLocked
|
|
|
|
? null
|
|
|
|
: (context) {
|
|
|
|
Navigator.of(context)
|
|
|
|
.popUntil((route) => route.isFirst);
|
|
|
|
showBlurDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => ManagementScreen(deviceData),
|
|
|
|
);
|
|
|
|
},
|
2024-03-06 23:06:48 +03:00
|
|
|
),
|
|
|
|
if (getResetCapabilities(hasFeature).any((c) =>
|
|
|
|
c.value &
|
|
|
|
(deviceData.info
|
|
|
|
.supportedCapabilities[deviceData.node.transport] ??
|
|
|
|
0) !=
|
|
|
|
0))
|
|
|
|
ActionListItem(
|
2024-03-08 17:50:19 +03:00
|
|
|
icon: const Icon(Symbols.delete_forever),
|
2024-03-06 23:06:48 +03:00
|
|
|
title: l10n.s_factory_reset,
|
|
|
|
subtitle: l10n.l_factory_reset_desc,
|
|
|
|
actionStyle: ActionStyle.primary,
|
2024-03-11 15:25:17 +03:00
|
|
|
onTap: (context) {
|
|
|
|
Navigator.of(context).popUntil((route) => route.isFirst);
|
|
|
|
showBlurDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => ResetDialog(deviceData),
|
2024-03-06 23:06:48 +03:00
|
|
|
);
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
ActionListSection(l10n.s_application, children: [
|
|
|
|
ActionListItem(
|
2024-03-08 17:50:19 +03:00
|
|
|
icon: const Icon(Symbols.settings),
|
2024-04-15 13:06:10 +03:00
|
|
|
key: settingDrawerIcon,
|
2024-03-06 23:06:48 +03:00
|
|
|
title: l10n.s_settings,
|
|
|
|
subtitle: l10n.l_settings_desc,
|
|
|
|
actionStyle: ActionStyle.primary,
|
2024-03-11 15:25:17 +03:00
|
|
|
onTap: (context) {
|
|
|
|
Navigator.of(context).popUntil((route) => route.isFirst);
|
2024-03-06 23:06:48 +03:00
|
|
|
Actions.maybeInvoke(context, const SettingsIntent());
|
|
|
|
},
|
|
|
|
),
|
|
|
|
ActionListItem(
|
2024-03-08 17:50:19 +03:00
|
|
|
icon: const Icon(Symbols.help),
|
2024-04-15 13:06:10 +03:00
|
|
|
key: helpDrawerIcon,
|
2024-03-06 23:06:48 +03:00
|
|
|
title: l10n.s_help_and_about,
|
|
|
|
subtitle: l10n.l_help_and_about_desc,
|
|
|
|
actionStyle: ActionStyle.primary,
|
2024-03-11 15:25:17 +03:00
|
|
|
onTap: (context) {
|
|
|
|
Navigator.of(context).popUntil((route) => route.isFirst);
|
2024-03-06 23:06:48 +03:00
|
|
|
Actions.maybeInvoke(context, const AboutIntent());
|
|
|
|
},
|
|
|
|
)
|
|
|
|
])
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|