2021-11-24 10:44:28 +03:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
|
2022-03-15 20:04:26 +03:00
|
|
|
import '../../management/views/management_screen.dart';
|
2021-12-02 13:44:17 +03:00
|
|
|
import '../../about_page.dart';
|
2022-02-22 13:15:15 +03:00
|
|
|
import '../../settings_page.dart';
|
2021-11-24 10:44:28 +03:00
|
|
|
import '../models.dart';
|
|
|
|
import '../state.dart';
|
|
|
|
|
2022-03-14 13:48:39 +03:00
|
|
|
extension on Application {
|
|
|
|
IconData get _icon {
|
|
|
|
switch (this) {
|
|
|
|
case Application.oath:
|
|
|
|
return Icons.supervisor_account;
|
|
|
|
case Application.fido:
|
|
|
|
return Icons.security;
|
|
|
|
case Application.otp:
|
|
|
|
return Icons.password;
|
|
|
|
case Application.piv:
|
|
|
|
return Icons.approval;
|
|
|
|
case Application.management:
|
|
|
|
return Icons.construction;
|
|
|
|
case Application.openpgp:
|
|
|
|
return Icons.key;
|
|
|
|
case Application.hsmauth:
|
|
|
|
return Icons.key;
|
|
|
|
}
|
2022-03-04 19:45:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-24 10:44:28 +03:00
|
|
|
class MainPageDrawer extends ConsumerWidget {
|
2022-03-03 19:09:03 +03:00
|
|
|
final bool shouldPop;
|
2022-05-12 10:56:55 +03:00
|
|
|
const MainPageDrawer({this.shouldPop = true, super.key});
|
2021-11-24 10:44:28 +03:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2022-03-14 13:48:39 +03:00
|
|
|
final supportedApps = ref.watch(supportedAppsProvider);
|
2022-03-14 12:57:00 +03:00
|
|
|
final data = ref.watch(currentDeviceDataProvider);
|
2022-03-14 13:48:39 +03:00
|
|
|
final currentApp = ref.watch(currentAppProvider);
|
2022-02-24 17:19:57 +03:00
|
|
|
|
2021-11-24 10:44:28 +03:00
|
|
|
return Drawer(
|
|
|
|
child: ListView(
|
2022-02-09 14:32:34 +03:00
|
|
|
primary: false, //Prevents conflict with the MainPage scroll view.
|
2021-11-24 10:44:28 +03:00
|
|
|
children: [
|
2021-12-02 13:44:17 +03:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(12.0),
|
|
|
|
child: Text(
|
|
|
|
'Yubico Authenticator',
|
2022-05-18 11:30:50 +03:00
|
|
|
style: Theme.of(context).textTheme.titleMedium,
|
2021-11-24 10:44:28 +03:00
|
|
|
),
|
|
|
|
),
|
2022-03-14 12:57:00 +03:00
|
|
|
if (data != null) ...[
|
2022-03-14 13:48:39 +03:00
|
|
|
// Normal YubiKey Applications
|
|
|
|
...supportedApps
|
|
|
|
.where((app) =>
|
|
|
|
app != Application.management &&
|
|
|
|
app.getAvailability(data) != Availability.unsupported)
|
|
|
|
.map((app) => ApplicationItem(
|
|
|
|
app: app,
|
2022-03-14 12:57:00 +03:00
|
|
|
available:
|
2022-03-14 13:48:39 +03:00
|
|
|
app.getAvailability(data) == Availability.enabled,
|
|
|
|
selected: app == currentApp,
|
2022-03-14 12:57:00 +03:00
|
|
|
onSelect: () {
|
|
|
|
if (shouldPop) Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
)),
|
2022-03-14 13:48:39 +03:00
|
|
|
// Management app
|
|
|
|
if (supportedApps.contains(Application.management) &&
|
|
|
|
Application.management.getAvailability(data) ==
|
|
|
|
Availability.enabled) ...[
|
2022-03-14 12:57:00 +03:00
|
|
|
const Divider(),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
child: Text(
|
|
|
|
'Configuration',
|
2022-05-18 11:30:50 +03:00
|
|
|
style: Theme.of(context).textTheme.titleSmall,
|
2022-03-14 12:57:00 +03:00
|
|
|
),
|
2022-03-07 17:36:49 +03:00
|
|
|
),
|
2022-03-14 12:57:00 +03:00
|
|
|
DrawerItem(
|
|
|
|
titleText: 'Toggle applications',
|
2022-03-14 13:48:39 +03:00
|
|
|
icon: Icon(Application.management._icon),
|
2022-03-14 12:57:00 +03:00
|
|
|
onTap: () {
|
|
|
|
if (shouldPop) Navigator.of(context).pop();
|
2022-03-15 20:04:26 +03:00
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => ManagementScreen(data),
|
|
|
|
);
|
2022-03-14 12:57:00 +03:00
|
|
|
},
|
|
|
|
),
|
|
|
|
const Divider(),
|
|
|
|
],
|
2022-03-07 17:36:49 +03:00
|
|
|
],
|
2022-03-14 12:57:00 +03:00
|
|
|
// Non-YubiKey pages
|
2022-02-22 13:15:15 +03:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
child: Text(
|
|
|
|
'Application',
|
2022-05-18 11:30:50 +03:00
|
|
|
style: Theme.of(context).textTheme.titleSmall,
|
2022-02-22 13:15:15 +03:00
|
|
|
),
|
|
|
|
),
|
2021-12-02 13:44:17 +03:00
|
|
|
DrawerItem(
|
2022-02-22 13:15:15 +03:00
|
|
|
titleText: 'Settings',
|
|
|
|
icon: const Icon(Icons.settings),
|
2021-12-02 13:44:17 +03:00
|
|
|
onTap: () {
|
2022-03-03 19:09:03 +03:00
|
|
|
final nav = Navigator.of(context);
|
|
|
|
if (shouldPop) nav.pop();
|
2022-03-15 20:04:26 +03:00
|
|
|
showDialog(
|
|
|
|
context: context, builder: (context) => const SettingsPage());
|
2021-12-02 13:44:17 +03:00
|
|
|
},
|
|
|
|
),
|
|
|
|
DrawerItem(
|
2022-03-25 14:23:14 +03:00
|
|
|
titleText: 'Help and feedback',
|
2022-05-18 11:53:22 +03:00
|
|
|
icon: const Icon(Icons.help),
|
2021-12-02 13:44:17 +03:00
|
|
|
onTap: () {
|
2022-03-03 19:09:03 +03:00
|
|
|
final nav = Navigator.of(context);
|
|
|
|
if (shouldPop) nav.pop();
|
2022-03-15 20:04:26 +03:00
|
|
|
showDialog(
|
|
|
|
context: context, builder: (context) => const AboutPage());
|
2021-12-02 13:44:17 +03:00
|
|
|
},
|
|
|
|
),
|
2021-11-24 10:44:28 +03:00
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2021-12-02 13:44:17 +03:00
|
|
|
|
2022-03-14 13:48:39 +03:00
|
|
|
class ApplicationItem extends ConsumerWidget {
|
|
|
|
final Application app;
|
2022-03-04 19:45:08 +03:00
|
|
|
final bool available;
|
|
|
|
final bool selected;
|
|
|
|
final Function onSelect;
|
2022-03-14 13:48:39 +03:00
|
|
|
const ApplicationItem({
|
|
|
|
required this.app,
|
2022-03-04 19:45:08 +03:00
|
|
|
required this.available,
|
|
|
|
required this.selected,
|
|
|
|
required this.onSelect,
|
2022-05-12 10:56:55 +03:00
|
|
|
super.key,
|
|
|
|
});
|
2022-03-04 19:45:08 +03:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
return DrawerItem(
|
2022-03-14 13:48:39 +03:00
|
|
|
titleText: app.displayName,
|
|
|
|
icon: Icon(app._icon),
|
2022-03-04 19:45:08 +03:00
|
|
|
selected: selected,
|
|
|
|
enabled: available,
|
|
|
|
onTap: available & !selected
|
|
|
|
? () {
|
2022-03-14 13:48:39 +03:00
|
|
|
ref.read(currentAppProvider.notifier).setCurrentApp(app);
|
2022-03-04 19:45:08 +03:00
|
|
|
onSelect();
|
|
|
|
}
|
|
|
|
: null,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-02 13:44:17 +03:00
|
|
|
class DrawerItem extends StatelessWidget {
|
2022-03-04 19:45:08 +03:00
|
|
|
final bool enabled;
|
2021-12-02 13:44:17 +03:00
|
|
|
final bool selected;
|
|
|
|
final String titleText;
|
|
|
|
final Icon icon;
|
|
|
|
final void Function()? onTap;
|
|
|
|
|
|
|
|
const DrawerItem({
|
|
|
|
required this.titleText,
|
|
|
|
required this.icon,
|
|
|
|
this.onTap,
|
|
|
|
this.selected = false,
|
2022-03-04 19:45:08 +03:00
|
|
|
this.enabled = true,
|
2022-05-12 10:56:55 +03:00
|
|
|
super.key,
|
|
|
|
});
|
2021-12-02 13:44:17 +03:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.only(right: 8),
|
|
|
|
child: ListTile(
|
2022-03-04 19:45:08 +03:00
|
|
|
enabled: enabled,
|
2021-12-02 13:44:17 +03:00
|
|
|
shape: const RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.horizontal(right: Radius.circular(20)),
|
|
|
|
),
|
|
|
|
dense: true,
|
|
|
|
selected: selected,
|
|
|
|
selectedColor: Theme.of(context).backgroundColor,
|
|
|
|
selectedTileColor: Theme.of(context).colorScheme.secondary,
|
|
|
|
leading: icon,
|
2021-12-02 22:29:40 +03:00
|
|
|
title: Text(titleText),
|
2021-12-02 13:44:17 +03:00
|
|
|
onTap: onTap,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|