2022-03-25 14:23:14 +03:00
|
|
|
import 'dart:convert';
|
2021-11-24 13:38:30 +03:00
|
|
|
import 'dart:io';
|
|
|
|
|
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-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 {
|
2021-11-19 17:05:57 +03:00
|
|
|
const AboutPage({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@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-03-25 14:23:14 +03:00
|
|
|
title: const Text('Yubico Authenticator'),
|
2022-03-15 20:04:26 +03:00
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
// TODO: Store the version number elsewhere
|
2022-04-07 14:12:27 +03:00
|
|
|
const Text('Yubico Authenticator: 6.0.0-alpha.2'),
|
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(),
|
2022-03-25 14:23:14 +03:00
|
|
|
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', []);
|
2022-03-25 14:23:14 +03:00
|
|
|
final data = response['diagnostics'];
|
|
|
|
final text = const JsonEncoder.withIndent(' ').convert(data);
|
|
|
|
await Clipboard.setData(ClipboardData(text: text));
|
2022-03-25 17:43:32 +03:00
|
|
|
showMessage(context, 'Diagnostic data copied to clipboard');
|
2022-03-15 20:04:26 +03:00
|
|
|
},
|
|
|
|
child: const Text('Run diagnostics...'),
|
|
|
|
),
|
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 {
|
|
|
|
const LoggingPanel({Key? key}) : super(key: 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,
|
|
|
|
items: [Level.WARNING, Level.INFO, Level.CONFIG, Level.FINE]
|
|
|
|
.map((e) => DropdownMenuItem(
|
|
|
|
value: e,
|
|
|
|
child: Text(e.name.toUpperCase()),
|
|
|
|
))
|
|
|
|
.toList(),
|
|
|
|
onChanged: (level) {
|
|
|
|
ref.read(logLevelProvider.notifier).setLogLevel(level!);
|
|
|
|
_log.config('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
|
|
|
},
|
|
|
|
),
|
|
|
|
const SizedBox(width: 8.0),
|
|
|
|
OutlinedButton(
|
|
|
|
child: const Text('Copy log'),
|
|
|
|
onPressed: () async {
|
|
|
|
_log.info('Copying log to clipboard...');
|
|
|
|
final logs = LogBuffer.of(context).getLogs().join('\n');
|
|
|
|
await Clipboard.setData(ClipboardData(text: logs));
|
2022-03-25 17:43:32 +03:00
|
|
|
showMessage(context, 'Log copied to clipboard');
|
2022-03-25 14:23:14 +03:00
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|