mirror of
https://github.com/kodjodevf/mangayomi.git
synced 2026-01-11 22:40:36 +00:00
Add logging and detailed botToast, remove doWhile
- Use the logger to log failed updates - After the update-botToast another botToast is being spawned to show exactly which manga(s) couldn't be updated. - Remove the doWhile loop because it is unnecessary. The condition of mangaList.length == numbers is always true, meaning it only runs once.
This commit is contained in:
parent
9bd8a62d31
commit
c911594e73
1 changed files with 22 additions and 12 deletions
|
|
@ -6,6 +6,7 @@ import 'package:mangayomi/modules/manga/detail/providers/update_manga_detail_pro
|
|||
import 'package:mangayomi/modules/more/settings/appearance/providers/theme_mode_state_provider.dart';
|
||||
import 'package:mangayomi/providers/l10n_providers.dart';
|
||||
import 'package:mangayomi/utils/extensions/build_context_extensions.dart';
|
||||
import 'package:mangayomi/utils/log/logger.dart';
|
||||
import 'package:mangayomi/models/manga.dart';
|
||||
|
||||
Future<void> updateLibrary({
|
||||
|
|
@ -14,6 +15,7 @@ Future<void> updateLibrary({
|
|||
required List<Manga> mangaList,
|
||||
required ItemType itemType,
|
||||
}) async {
|
||||
AppLogger.log("Updating $itemType library...");
|
||||
bool isDark = ref.read(themeModeStateProvider);
|
||||
botToast(
|
||||
context.l10n.updating_library("0", "0", "0"),
|
||||
|
|
@ -22,9 +24,10 @@ Future<void> updateLibrary({
|
|||
alignY: !context.isTablet ? 0.85 : 1,
|
||||
themeDark: isDark,
|
||||
);
|
||||
int numbers = 0;
|
||||
int failed = 0;
|
||||
for (var manga in mangaList) {
|
||||
List<String> failedMangas = [];
|
||||
for (var i = 0; i < mangaList.length; i++) {
|
||||
final manga = mangaList[i];
|
||||
try {
|
||||
await ref.read(
|
||||
updateMangaDetailProvider(
|
||||
|
|
@ -33,13 +36,15 @@ Future<void> updateLibrary({
|
|||
showToast: false,
|
||||
).future,
|
||||
);
|
||||
} catch (_) {
|
||||
} catch (e) {
|
||||
AppLogger.log("Failed to update $itemType:", logLevel: LogLevel.error);
|
||||
AppLogger.log(e.toString(), logLevel: LogLevel.error);
|
||||
failed++;
|
||||
failedMangas.add(manga.name ?? "Unknown $itemType");
|
||||
}
|
||||
numbers++;
|
||||
if (context.mounted) {
|
||||
botToast(
|
||||
context.l10n.updating_library(numbers, failed, mangaList.length),
|
||||
context.l10n.updating_library(i + 1, failed, mangaList.length),
|
||||
fontSize: 13,
|
||||
second: 10,
|
||||
alignY: !context.isTablet ? 0.85 : 1,
|
||||
|
|
@ -50,12 +55,17 @@ Future<void> updateLibrary({
|
|||
);
|
||||
}
|
||||
}
|
||||
await Future.doWhile(() async {
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
if (mangaList.length == numbers) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
BotToast.cleanAll();
|
||||
if (context.mounted && failedMangas.isNotEmpty) {
|
||||
final failedListText = failedMangas.map((m) => "• $m").join('\n');
|
||||
final plural = failed == 1 ? itemType : "${itemType}s";
|
||||
botToast(
|
||||
"Failed to update $failed $plural:\n$failedListText",
|
||||
fontSize: 13,
|
||||
second: 10,
|
||||
alignY: !context.isTablet ? 0.85 : 1,
|
||||
themeDark: isDark,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue