A cross platform Audiobookshelf client for Android and iOS
Dart
Say why a download failed instead of just going back to the download button
Barnabasb58b7e97039a
diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arbindex 1b71a1d9..db2a11ec 100644--- a/lib/l10n/app_en.arb+++ b/lib/l10n/app_en.arb@@ -351,6 +351,38 @@}}},+ "downloadFailedMissingFile": "Couldn't download \"{title}\" - one of its files isn't on the server. A library scan may fix it.",+ "@downloadFailedMissingFile": {+ "placeholders": {+ "title": {+ "type": "String"+ }+ }+ },+ "downloadFailedNoSpace": "Couldn't download \"{title}\" - not enough storage space",+ "@downloadFailedNoSpace": {+ "placeholders": {+ "title": {+ "type": "String"+ }+ }+ },+ "downloadFailedPermission": "Couldn't download \"{title}\" - check the download location in Settings",+ "@downloadFailedPermission": {+ "placeholders": {+ "title": {+ "type": "String"+ }+ }+ },+ "downloadFailedGeneric": "Couldn't download \"{title}\"",+ "@downloadFailedGeneric": {+ "placeholders": {+ "title": {+ "type": "String"+ }+ }+ },"downloadsSelectedCount": "{count} selected","@downloadsSelectedCount": {"placeholders": {diff --git a/lib/l10n/app_localizations.dart b/lib/l10n/app_localizations.dartindex 538cf8a1..541ca3cc 100644--- a/lib/l10n/app_localizations.dart+++ b/lib/l10n/app_localizations.dart@@ -1480,6 +1480,30 @@ abstract class AppLocalizations {/// **'\"{title}\" removed'**String downloadsRemovedTitle(String title);+ /// No description provided for @downloadFailedMissingFile.+ ///+ /// In en, this message translates to:+ /// **'Couldn\'t download \"{title}\" - one of its files isn\'t on the server. A library scan may fix it.'**+ String downloadFailedMissingFile(String title);++ /// No description provided for @downloadFailedNoSpace.+ ///+ /// In en, this message translates to:+ /// **'Couldn\'t download \"{title}\" - not enough storage space'**+ String downloadFailedNoSpace(String title);++ /// No description provided for @downloadFailedPermission.+ ///+ /// In en, this message translates to:+ /// **'Couldn\'t download \"{title}\" - check the download location in Settings'**+ String downloadFailedPermission(String title);++ /// No description provided for @downloadFailedGeneric.+ ///+ /// In en, this message translates to:+ /// **'Couldn\'t download \"{title}\"'**+ String downloadFailedGeneric(String title);+/// No description provided for @downloadsSelectedCount.////// In en, this message translates to:diff --git a/lib/l10n/app_localizations_de.dart b/lib/l10n/app_localizations_de.dartindex 01348bf4..3737dfd8 100644--- a/lib/l10n/app_localizations_de.dart+++ b/lib/l10n/app_localizations_de.dart@@ -761,6 +761,26 @@ class AppLocalizationsDe extends AppLocalizations {return '\"$title\" entfernt';}+ @override+ String downloadFailedMissingFile(String title) {+ return 'Couldn\'t download \"$title\" - one of its files isn\'t on the server. A library scan may fix it.';+ }++ @override+ String downloadFailedNoSpace(String title) {+ return 'Couldn\'t download \"$title\" - not enough storage space';+ }++ @override+ String downloadFailedPermission(String title) {+ return 'Couldn\'t download \"$title\" - check the download location in Settings';+ }++ @override+ String downloadFailedGeneric(String title) {+ return 'Couldn\'t download \"$title\"';+ }+@overrideString downloadsSelectedCount(int count) {return '$count ausgewählt';diff --git a/lib/l10n/app_localizations_el.dart b/lib/l10n/app_localizations_el.dartindex e5bc34c7..214d026f 100644--- a/lib/l10n/app_localizations_el.dart+++ b/lib/l10n/app_localizations_el.dart@@ -754,6 +754,26 @@ class AppLocalizationsEl extends AppLocalizations {return '\"$title\" removed';}+ @override+ String downloadFailedMissingFile(String title) {+ return 'Couldn\'t download \"$title\" - one of its files isn\'t on the server. A library scan may fix it.';+ }++ @override+ String downloadFailedNoSpace(String title) {+ return 'Couldn\'t download \"$title\" - not enough storage space';+ }++ @override+ String downloadFailedPermission(String title) {+ return 'Couldn\'t download \"$title\" - check the download location in Settings';+ }++ @override+ String downloadFailedGeneric(String title) {+ return 'Couldn\'t download \"$title\"';+ }+@overrideString downloadsSelectedCount(int count) {return '$count selected';diff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dartindex e94c79b7..21bdd9f3 100644--- a/lib/l10n/app_localizations_en.dart+++ b/lib/l10n/app_localizations_en.dart@@ -754,6 +754,26 @@ class AppLocalizationsEn extends AppLocalizations {return '\"$title\" removed';}+ @override+ String downloadFailedMissingFile(String title) {+ return 'Couldn\'t download \"$title\" - one of its files isn\'t on the server. A library scan may fix it.';+ }++ @override+ String downloadFailedNoSpace(String title) {+ return 'Couldn\'t download \"$title\" - not enough storage space';+ }++ @override+ String downloadFailedPermission(String title) {+ return 'Couldn\'t download \"$title\" - check the download location in Settings';+ }++ @override+ String downloadFailedGeneric(String title) {+ return 'Couldn\'t download \"$title\"';+ }+@overrideString downloadsSelectedCount(int count) {return '$count selected';diff --git a/lib/l10n/app_localizations_es.dart b/lib/l10n/app_localizations_es.dartindex f78c45e3..30f53e70 100644--- a/lib/l10n/app_localizations_es.dart+++ b/lib/l10n/app_localizations_es.dart@@ -756,6 +756,26 @@ class AppLocalizationsEs extends AppLocalizations {return '\"$title\" removed';}+ @override+ String downloadFailedMissingFile(String title) {+ return 'Couldn\'t download \"$title\" - one of its files isn\'t on the server. A library scan may fix it.';+ }++ @override+ String downloadFailedNoSpace(String title) {+ return 'Couldn\'t download \"$title\" - not enough storage space';+ }++ @override+ String downloadFailedPermission(String title) {+ return 'Couldn\'t download \"$title\" - check the download location in Settings';+ }++ @override+ String downloadFailedGeneric(String title) {+ return 'Couldn\'t download \"$title\"';+ }+@overrideString downloadsSelectedCount(int count) {return '$count selected';diff --git a/lib/l10n/app_localizations_fr.dart b/lib/l10n/app_localizations_fr.dartindex f0bea7d8..de8ad8c8 100644--- a/lib/l10n/app_localizations_fr.dart+++ b/lib/l10n/app_localizations_fr.dart@@ -762,6 +762,26 @@ class AppLocalizationsFr extends AppLocalizations {return '\"$title\" supprimé';}+ @override+ String downloadFailedMissingFile(String title) {+ return 'Couldn\'t download \"$title\" - one of its files isn\'t on the server. A library scan may fix it.';+ }++ @override+ String downloadFailedNoSpace(String title) {+ return 'Couldn\'t download \"$title\" - not enough storage space';+ }++ @override+ String downloadFailedPermission(String title) {+ return 'Couldn\'t download \"$title\" - check the download location in Settings';+ }++ @override+ String downloadFailedGeneric(String title) {+ return 'Couldn\'t download \"$title\"';+ }+@overrideString downloadsSelectedCount(int count) {return '$count sélectionné(s)';diff --git a/lib/l10n/app_localizations_it.dart b/lib/l10n/app_localizations_it.dartindex d6d99dc9..6a690e42 100644--- a/lib/l10n/app_localizations_it.dart+++ b/lib/l10n/app_localizations_it.dart@@ -754,6 +754,26 @@ class AppLocalizationsIt extends AppLocalizations {return '\"$title\" removed';}+ @override+ String downloadFailedMissingFile(String title) {+ return 'Couldn\'t download \"$title\" - one of its files isn\'t on the server. A library scan may fix it.';+ }++ @override+ String downloadFailedNoSpace(String title) {+ return 'Couldn\'t download \"$title\" - not enough storage space';+ }++ @override+ String downloadFailedPermission(String title) {+ return 'Couldn\'t download \"$title\" - check the download location in Settings';+ }++ @override+ String downloadFailedGeneric(String title) {+ return 'Couldn\'t download \"$title\"';+ }+@overrideString downloadsSelectedCount(int count) {return '$count selected';diff --git a/lib/l10n/app_localizations_ja.dart b/lib/l10n/app_localizations_ja.dartindex 7efe1b29..ec25170e 100644--- a/lib/l10n/app_localizations_ja.dart+++ b/lib/l10n/app_localizations_ja.dart@@ -754,6 +754,26 @@ class AppLocalizationsJa extends AppLocalizations {return '\"$title\" removed';}+ @override+ String downloadFailedMissingFile(String title) {+ return 'Couldn\'t download \"$title\" - one of its files isn\'t on the server. A library scan may fix it.';+ }++ @override+ String downloadFailedNoSpace(String title) {+ return 'Couldn\'t download \"$title\" - not enough storage space';+ }++ @override+ String downloadFailedPermission(String title) {+ return 'Couldn\'t download \"$title\" - check the download location in Settings';+ }++ @override+ String downloadFailedGeneric(String title) {+ return 'Couldn\'t download \"$title\"';+ }+@overrideString downloadsSelectedCount(int count) {return '$count selected';diff --git a/lib/l10n/app_localizations_no.dart b/lib/l10n/app_localizations_no.dartindex e4a70093..4c761693 100644--- a/lib/l10n/app_localizations_no.dart+++ b/lib/l10n/app_localizations_no.dart@@ -754,6 +754,26 @@ class AppLocalizationsNo extends AppLocalizations {return '\"$title\" removed';}+ @override+ String downloadFailedMissingFile(String title) {+ return 'Couldn\'t download \"$title\" - one of its files isn\'t on the server. A library scan may fix it.';+ }++ @override+ String downloadFailedNoSpace(String title) {+ return 'Couldn\'t download \"$title\" - not enough storage space';+ }++ @override+ String downloadFailedPermission(String title) {+ return 'Couldn\'t download \"$title\" - check the download location in Settings';+ }++ @override+ String downloadFailedGeneric(String title) {+ return 'Couldn\'t download \"$title\"';+ }+@overrideString downloadsSelectedCount(int count) {return '$count selected';diff --git a/lib/l10n/app_localizations_pt.dart b/lib/l10n/app_localizations_pt.dartindex 1be37d25..8e7ee503 100644--- a/lib/l10n/app_localizations_pt.dart+++ b/lib/l10n/app_localizations_pt.dart@@ -754,6 +754,26 @@ class AppLocalizationsPt extends AppLocalizations {return '\"$title\" removed';}+ @override+ String downloadFailedMissingFile(String title) {+ return 'Couldn\'t download \"$title\" - one of its files isn\'t on the server. A library scan may fix it.';+ }++ @override+ String downloadFailedNoSpace(String title) {+ return 'Couldn\'t download \"$title\" - not enough storage space';+ }++ @override+ String downloadFailedPermission(String title) {+ return 'Couldn\'t download \"$title\" - check the download location in Settings';+ }++ @override+ String downloadFailedGeneric(String title) {+ return 'Couldn\'t download \"$title\"';+ }+@overrideString downloadsSelectedCount(int count) {return '$count selected';diff --git a/lib/l10n/app_localizations_ro.dart b/lib/l10n/app_localizations_ro.dartindex 4dd72f13..f71d2f79 100644--- a/lib/l10n/app_localizations_ro.dart+++ b/lib/l10n/app_localizations_ro.dart@@ -754,6 +754,26 @@ class AppLocalizationsRo extends AppLocalizations {return '\"$title\" removed';}+ @override+ String downloadFailedMissingFile(String title) {+ return 'Couldn\'t download \"$title\" - one of its files isn\'t on the server. A library scan may fix it.';+ }++ @override+ String downloadFailedNoSpace(String title) {+ return 'Couldn\'t download \"$title\" - not enough storage space';+ }++ @override+ String downloadFailedPermission(String title) {+ return 'Couldn\'t download \"$title\" - check the download location in Settings';+ }++ @override+ String downloadFailedGeneric(String title) {+ return 'Couldn\'t download \"$title\"';+ }+@overrideString downloadsSelectedCount(int count) {return '$count selected';diff --git a/lib/l10n/app_localizations_ru.dart b/lib/l10n/app_localizations_ru.dartindex 622ff72e..7246f7c7 100644--- a/lib/l10n/app_localizations_ru.dart+++ b/lib/l10n/app_localizations_ru.dart@@ -754,6 +754,26 @@ class AppLocalizationsRu extends AppLocalizations {return '\"$title\" удалено';}+ @override+ String downloadFailedMissingFile(String title) {+ return 'Couldn\'t download \"$title\" - one of its files isn\'t on the server. A library scan may fix it.';+ }++ @override+ String downloadFailedNoSpace(String title) {+ return 'Couldn\'t download \"$title\" - not enough storage space';+ }++ @override+ String downloadFailedPermission(String title) {+ return 'Couldn\'t download \"$title\" - check the download location in Settings';+ }++ @override+ String downloadFailedGeneric(String title) {+ return 'Couldn\'t download \"$title\"';+ }+@overrideString downloadsSelectedCount(int count) {return '$count выбрано';diff --git a/lib/l10n/app_localizations_zh.dart b/lib/l10n/app_localizations_zh.dartindex 8df1c18e..3986dfa8 100644--- a/lib/l10n/app_localizations_zh.dart+++ b/lib/l10n/app_localizations_zh.dart@@ -743,6 +743,26 @@ class AppLocalizationsZh extends AppLocalizations {return '\"$title\" 已移除';}+ @override+ String downloadFailedMissingFile(String title) {+ return 'Couldn\'t download \"$title\" - one of its files isn\'t on the server. A library scan may fix it.';+ }++ @override+ String downloadFailedNoSpace(String title) {+ return 'Couldn\'t download \"$title\" - not enough storage space';+ }++ @override+ String downloadFailedPermission(String title) {+ return 'Couldn\'t download \"$title\" - check the download location in Settings';+ }++ @override+ String downloadFailedGeneric(String title) {+ return 'Couldn\'t download \"$title\"';+ }+@overrideString downloadsSelectedCount(int count) {return '已选择 $count 项';diff --git a/lib/services/download_service.dart b/lib/services/download_service.dartindex 22a30ee3..c8c17164 100644--- a/lib/services/download_service.dart+++ b/lib/services/download_service.dart@@ -12,6 +12,7 @@ import 'package:background_downloader/background_downloader.dart';import 'package:flutter_local_notifications/flutter_local_notifications.dart';import '../l10n/app_localizations.dart';import '../main.dart' show rootNavigatorKey;+import '../widgets/overlay_toast.dart';import 'api_service.dart';import 'audio_player_service.dart';import 'ebook_cache.dart';@@ -2327,10 +2328,37 @@ class DownloadService extends ChangeNotifier {await _deleteDbRecords(itemId, p?.trackCount ?? 0);_cancelledIds.remove(itemId);debugPrint('[Download] Failed "$t": $msg (${cause ?? taskException?.description})');+ _toastFailure(t, cause, taskException, responseCode);notifyListeners();unawaited(_processQueue());}+ /// A failed book used to just drop back to the download button, so a book+ /// whose server folder holds a file the server 404s looked like it never+ /// started (GH #310). Say what went wrong.+ void _toastFailure(+ String title, Object? cause, TaskException? te, int? code) {+ final navigator = rootNavigatorKey.currentState;+ if (navigator == null) return;+ final l = AppLocalizations.of(navigator.context);+ if (l == null) return;+ final s = '${cause ?? ''} ${te?.description ?? ''}'.toLowerCase();+ final String message;+ if (code == 404) {+ message = l.downloadFailedMissingFile(title);+ } else if (s.contains('no space') || s.contains('enospc')) {+ message = l.downloadFailedNoSpace(title);+ } else if (s.contains('permission') ||+ s.contains('not permitted') ||+ code == 403) {+ message = l.downloadFailedPermission(title);+ } else {+ message = l.downloadFailedGeneric(title);+ }+ showNavigatorOverlayToast(navigator, message,+ icon: Icons.error_outline_rounded);+ }+Future<void> _handleCanceled(String itemId) async {final p = _pending[itemId];// A canceled book still ends its group notification as "complete" (the