yubioath-flutter/lib/about_page.dart

105 lines
3.3 KiB
Dart
Raw Normal View History

import 'dart:convert';
import 'dart:io';
2021-11-19 17:05:57 +03:00
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:logging/logging.dart';
2022-05-12 09:34:51 +03:00
import 'package:yubico_authenticator/app/state.dart';
2022-05-13 11:46:36 +03:00
import 'version.dart';
import 'app/logging.dart';
2022-03-25 17:43:32 +03:00
import 'app/message.dart';
import 'core/state.dart';
import 'desktop/state.dart';
import 'widgets/responsive_dialog.dart';
final _log = Logger('about');
2021-11-19 17:05:57 +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
Widget build(BuildContext context, WidgetRef ref) {
2022-03-15 20:04:26 +03:00
return ResponsiveDialog(
title: const Text('Yubico Authenticator'),
2022-03-15 20:04:26 +03:00
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
2022-05-13 11:46:36 +03:00
const Text('Yubico Authenticator: $version'),
2022-03-15 20:04:26 +03:00
if (isDesktop)
Text('ykman version: ${ref.watch(rpcStateProvider).version}'),
Text('Dart version: ${Platform.version}'),
const SizedBox(height: 8.0),
const Divider(),
const LoggingPanel(),
if (isDesktop) ...[
const Divider(),
OutlinedButton(
2022-03-15 20:04:26 +03:00
onPressed: () async {
_log.info('Running diagnostics...');
final response =
await ref.read(rpcProvider).command('diagnose', []);
final data = response['diagnostics'] as List;
data.insert(0, {'app_version': version});
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
},
child: const Text('Run diagnostics...'),
),
]
2022-03-15 20:04:26 +03:00
],
2021-11-19 17:05:57 +03:00
),
);
}
}
class LoggingPanel extends ConsumerWidget {
2022-05-12 10:56:55 +03:00
const LoggingPanel({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
return Row(
children: [
const Text('Log level:'),
const SizedBox(width: 8.0),
DropdownButton<Level>(
value: ref.watch(logLevelProvider),
isDense: true,
2022-05-03 12:24:25 +03:00
items: Levels.LEVELS
.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');
},
),
const SizedBox(width: 8.0),
OutlinedButton(
child: const Text('Copy log'),
onPressed: () async {
_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');
},
);
},
),
],
);
}
}