A cross platform Audiobookshelf client for Android and iOS
Dart
Fix tag and genre chip taps from full player and on cold start
Barnabas1a76d98990fb
diff --git a/lib/screens/app_shell.dart b/lib/screens/app_shell.dartindex 73f23898..4bf253a1 100644--- a/lib/screens/app_shell.dart+++ b/lib/screens/app_shell.dart@@ -73,7 +73,21 @@ class AppShell extends StatefulWidget {void Function(LibraryScreenState) apply) {final inst = _AppShellState._instance;if (inst == null) return false;+ // If the full-screen expanded player is on top of the shell, pop it+ // first. Otherwise switching to the Library tab leaves the player+ // covering the filtered library underneath. Caller (e.g. the book+ // detail sheet) has already popped its own modal route at this point.+ if (inst._expandedIsOpen && inst.mounted) {+ Navigator.of(inst.context, rootNavigator: true).maybePop();+ }inst._navigateTo(1);+ // The retry budget has to survive the fade transition (~200ms by+ // default, see `_fadeController` and `_navigateTo`) plus the library+ // widget's own mount + first build. On cold start that easily takes+ // 300-500ms before `_libraryKey.currentState` becomes non-null. ~3s+ // worth of frames is generous enough to cover slow devices and stingy+ // enough to give up if something is genuinely broken.+ const maxAttempts = 180; // ~3s at 60fpsvar attempts = 0;void tryApply() {if (!inst.mounted) return;@@ -82,7 +96,7 @@ class AppShell extends StatefulWidget {apply(state);return;}- if (++attempts < 10) {+ if (++attempts < maxAttempts) {WidgetsBinding.instance.addPostFrameCallback((_) => tryApply());}}diff --git a/lib/screens/library_screen.dart b/lib/screens/library_screen.dartindex 998ac434..b1b076ed 100644--- a/lib/screens/library_screen.dart+++ b/lib/screens/library_screen.dart@@ -128,6 +128,14 @@ class LibraryScreenState extends State<LibraryScreen> with TickerProviderStateMiLibraryFilter _filter = LibraryFilter.none;String? _genreFilter;String? _tagFilter;++ /// Set to true the first time the user (or a chip tap via+ /// AppShell.openLibraryWith*FilterGlobal) explicitly changes the filter.+ /// `_restoreSortFilter` checks this before overwriting filter state from+ /// SharedPreferences — fixes the cold-start race where a tag/genre chip+ /// tap on a freshly opened app got clobbered by the prefs restore that+ /// runs in postFrame right after the library widget mounts.+ bool _filterOverriddenByUser = false;List<String> _availableGenres = [];List<String> _availableTags = [];bool _hideEbookOnly = false;@@ -293,6 +301,10 @@ class LibraryScreenState extends State<LibraryScreen> with TickerProviderStateMi_allNarratorsCache = null;_allNarratorsCacheLibraryId = null;_searchNarratorResults = [];+ // New library, so any prior chip-driven override no longer+ // applies — let `_restoreSortFilter` set the new library's+ // saved filter freely.+ _filterOverriddenByUser = false;});_revealDriver.resetToShown();// Restore sort/filter for the new library type, then load@@ -371,12 +383,18 @@ class LibraryScreenState extends State<LibraryScreen> with TickerProviderStateMi);_sortAsc = sortAsc;if (_sort == LibrarySort.random) _randomSeed = Random().nextInt(100000);- _filter = LibraryFilter.values.firstWhere(- (f) => f.name == filterName,- orElse: () => LibraryFilter.none,- );- _genreFilter = genreFilter.isNotEmpty ? genreFilter : null;- _tagFilter = tagFilter.isNotEmpty ? tagFilter : null;+ // Don't restore filter from prefs if the user (typically via a+ // chip tap from an open detail sheet) already set one during this+ // session — that race would otherwise undo their selection on cold+ // start when the library widget is mounting for the first time.+ if (!_filterOverriddenByUser) {+ _filter = LibraryFilter.values.firstWhere(+ (f) => f.name == filterName,+ orElse: () => LibraryFilter.none,+ );+ _genreFilter = genreFilter.isNotEmpty ? genreFilter : null;+ _tagFilter = tagFilter.isNotEmpty ? tagFilter : null;+ }_seriesSort = LibrarySort.values.firstWhere((s) => s.name == seriesSortName,orElse: () => LibrarySort.alphabetical,@@ -1138,6 +1156,7 @@ class LibraryScreenState extends State<LibraryScreen> with TickerProviderStateMi_page = 0;_hasMore = true;_isLoadingPage = false;+ _filterOverriddenByUser = true;});if (!isPodcast) {PlayerSettings.setLibraryFilter(_filter.name);