A cross platform Audiobookshelf client for Android and iOS
Dart
Log what happens to the library list when the app starts offline
Barnabasa4aa112e7807
diff --git a/lib/providers/_lp_core.dart b/lib/providers/_lp_core.dartindex ace085df..60e98dfe 100644--- a/lib/providers/_lp_core.dart+++ b/lib/providers/_lp_core.dart@@ -460,7 +460,8 @@ mixin _CoreMixin on ChangeNotifier, _StateMixin {return (dl.itemId.length > 36) == isPodcast;}).toList();debugPrint(- '[Library] Building offline sections: ${downloads.length}/${allDownloads.length} downloads (${isPodcast ? "podcast" : "book"})');+ '[Library] Building offline sections: ${downloads.length}/${allDownloads.length} downloads (${isPodcast ? "podcast" : "book"}) '+ 'library=$_selectedLibraryId of ${_libraries.length}');if (downloads.isEmpty) {_personalizedSections = [];_errorMessage = null;diff --git a/lib/providers/library_provider.dart b/lib/providers/library_provider.dartindex c2283160..cd134ddc 100644--- a/lib/providers/library_provider.dart+++ b/lib/providers/library_provider.dart@@ -206,7 +206,13 @@ class LibraryProvider extends ChangeNotifier_buildProgressMap(auth);if (!auth.serverReachable) {- debugPrint('[Library] Server not reachable — going offline');+ debugPrint(+ '[Library] Server not reachable — going offline with ${_libraries.length} libraries '+ '(fromCache=$_librariesFromCache selected=$_selectedLibraryId)');+ unawaited(PlayerSettings.getPodcastTabEnabled().then((on) async {+ final tabLib = await PlayerSettings.getPodcastTabLibraryId();+ debugPrint('[Library] Offline start: podcast tab=$on library=$tabLib');+ }));_networkOffline = true;_buildOfflineSections();_isLoading = false;@@ -310,6 +316,7 @@ class LibraryProvider extends ChangeNotifier_libraries = fetched;_librariesFromCache = false;await LibraryCache.save(fetched);+ debugPrint('[Library] Saved ${fetched.length} libraries for offline starts');await _restoreSelectedLibrary();await _loadSectionPrefs();@@ -341,9 +348,18 @@ class LibraryProvider extends ChangeNotifier}Future<void> _restoreCachedLibraries() async {- if (_libraries.isNotEmpty) return;+ if (_libraries.isNotEmpty) {+ debugPrint(+ '[Library] Cached libraries not needed, already have ${_libraries.length}');+ return;+ }final cached = await LibraryCache.load();- if (cached.isEmpty) return;+ if (cached.isEmpty) {+ // Nothing saved while online, so offline there is one library at most+ // and the switcher stays hidden (#313).+ debugPrint('[Library] No saved libraries to restore for offline use');+ return;+ }// Widened copy: handing the cache's List<Map> to the List<dynamic> field// directly would tighten the runtime type and blow up firstWhere calls// whose orElse returns null.@@ -363,10 +379,13 @@ class LibraryProvider extends ChangeNotifierfinal defaultId = _auth?.defaultLibraryId;if (savedId != null && _libraries.any((l) => l['id'] == savedId)) {_selectedLibraryId = savedId;+ debugPrint('[Library] Selected library $savedId (last used)');return;}if (defaultId != null && _libraries.any((l) => l['id'] == defaultId)) {_selectedLibraryId = defaultId;+ debugPrint(+ '[Library] Selected library $defaultId (server default, last used was $savedId)');return;}final bookLibraries = _libraries@@ -376,9 +395,14 @@ class LibraryProvider extends ChangeNotifier_selectedLibraryId = bookLibraries.isNotEmpty? bookLibraries.first['id'] as String?: _libraries.first['id'] as String?;+ debugPrint(+ '[Library] Selected library $_selectedLibraryId (first book library, last used was $savedId)');}Future<void> selectLibrary(String libraryId) async {+ debugPrint(+ '[Library] selectLibrary $libraryId (podcast=${isPodcastLibraryId(libraryId)} '+ 'offline=$isOffline libraries=${_libraries.length})');// When Merge Libraries is on, the absorbing card stays visible across// libraries so the user can still control playback. Only stop on switch// when merge is off, otherwise the player would be unreachable from the