A cross platform Audiobookshelf client for Android and iOS
Dart
Reload per-account state after fresh login, not just account switch
Barnabasefa641c1868a
diff --git a/lib/providers/auth_provider.dart b/lib/providers/auth_provider.dartindex 073c1560..1118c51e 100644--- a/lib/providers/auth_provider.dart+++ b/lib/providers/auth_provider.dart@@ -318,6 +318,8 @@ class AuthProvider extends ChangeNotifier {));} catch (_) {}+ await _onAccountActivated();+// Wipe any previous user's stats from the widget and pull this user's.await HomeWidgetService().clearStats();HomeWidgetService().refreshStats(force: true);@@ -403,6 +405,8 @@ class AuthProvider extends ChangeNotifier {));} catch (_) {}+ await _onAccountActivated();+await HomeWidgetService().clearStats();HomeWidgetService().refreshStats(force: true);@@ -484,6 +488,8 @@ class AuthProvider extends ChangeNotifier {));} catch (_) {}+ await _onAccountActivated();+// Wipe any previous user's stats from the widget and pull this user's.await HomeWidgetService().clearStats();HomeWidgetService().refreshStats(force: true);@@ -502,6 +508,31 @@ class AuthProvider extends ChangeNotifier {}}+ /// Refresh in-memory state to match the now-active account's scope. Call+ /// after `UserAccountService.saveAccount()` so settings cached from the+ /// previous account don't leak across. The big one is the local-server+ /// override: if left stale, API calls route to the previous account's+ /// local URL with the new account's token, producing 401s.+ Future<void> _onAccountActivated() async {+ PlayerSettings.notifySettingsChanged();+ await EqualizerService().reloadForActiveAccount();++ await _loadLocalServerSettings();+ _useLocalServer = false;+ if (_localServerEnabled && _localServerUrl.isNotEmpty) {+ final connectivity = await Connectivity().checkConnectivity();+ if (connectivity.contains(ConnectivityResult.wifi)) {+ final localReachable = await ApiService.pingServer(+ _localServerUrl, customHeaders: _customHeaders)+ .timeout(const Duration(seconds: 2), onTimeout: () => false);+ if (localReachable) {+ debugPrint('[Auth] Local server reachable - using local');+ _useLocalServer = true;+ }+ }+ }+ }+/// Check if the configured local server is reachable./// Called on WiFi connectivity changes by LibraryProvider.Future<void> checkLocalServer() async {