Skip to content

Commit

Permalink
Show a snackbar if there are no logs to download
Browse files Browse the repository at this point in the history
Throw an exception in the logs layer if there are no exported log files to share.
Catch the error and show a snackbar.
  • Loading branch information
takenagain committed Dec 7, 2023
1 parent 6379ee6 commit 1fd20e8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
17 changes: 14 additions & 3 deletions lib/screens/authentification/authenticate_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
),
);
}
}

Expand Down
15 changes: 14 additions & 1 deletion lib/screens/settings/setting_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,20 @@ class _SettingPageState extends State<SettingPage> {
Future<void> _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<void> _shareFileDialog() async {
Expand Down
3 changes: 3 additions & 0 deletions lib/utils/log.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 1fd20e8

Please sign in to comment.