Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Add download init timeout, async file checks, remove noisy bg save log

Nathan Poulsona298512cc067
diff --git a/lib/main.dart b/lib/main.dart
index 1be0711e..d7172456 100644
--- a/lib/main.dart
+++ b/lib/main.dart
@@ -47,7 +47,11 @@ void main() async {
// AA launches it), every millisecond of delay here is time the user
// stares at a loading spinner. Downloads must be loaded before the
// handler so getChildren() can serve the browse tree immediately.
- await DownloadService().init();
+ try {
+ await DownloadService().init().timeout(const Duration(seconds: 8));
+ } catch (e) {
+ debugPrint('[Main] DownloadService.init timed out or failed: $e');
+ }
// Timeout guards against AudioService.init() hanging when Android killed
// the app process but kept the MediaBrowserService alive (e.g. Bluetooth
// or Android Auto was connected). If it times out the app still launches
diff --git a/lib/services/audio_player_service.dart b/lib/services/audio_player_service.dart
index 311c66d7..1d3b131b 100644
--- a/lib/services/audio_player_service.dart
+++ b/lib/services/audio_player_service.dart
@@ -1813,7 +1813,6 @@ class AudioPlayerService extends ChangeNotifier {
final pos = position;
final posSec = pos.inMilliseconds / 1000.0;
if (posSec <= 0) return;
- debugPrint('[Player] Background save: ${posSec.toStringAsFixed(1)}s');
await _saveProgressLocal(pos);
// Sync to server through the active session
if (!_isOfflineMode && _playbackSessionId != null) {
diff --git a/lib/services/download_service.dart b/lib/services/download_service.dart
index d80db9d6..4ee30436 100644
--- a/lib/services/download_service.dart
+++ b/lib/services/download_service.dart
@@ -268,7 +268,7 @@ class DownloadService extends ChangeNotifier {
if (info.status == DownloadStatus.downloaded) {
bool allExist = true;
for (final path in info.localPaths) {
- if (!File(path).existsSync()) {
+ if (!await File(path).exists()) {
allExist = false;
break;
}
@@ -291,11 +291,11 @@ class DownloadService extends ChangeNotifier {
debugPrint('[Download] Cleaning up orphaned entry: $id');
try {
final dir = Directory('$basePath/$id');
- if (dir.existsSync()) dir.deleteSync(recursive: true);
+ if (await dir.exists()) await dir.delete(recursive: true);
} catch (_) {}
try {
final coverDir = Directory('$internalBase/$id');
- if (coverDir.existsSync()) coverDir.deleteSync(recursive: true);
+ if (await coverDir.exists()) await coverDir.delete(recursive: true);
} catch (_) {}
}
}