Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Fix log device info header missing after clear and on startup

Nathan Poulsonb9abb1908a19
diff --git a/lib/main.dart b/lib/main.dart
index 3f45bf1f..ecfbff5d 100644
--- a/lib/main.dart
+++ b/lib/main.dart
@@ -361,7 +361,23 @@ class _AuthGateState extends State<AuthGate> {
}
Future<void> _initServices() async {
- // Initialize log service FIRST so all debugPrint calls are captured in the
+ // Load device info before log service so the log header has the real
+ // app version and device model instead of fallback values.
+ await ApiService.initVersion();
+ try {
+ if (Platform.isAndroid) {
+ final info = await DeviceInfoPlugin().androidInfo;
+ ApiService.deviceManufacturer = info.manufacturer;
+ ApiService.deviceModel = info.model;
+ ApiService.deviceSdkInt = info.version.sdkInt;
+ } else if (Platform.isIOS) {
+ final info = await DeviceInfoPlugin().iosInfo;
+ ApiService.deviceManufacturer = 'Apple';
+ ApiService.deviceModel = info.utsname.machine;
+ }
+ } catch (_) {}
+
+ // Initialize log service early so all debugPrint calls are captured in the
// log file. This is critical for diagnosing startup freezes in production.
try {
final loggingEnabled = await PlayerSettings.getLoggingEnabled();
@@ -409,22 +425,9 @@ class _AuthGateState extends State<AuthGate> {
// Migrate unified queueMode → per-type book/podcast modes (one-time)
await PlayerSettings.migrateBookPodcastQueueMode();
- // Load device info for server identification
- debugPrint('[Init] device info... (${sw.elapsedMilliseconds}ms)');
+ // Generate persistent device ID for server identification
+ debugPrint('[Init] device ID... (${sw.elapsedMilliseconds}ms)');
await ApiService.initDeviceId();
- await ApiService.initVersion();
- try {
- if (Platform.isAndroid) {
- final info = await DeviceInfoPlugin().androidInfo;
- ApiService.deviceManufacturer = info.manufacturer;
- ApiService.deviceModel = info.model;
- ApiService.deviceSdkInt = info.version.sdkInt;
- } else if (Platform.isIOS) {
- final info = await DeviceInfoPlugin().iosInfo;
- ApiService.deviceManufacturer = 'Apple';
- ApiService.deviceModel = info.utsname.machine;
- }
- } catch (_) {}
// Downloads must be loaded before the audio handler so getChildren()
// can serve the Android Auto browse tree immediately.
diff --git a/lib/services/log_service.dart b/lib/services/log_service.dart
index 605e3c4f..94087e0f 100644
--- a/lib/services/log_service.dart
+++ b/lib/services/log_service.dart
@@ -52,7 +52,7 @@ class LogService {
}
}
- if (shouldClear || !_logFile!.existsSync()) {
+ if (shouldClear || !_logFile!.existsSync() || !createdAtFile.existsSync()) {
// Start fresh - write device/server info header
final header = StringBuffer()
..writeln('=== Absorb Log ===')
@@ -142,12 +142,23 @@ class LogService {
Future<void> clearLogs() async {
if (_logFile != null && await _logFile!.exists()) {
- await _logFile!.writeAsString('');
- // Reset creation timestamp so next init writes a fresh header
+ // Write a fresh header immediately so logs shared in the same session
+ // still have device info (don't wait for next init/restart).
+ final header = StringBuffer()
+ ..writeln('=== Absorb Log ===')
+ ..writeln('App Version: ${ApiService.appVersion}')
+ ..writeln('Device: ${ApiService.deviceManufacturer} ${ApiService.deviceModel}')
+ ..writeln('OS: ${Platform.operatingSystem} ${Platform.operatingSystemVersion}')
+ ..writeln('Created: ${DateTime.now().toIso8601String()}')
+ ..writeln('==================')
+ ..writeln();
+ await _logFile!.writeAsString(header.toString());
+ // Reset creation timestamp
try {
final dir = _logFile!.parent;
final createdAtFile = File('${dir.path}/$_createdAtKey');
- if (createdAtFile.existsSync()) createdAtFile.deleteSync();
+ createdAtFile.writeAsStringSync(
+ DateTime.now().millisecondsSinceEpoch.toString());
} catch (_) {}
}
}