From 1fd20e87cb608bbf2ecb5eeac6b541e8c7e04359 Mon Sep 17 00:00:00 2001 From: Francois Date: Thu, 7 Dec 2023 18:11:46 +0200 Subject: [PATCH] Show a snackbar if there are no logs to download Throw an exception in the logs layer if there are no exported log files to share. Catch the error and show a snackbar. --- .../authentification/authenticate_page.dart | 17 ++++++++++++++--- lib/screens/settings/setting_page.dart | 15 ++++++++++++++- lib/utils/log.dart | 3 +++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/lib/screens/authentification/authenticate_page.dart b/lib/screens/authentification/authenticate_page.dart index 2b3e99ea..b85443b0 100644 --- a/lib/screens/authentification/authenticate_page.dart +++ b/lib/screens/authentification/authenticate_page.dart @@ -300,7 +300,7 @@ class _FullAppLogo extends StatelessWidget { @override Widget build(BuildContext context) { return RepeatedTapDetector( - onRepeatedTap: _downloadLogs, + onRepeatedTap: () => _downloadLogs(context), tapTriggerCount: 7, child: SizedBox( height: 240, @@ -315,8 +315,19 @@ class _FullAppLogo extends StatelessWidget { /// download the logs and share them via the system share sheet. This is so /// that users can download logs even if they can't access the settings page. /// E.g. if the app crashes on login. - void _downloadLogs() { - Log.downloadLogs().ignore(); + void _downloadLogs(BuildContext context) { + Log.downloadLogs().catchError((e) { + _showSnackbar(context, e.toString()); + }); + } + + void _showSnackbar(BuildContext context, String message) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text(message), + duration: const Duration(seconds: 3), + ), + ); } } diff --git a/lib/screens/settings/setting_page.dart b/lib/screens/settings/setting_page.dart index c43fef67..b9638a24 100644 --- a/lib/screens/settings/setting_page.dart +++ b/lib/screens/settings/setting_page.dart @@ -557,7 +557,20 @@ class _SettingPageState extends State { Future _shareLogs() async { Navigator.of(context).pop(); - Log.downloadLogs().ignore(); + Log.downloadLogs().catchError((dynamic e) { + _showSnackbar(e.toString()); + }); + } + + void _showSnackbar(String message) { + if (context == null) return; + + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text(message), + duration: const Duration(seconds: 3), + ), + ); } Future _shareFileDialog() async { diff --git a/lib/utils/log.dart b/lib/utils/log.dart index 4d14a18d..a7747a10 100644 --- a/lib/utils/log.dart +++ b/lib/utils/log.dart @@ -153,6 +153,9 @@ class Log { // Discord attachment size limit is about 25 MiB final exportedLogFiles = (await LogStorage().exportLogs()).map((f) => XFile(f.path)).toList(); + if (exportedLogFiles.isEmpty) { + throw Exception('No logs to download'); + } mainBloc.isUrlLaucherIsOpen = true;