Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Refresh library data when active server switches

Barnabasf09aad1ab6be
diff --git a/lib/providers/_lp_state.dart b/lib/providers/_lp_state.dart
index 198ededd..f1e94344 100644
--- a/lib/providers/_lp_state.dart
+++ b/lib/providers/_lp_state.dart
@@ -86,6 +86,7 @@ mixin _StateMixin on ChangeNotifier {
StreamSubscription? _connectivitySub;
bool _listeningToDownloads = false;
String? _lastAuthKey;
+ bool? _lastUseLocalServer;
final Map<String, Set<String>> _knownEpisodeIds = {};
diff --git a/lib/providers/library_provider.dart b/lib/providers/library_provider.dart
index 45b52d69..f58b641b 100644
--- a/lib/providers/library_provider.dart
+++ b/lib/providers/library_provider.dart
@@ -75,7 +75,23 @@ class LibraryProvider extends ChangeNotifier
'[Library] updateAuth: key=$authKey lastKey=$_lastAuthKey isNewUser=$isNewUser isFreshLogin=$isFreshLogin isDuplicate=$isDuplicate');
_lastAuthKey = authKey;
- if (isDuplicate) return;
+ if (isDuplicate) {
+ // The remote auth key didn't change, but the active server URL might
+ // have flipped (local <-> remote). When it does, library data was
+ // fetched from the OLD server and the home page can render with stale
+ // or empty sections. Refresh once on each transition.
+ if (_lastUseLocalServer != null && _lastUseLocalServer != auth.useLocalServer) {
+ _lastUseLocalServer = auth.useLocalServer;
+ if (!_networkOffline && !_manualOffline) {
+ debugPrint('[Library] Active server switched - refreshing library data');
+ refresh();
+ }
+ } else {
+ _lastUseLocalServer = auth.useLocalServer;
+ }
+ return;
+ }
+ _lastUseLocalServer = auth.useLocalServer;
if (isNewUser || isFreshLogin) {
_libraries = [];
@@ -160,6 +176,7 @@ class LibraryProvider extends ChangeNotifier
});
} else {
_lastAuthKey = null;
+ _lastUseLocalServer = null;
_idleDisconnectTimer?.cancel();
_idleDisconnectTimer = null;
_libraries = [];