2022-03-25 14:23:14 +03:00
|
|
|
import 'dart:convert';
|
2021-11-24 13:38:30 +03:00
|
|
|
|
2022-06-02 15:53:29 +03:00
|
|
|
import 'package:flutter/gestures.dart';
|
2021-11-19 17:05:57 +03:00
|
|
|
import 'package:flutter/material.dart';
|
2022-03-25 14:23:14 +03:00
|
|
|
import 'package:flutter/services.dart';
|
2021-11-24 13:38:30 +03:00
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import 'package:logging/logging.dart';
|
2021-11-25 13:56:25 +03:00
|
|
|
|
2022-06-02 15:53:29 +03:00
|
|
|
import 'app/state.dart';
|
2022-05-13 11:46:36 +03:00
|
|
|
import 'version.dart';
|
2022-03-25 14:23:14 +03:00
|
|
|
import 'app/logging.dart';
|
2022-03-25 17:43:32 +03:00
|
|
|
import 'app/message.dart';
|
2021-11-25 13:56:25 +03:00
|
|
|
import 'core/state.dart';
|
2022-01-27 14:34:29 +03:00
|
|
|
import 'desktop/state.dart';
|
2022-03-31 12:50:40 +03:00
|
|
|
import 'widgets/responsive_dialog.dart';
|
2021-11-24 13:38:30 +03:00
|
|
|
|
2022-02-21 11:38:09 +03:00
|
|
|
final _log = Logger('about');
|
2021-11-19 17:05:57 +03:00
|
|
|
|
2021-11-24 13:38:30 +03:00
|
|
|
class AboutPage extends ConsumerWidget {
|
2022-05-12 10:56:55 +03:00
|
|
|
const AboutPage({super.key});
|
2021-11-19 17:05:57 +03:00
|
|
|
|
|
|
|
@override
|
2021-11-24 13:38:30 +03:00
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2022-03-15 20:04:26 +03:00
|
|
|
return ResponsiveDialog(
|
2022-06-02 15:53:29 +03:00
|
|
|
title: const Text('About'),
|
2022-03-15 20:04:26 +03:00
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
2022-06-02 15:53:29 +03:00
|
|
|
//crossAxisAlignment: CrossAxisAlignment.start,
|
2022-03-15 20:04:26 +03:00
|
|
|
children: [
|
2022-06-02 15:53:29 +03:00
|
|
|
Image.asset('assets/graphics/app-icon.png', scale: 1 / 0.75),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 24.0),
|
|
|
|
child: Text(
|
|
|
|
'Yubico Authenticator',
|
|
|
|
style: Theme.of(context).textTheme.titleMedium,
|
|
|
|
),
|
|
|
|
),
|
2022-05-13 11:46:36 +03:00
|
|
|
const Text('Yubico Authenticator: $version'),
|
2022-06-02 15:53:29 +03:00
|
|
|
if (isDesktop) Text('ykman: ${ref.watch(rpcStateProvider).version}'),
|
|
|
|
//Text('Dart version: ${Platform.version}'),
|
|
|
|
const Text('Copyright © 2022 Yubico'),
|
|
|
|
const Text('All rights reserved'),
|
|
|
|
const Text(''),
|
|
|
|
Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: const [
|
|
|
|
UrlLink(text: 'Terms of use', url: 'https://example.com'),
|
|
|
|
SizedBox(width: 8.0),
|
|
|
|
UrlLink(text: 'Privacy policy', url: 'https://example.com'),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
const Padding(
|
|
|
|
padding: EdgeInsets.only(top: 24.0, bottom: 8.0),
|
|
|
|
child: Divider(),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 16.0),
|
|
|
|
child: Text(
|
|
|
|
'Help and feedback',
|
|
|
|
style: Theme.of(context).textTheme.titleMedium,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: const [
|
|
|
|
UrlLink(text: 'Send us feedback', url: 'https://example.com'),
|
|
|
|
SizedBox(width: 8.0),
|
|
|
|
UrlLink(text: 'I need help', url: 'https://example.com'),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
const Padding(
|
|
|
|
padding: EdgeInsets.only(top: 24.0, bottom: 8.0),
|
|
|
|
child: Divider(),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 16.0),
|
|
|
|
child: Text(
|
|
|
|
'Troubleshooting',
|
|
|
|
style: Theme.of(context).textTheme.titleMedium,
|
|
|
|
),
|
|
|
|
),
|
2022-03-25 14:23:14 +03:00
|
|
|
const LoggingPanel(),
|
|
|
|
if (isDesktop) ...[
|
2022-06-02 15:53:29 +03:00
|
|
|
const SizedBox(height: 12.0),
|
2022-05-25 17:10:26 +03:00
|
|
|
OutlinedButton.icon(
|
2022-06-02 15:53:29 +03:00
|
|
|
icon: const Icon(Icons.bug_report_outlined),
|
|
|
|
label: const Text('Run diagnostics'),
|
2022-03-15 20:04:26 +03:00
|
|
|
onPressed: () async {
|
|
|
|
_log.info('Running diagnostics...');
|
|
|
|
final response =
|
|
|
|
await ref.read(rpcProvider).command('diagnose', []);
|
2022-05-17 10:10:23 +03:00
|
|
|
final data = response['diagnostics'] as List;
|
|
|
|
data.insert(0, {'app_version': version});
|
2022-03-25 14:23:14 +03:00
|
|
|
final text = const JsonEncoder.withIndent(' ').convert(data);
|
|
|
|
await Clipboard.setData(ClipboardData(text: text));
|
2022-05-12 09:34:51 +03:00
|
|
|
await ref.read(withContextProvider)(
|
|
|
|
(context) async {
|
|
|
|
showMessage(context, 'Diagnostic data copied to clipboard');
|
|
|
|
},
|
|
|
|
);
|
2022-03-15 20:04:26 +03:00
|
|
|
},
|
|
|
|
),
|
2022-03-25 14:23:14 +03:00
|
|
|
]
|
2022-03-15 20:04:26 +03:00
|
|
|
],
|
2021-11-19 17:05:57 +03:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2022-03-25 14:23:14 +03:00
|
|
|
|
|
|
|
class LoggingPanel extends ConsumerWidget {
|
2022-05-12 10:56:55 +03:00
|
|
|
const LoggingPanel({super.key});
|
2022-03-25 14:23:14 +03:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2022-06-02 15:53:29 +03:00
|
|
|
return Column(
|
|
|
|
//crossAxisAlignment: CrossAxisAlignment.start,
|
2022-03-25 14:23:14 +03:00
|
|
|
children: [
|
2022-06-02 15:53:29 +03:00
|
|
|
const SizedBox(height: 12.0),
|
|
|
|
DropdownButtonFormField<Level>(
|
|
|
|
decoration: const InputDecoration(
|
|
|
|
labelText: 'Log level',
|
|
|
|
border: OutlineInputBorder(),
|
|
|
|
),
|
2022-03-25 14:23:14 +03:00
|
|
|
value: ref.watch(logLevelProvider),
|
2022-05-03 12:24:25 +03:00
|
|
|
items: Levels.LEVELS
|
2022-03-25 14:23:14 +03:00
|
|
|
.map((e) => DropdownMenuItem(
|
|
|
|
value: e,
|
|
|
|
child: Text(e.name.toUpperCase()),
|
|
|
|
))
|
|
|
|
.toList(),
|
|
|
|
onChanged: (level) {
|
|
|
|
ref.read(logLevelProvider.notifier).setLogLevel(level!);
|
2022-05-03 12:24:25 +03:00
|
|
|
_log.debug('Log level set to $level');
|
2022-03-25 17:43:32 +03:00
|
|
|
showMessage(context, 'Log level set to $level');
|
2022-03-25 14:23:14 +03:00
|
|
|
},
|
|
|
|
),
|
2022-06-02 15:53:29 +03:00
|
|
|
const SizedBox(height: 12.0),
|
2022-05-25 17:10:26 +03:00
|
|
|
OutlinedButton.icon(
|
|
|
|
icon: const Icon(Icons.copy),
|
2022-06-02 15:53:29 +03:00
|
|
|
label: const Text('Copy log to clipboard'),
|
2022-03-25 14:23:14 +03:00
|
|
|
onPressed: () async {
|
2022-05-17 10:10:23 +03:00
|
|
|
_log.info('Copying log to clipboard ($version)...');
|
2022-05-11 16:47:35 +03:00
|
|
|
final logs = await ref.read(logLevelProvider.notifier).getLogs();
|
|
|
|
await Clipboard.setData(ClipboardData(text: logs.join('\n')));
|
2022-05-12 09:34:51 +03:00
|
|
|
await ref.read(withContextProvider)(
|
|
|
|
(context) async {
|
|
|
|
showMessage(context, 'Log copied to clipboard');
|
|
|
|
},
|
|
|
|
);
|
2022-03-25 14:23:14 +03:00
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2022-06-02 15:53:29 +03:00
|
|
|
|
|
|
|
class UrlLink extends StatefulWidget {
|
|
|
|
final String text;
|
|
|
|
final String url;
|
|
|
|
|
|
|
|
const UrlLink({super.key, required this.text, required this.url});
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() => _UrlLinkState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _UrlLinkState extends State<UrlLink> {
|
|
|
|
late TapGestureRecognizer _tapRecognizer;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
_tapRecognizer = TapGestureRecognizer();
|
|
|
|
_tapRecognizer.onTap = () {
|
2022-06-02 16:37:18 +03:00
|
|
|
//TODO: use url_launcher
|
|
|
|
// ignore: avoid_print
|
|
|
|
print('TODO: Go to ${widget.url}');
|
2022-06-02 15:53:29 +03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
_tapRecognizer.dispose();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return RichText(
|
|
|
|
text: TextSpan(
|
|
|
|
text: widget.text,
|
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).colorScheme.primary,
|
|
|
|
decoration: TextDecoration.underline,
|
|
|
|
),
|
|
|
|
recognizer: _tapRecognizer,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|