A cross platform Audiobookshelf client for Android and iOS
Dart
Skip server fetch and show only Downloads tab in offline CarPlay
Barnabasf3aaf73e1342
diff --git a/lib/services/android_auto_service.dart b/lib/services/android_auto_service.dartindex e74cdd5d..58de553d 100644--- a/lib/services/android_auto_service.dart+++ b/lib/services/android_auto_service.dart@@ -6,6 +6,7 @@ import 'package:audio_service/audio_service.dart';import 'package:flutter/foundation.dart';import 'package:shared_preferences/shared_preferences.dart';import 'api_service.dart';+import 'audio_player_service.dart';import 'download_service.dart';import 'progress_sync_service.dart';import 'scoped_prefs.dart';@@ -399,7 +400,11 @@ class AndroidAutoService {final prefs = await SharedPreferences.getInstance();final manualOffline = prefs.getBool('manual_offline_mode') ?? false;- if (manualOffline) {+ // Skip the server fetch if we know we're offline. Without this,+ // CarPlay / AndroidAuto sit on a 15s getLibraries timeout every time+ // the user opens the app or connects to the head unit while their+ // server is unreachable.+ if (manualOffline || AudioPlayerService().knownOffline) {_continueListening = [];_recentlyAdded = [];_libraries = [];diff --git a/lib/services/audio_player_service.dart b/lib/services/audio_player_service.dartindex 4d71e825..840000b8 100644--- a/lib/services/audio_player_service.dart+++ b/lib/services/audio_player_service.dart@@ -800,8 +800,11 @@ class AudioPlayerService extends ChangeNotifier {/// AuthProvider mirrors `serverReachable` here on each ping result so we/// can short-circuit pre-play server calls (e.g. session creation) for/// instant offline playback - no need to wait for a network timeout to- /// discover what the auth layer already knows.+ /// discover what the auth layer already knows. Other services+ /// (AndroidAuto/CarPlay browse) read it via [knownOffline] to skip+ /// their own server fetches.bool _knownOffline = false;+ bool get knownOffline => _knownOffline;void setKnownOffline(bool offline) {_knownOffline = offline;}diff --git a/lib/services/carplay_service.dart b/lib/services/carplay_service.dartindex 77cb2327..c1c6950b 100644--- a/lib/services/carplay_service.dart+++ b/lib/services/carplay_service.dart@@ -99,10 +99,17 @@ class CarPlayService {// ─── Root template ──────────────────────────────────────────────────Future<List<CPListTemplate>> _buildTabs() async {+ final downloadsTab = await _buildDownloadsTab();+ // When the server is unreachable, Continue / New / Library are empty+ // anyway (we skip the server fetch). Drop them so CarPlay opens+ // straight into the user's downloads instead of showing three empty+ // tabs they have to swipe past.+ if (AudioPlayerService().knownOffline) {+ return [downloadsTab];+ }final continueTab = await _buildContinueTab();final recentlyAddedTab = await _buildRecentlyAddedTab();final libraryTab = await _buildLibraryTab();- final downloadsTab = await _buildDownloadsTab();return [continueTab, recentlyAddedTab, libraryTab, downloadsTab];}