Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Add log catcher, crash handlers, and Issues & Support section

Nathan Poulson7672875309e5
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index 3220082a..57c5de21 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -79,7 +79,18 @@
<service
android:name="com.dexterous.flutterlocalnotifications.ForegroundService"
android:exported="false"
- android:foregroundServiceType="dataSync" />
+ android:foregroundServiceType="dataSync" />
+
+ <!-- FileProvider for share_plus file sharing -->
+ <provider
+ android:name="androidx.core.content.FileProvider"
+ android:authorities="${applicationId}.fileprovider"
+ android:exported="false"
+ android:grantUriPermissions="true">
+ <meta-data
+ android:name="android.support.FILE_PROVIDER_PATHS"
+ android:resource="@xml/file_paths" />
+ </provider>
</application>
diff --git a/android/app/src/main/res/xml/file_paths.xml b/android/app/src/main/res/xml/file_paths.xml
new file mode 100644
index 00000000..b9a44d9f
--- /dev/null
+++ b/android/app/src/main/res/xml/file_paths.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<paths>
+ <files-path name="files" path="." />
+ <cache-path name="cache" path="." />
+ <external-path name="external" path="." />
+</paths>
diff --git a/lib/main.dart b/lib/main.dart
index 5fafdcc4..bb92cea9 100644
--- a/lib/main.dart
+++ b/lib/main.dart
@@ -1,3 +1,4 @@
+import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
@@ -17,6 +18,7 @@ import 'services/sleep_timer_service.dart';
import 'services/user_account_service.dart';
import 'services/android_auto_service.dart';
import 'services/chromecast_service.dart';
+import 'services/log_service.dart';
import 'screens/login_screen.dart';
import 'screens/app_shell.dart';
import 'widgets/absorb_wave_icon.dart';
@@ -47,6 +49,22 @@ void main() async {
ApiService.deviceModel = info.model;
} catch (_) {}
+ // Initialize log service (must be before other services so debugPrint is captured)
+ final loggingEnabled = await PlayerSettings.getLoggingEnabled();
+ await LogService().init(loggingEnabled);
+
+ // Capture Flutter framework errors (widget build failures, etc.)
+ FlutterError.onError = (details) {
+ FlutterError.presentError(details);
+ LogService().log('[CRASH] FlutterError: ${details.exceptionAsString()}\n${details.stack}');
+ };
+
+ // Capture unhandled Dart exceptions (async errors, null dereferences, etc.)
+ PlatformDispatcher.instance.onError = (error, stack) {
+ LogService().log('[CRASH] Unhandled: $error\n$stack');
+ return true;
+ };
+
// Initialize download notification service
await DownloadNotificationService().init();
diff --git a/lib/screens/app_shell.dart b/lib/screens/app_shell.dart
index 32e54310..61285e43 100644
--- a/lib/screens/app_shell.dart
+++ b/lib/screens/app_shell.dart
@@ -2,12 +2,10 @@ import 'dart:math' as math;
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
-import 'package:url_launcher/url_launcher.dart';
import '../providers/library_provider.dart';
import '../services/audio_player_service.dart';
import '../services/sleep_timer_service.dart';
import '../services/android_auto_service.dart';
-import '../services/update_checker_service.dart';
import 'absorbing_screen.dart';
import 'home_screen.dart';
import 'library_screen.dart';
@@ -70,41 +68,6 @@ class _AppShellState extends State<AppShell> with WidgetsBindingObserver {
_instance = this;
WidgetsBinding.instance.addObserver(this);
AudioPlayerService.setOnEpisodePlayStartedCallback(AppShell.goToAbsorbingGlobal);
- _checkForUpdate();
- }
-
- Future<void> _checkForUpdate() async {
- final update = await UpdateCheckerService.check();
- if (update != null && mounted) {
- _showUpdateBanner(update);
- }
- }
-
- void _showUpdateBanner(UpdateInfo update) {
- ScaffoldMessenger.of(context).showMaterialBanner(
- MaterialBanner(
- padding: const EdgeInsets.fromLTRB(16, 12, 8, 12),
- leading: Icon(Icons.system_update_rounded, color: Theme.of(context).colorScheme.primary),
- content: Text('Absorb ${update.latestVersion} is available',
- style: TextStyle(fontWeight: FontWeight.w600, color: Theme.of(context).colorScheme.onSurface)),
- actions: [
- TextButton(
- onPressed: () {
- ScaffoldMessenger.of(context).hideCurrentMaterialBanner();
- UpdateCheckerService.dismiss(update.latestVersion);
- },
- child: const Text('Later'),
- ),
- FilledButton(
- onPressed: () {
- ScaffoldMessenger.of(context).hideCurrentMaterialBanner();
- launchUrl(Uri.parse(update.downloadUrl), mode: LaunchMode.externalApplication);
- },
- child: const Text('Update'),
- ),
- ],
- ),
- );
}
@override
diff --git a/lib/screens/settings_screen.dart b/lib/screens/settings_screen.dart
index f8cf9920..3e12f6c6 100644
--- a/lib/screens/settings_screen.dart
+++ b/lib/screens/settings_screen.dart
@@ -11,7 +11,7 @@ import '../services/audio_player_service.dart';
import '../services/download_service.dart';
import '../services/sleep_timer_service.dart';
import '../services/user_account_service.dart';
-import '../services/update_checker_service.dart';
+import '../services/log_service.dart';
import '../screens/login_screen.dart';
import '../screens/app_shell.dart';
import '../screens/admin_screen.dart';
@@ -39,6 +39,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
bool _autoContinueSeries = true;
bool _hideEbookOnly = false;
bool _showGoodreadsButton = false;
+ bool _loggingEnabled = false;
bool _loaded = false;
String _downloadLocationLabel = 'App Internal Storage (Default)';
int _totalDownloadSizeBytes = 0;
@@ -65,6 +66,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
final autoSeries = await PlayerSettings.getAutoContinueSeries();
final hideEbook = await PlayerSettings.getHideEbookOnly();
final showGoodreads = await PlayerSettings.getShowGoodreadsButton();
+ final logging = await PlayerSettings.getLoggingEnabled();
final dlLabel = await DownloadService().downloadLocationLabel;
final dlSize = await DownloadService().totalDownloadSize;
@@ -84,6 +86,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
_autoContinueSeries = autoSeries;
_hideEbookOnly = hideEbook;
_showGoodreadsButton = showGoodreads;
+ _loggingEnabled = logging;
_downloadLocationLabel = dlLabel;
_totalDownloadSizeBytes = dlSize;
_autoSleepSettings = autoSleep;
@@ -941,32 +944,100 @@ class _SettingsScreenState extends State<SettingsScreen> {
),
const SizedBox(height: 16),
- // ── Support & Info ──
+ // ── Issues & Support ──
+ _CollapsibleSection(
+ icon: Icons.support_agent_rounded,
+ title: 'Issues & Support',
+ cs: cs,
+ children: [
+ ListTile(
+ leading: Icon(Icons.bug_report_outlined, color: cs.onSurfaceVariant),
+ title: const Text('Bugs & Feature Requests'),
+ subtitle: Text('Open an issue on GitHub',
+ style: tt.bodySmall?.copyWith(color: cs.onSurfaceVariant)),
+ trailing: Icon(Icons.open_in_new_rounded,
+ size: 18, color: cs.onSurfaceVariant),
+ onTap: () => launchUrl(
+ Uri.parse('https://github.com/pounat/absorb/issues'),
+ mode: LaunchMode.externalApplication),
+ ),
+ const Divider(height: 1, indent: 16, endIndent: 16),
+ ListTile(
+ leading: Icon(Icons.email_outlined, color: cs.primary),
+ title: const Text('Contact'),
+ subtitle: Text('Send device info via email',
+ style: tt.bodySmall?.copyWith(color: cs.onSurfaceVariant)),
+ trailing: const Icon(Icons.chevron_right_rounded),
+ onTap: () {
+ LogService().contactEmail(
+ serverVersion: auth.serverVersion,
+ );
+ },
+ ),
+ const Divider(height: 1, indent: 16, endIndent: 16),
+ SwitchListTile(
+ title: const Text('Enable logging'),
+ subtitle: Text(
+ _loggingEnabled
+ ? 'On — logs saved to file (restart to apply)'
+ : 'Off — no logs captured',
+ style: tt.bodySmall?.copyWith(color: cs.onSurfaceVariant)),
+ value: _loggingEnabled,
+ onChanged: _loaded ? (v) {
+ setState(() => _loggingEnabled = v);
+ PlayerSettings.setLoggingEnabled(v);
+ ScaffoldMessenger.of(context).showSnackBar(SnackBar(
+ content: Text(v
+ ? 'Logging enabled — restart app to start capturing'
+ : 'Logging disabled — restart app to stop capturing'),
+ ));
+ } : null,
+ ),
+ if (_loggingEnabled && LogService().enabled) ...[
+ const Divider(height: 1, indent: 16, endIndent: 16),
+ ListTile(
+ leading: Icon(Icons.attach_file_rounded, color: cs.primary),
+ title: const Text('Send logs'),
+ subtitle: Text('Share log file as attachment',
+ style: tt.bodySmall?.copyWith(color: cs.onSurfaceVariant)),
+ trailing: const Icon(Icons.chevron_right_rounded),
+ onTap: () async {
+ try {
+ await LogService().shareLogs(
+ serverVersion: auth.serverVersion,
+ );
+ } catch (e) {
+ if (mounted) {
+ ScaffoldMessenger.of(context).showSnackBar(
+ SnackBar(content: Text('Failed to share: $e')),
+ );
+ }
+ }
+ },
+ ),
+ const Divider(height: 1, indent: 16, endIndent: 16),
+ ListTile(
+ leading: Icon(Icons.delete_outline_rounded, color: cs.error),
+ title: const Text('Clear logs'),
+ onTap: () async {
+ await LogService().clearLogs();
+ if (mounted) {
+ ScaffoldMessenger.of(context).showSnackBar(
+ const SnackBar(content: Text('Logs cleared')),
+ );
+ }
+ },
+ ),
+ ],
+ ],
+ ),
+ const SizedBox(height: 16),
+
+ // ── Support the Dev ──
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Column(
children: [
- Card(
- color: cs.surfaceContainerHigh,
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(14)),
- clipBehavior: Clip.antiAlias,
- child: ListTile(
- leading: Icon(Icons.feedback_outlined,
- color: cs.onSurfaceVariant),
- title: const Text('Bugs & Feature Requests'),
- subtitle: Text('Open an issue on GitHub',
- style: tt.bodySmall
- ?.copyWith(color: cs.onSurfaceVariant)),
- trailing: Icon(Icons.open_in_new_rounded,
- size: 18, color: cs.onSurfaceVariant),
- onTap: () => launchUrl(
- Uri.parse(
- 'https://github.com/pounat/absorb/issues'),
- mode: LaunchMode.externalApplication),
- ),
- ),
- const SizedBox(height: 8),
Card(
color: cs.surfaceContainerHigh,
shape: RoundedRectangleBorder(
@@ -988,30 +1059,6 @@ class _SettingsScreenState extends State<SettingsScreen> {
),
),
const SizedBox(height: 12),
- GestureDetector(
- onTap: () async {
- final update = await UpdateCheckerService.check(force: true);
- if (!mounted) return;
- if (update != null) {
- ScaffoldMessenger.of(context).showSnackBar(
- SnackBar(
- content: Text('Absorb ${update.latestVersion} is available!'),
- action: SnackBarAction(
- label: 'Download',
- onPressed: () => launchUrl(Uri.parse(update.downloadUrl), mode: LaunchMode.externalApplication),
- ),
- ),
- );
- } else {
- ScaffoldMessenger.of(context).showSnackBar(
- const SnackBar(content: Text('You\'re on the latest version')),
- );
- }
- },
- child: Text('Check for updates',
- style: tt.bodySmall?.copyWith(color: cs.primary, fontWeight: FontWeight.w600)),
- ),
- const SizedBox(height: 8),
Text(
auth.serverVersion != null
? 'Absorb v$_appVersion · Server ${auth.serverVersion}'
diff --git a/lib/services/audio_player_service.dart b/lib/services/audio_player_service.dart
index 50d4612b..6ed992b6 100644
--- a/lib/services/audio_player_service.dart
+++ b/lib/services/audio_player_service.dart
@@ -123,6 +123,9 @@ class PlayerSettings {
static Future<bool> getShowGoodreadsButton() => _get('showGoodreadsButton', false);
static Future<void> setShowGoodreadsButton(bool value) => _set('showGoodreadsButton', value);
+ static Future<bool> getLoggingEnabled() => _get('loggingEnabled', false);
+ static Future<void> setLoggingEnabled(bool value) => _set('loggingEnabled', value);
+
/// Check if an item has no audio content.
/// For minified responses (library list), duration == 0 means no audio files.
/// For full responses (detail sheet), we also check ebookFile + audioFiles.
diff --git a/lib/services/log_service.dart b/lib/services/log_service.dart
new file mode 100644
index 00000000..a141c72d
--- /dev/null
+++ b/lib/services/log_service.dart
@@ -0,0 +1,134 @@
+import 'dart:io';
+import 'package:flutter/foundation.dart';
+import 'package:path_provider/path_provider.dart';
+import 'package:share_plus/share_plus.dart';
+import 'package:url_launcher/url_launcher.dart';
+import 'api_service.dart';
+
+class LogService {
+ static final LogService _instance = LogService._();
+ factory LogService() => _instance;
+ LogService._();
+
+ static const supportEmail = '[email protected]';
+
+ File? _logFile;
+ bool _enabled = false;
+ DebugPrintCallback? _originalDebugPrint;
+
+ bool get enabled => _enabled;
+
+ /// Call once at startup. If [loggingEnabled] is true, sets up the log file
+ /// and overrides [debugPrint] to capture all output.
+ Future<void> init(bool loggingEnabled) async {
+ _enabled = loggingEnabled;
+ if (!_enabled) return;
+
+ final dir = await getApplicationDocumentsDirectory();
+ _logFile = File('${dir.path}/absorb_logs.txt');
+
+ // Rotate: if file > 1MB, keep the last 512KB
+ if (await _logFile!.exists()) {
+ final size = await _logFile!.length();
+ if (size > 1024 * 1024) {
+ final contents = await _logFile!.readAsString();
+ await _logFile!.writeAsString(
+ contents.substring(contents.length - (512 * 1024)),
+ );
+ }
+ }
+
+ // Session header
+ final now = DateTime.now().toIso8601String();
+ await _logFile!.writeAsString(
+ '\n=== Session started $now ===\n',
+ mode: FileMode.append,
+ );
+
+ // Override debugPrint globally
+ _originalDebugPrint = debugPrint;
+ debugPrint = _interceptedDebugPrint;
+ }
+
+ void _interceptedDebugPrint(String? message, {int? wrapWidth}) {
+ _originalDebugPrint?.call(message, wrapWidth: wrapWidth);
+ if (_logFile != null && message != null) {
+ final ts = DateTime.now().toIso8601String();
+ _logFile!.writeAsStringSync(
+ '[$ts] $message\n',
+ mode: FileMode.append,
+ );
+ }
+ }
+
+ /// Write a log entry directly (for error handlers that bypass debugPrint).
+ void log(String message) {
+ if (_logFile != null) {
+ final ts = DateTime.now().toIso8601String();
+ _logFile!.writeAsStringSync(
+ '[$ts] $message\n',
+ mode: FileMode.append,
+ );
+ }
+ }
+
+ Future<void> clearLogs() async {
+ if (_logFile != null && await _logFile!.exists()) {
+ await _logFile!.writeAsString('');
+ }
+ }
+
+ /// Build device info string used by both email methods.
+ String _deviceInfo({String? serverVersion}) {
+ final buf = StringBuffer()
+ ..writeln('App Version: ${ApiService.appVersion}')
+ ..writeln('Device: ${ApiService.deviceManufacturer} ${ApiService.deviceModel}')
+ ..writeln('Device ID: ${ApiService.deviceId}');
+ if (serverVersion != null) {
+ buf.writeln('Server Version: $serverVersion');
+ }
+ buf.writeln('Timestamp: ${DateTime.now().toIso8601String()}');
+ return buf.toString();
+ }
+
+ /// Share log file as attachment via share sheet with device info.
+ Future<void> shareLogs({String? serverVersion}) async {
+ final info = _deviceInfo(serverVersion: serverVersion);
+
+ final hasFile =
+ _logFile != null && await _logFile!.exists() && await _logFile!.length() > 0;
+
+ if (hasFile) {
+ await Share.shareXFiles(
+ [XFile(_logFile!.path)],
+ subject: 'Absorb Log Report',
+ text: 'Send to: $supportEmail\n\n$info',
+ );
+ } else {
+ await Share.share(
+ 'Send to: $supportEmail\n\n$info\n(No log file found — is logging enabled?)',
+ subject: 'Absorb Log Report',
+ );
+ }
+ }
+
+ /// Open a mailto: link with device info (no logs) for general contact.
+ Future<void> contactEmail({String? serverVersion}) async {
+ final info = _deviceInfo(serverVersion: serverVersion);
+ final uri = Uri(
+ scheme: 'mailto',
+ path: supportEmail,
+ query: _encodeMailtoQuery({
+ 'subject': 'Absorb Feedback',
+ 'body': info,
+ }),
+ );
+ await launchUrl(uri);
+ }
+
+ String _encodeMailtoQuery(Map<String, String> params) {
+ return params.entries
+ .map((e) => '${e.key}=${Uri.encodeComponent(e.value)}')
+ .join('&');
+ }
+}
diff --git a/pubspec.lock b/pubspec.lock
index e4d1b54f..b4786195 100644
--- a/pubspec.lock
+++ b/pubspec.lock
@@ -551,6 +551,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.17.0"
+ mime:
+ dependency: transitive
+ description:
+ name: mime
+ sha256: "41a20518f0cb1256669420fdba0cd90d21561e560ac240f26ef8322e45bb7ed6"
+ url: "https://pub.dev"
+ source: hosted
+ version: "2.0.0"
nested:
dependency: transitive
description:
@@ -775,6 +783,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.2.0"
+ share_plus:
+ dependency: "direct main"
+ description:
+ name: share_plus
+ sha256: fce43200aa03ea87b91ce4c3ac79f0cecd52e2a7a56c7a4185023c271fbfa6da
+ url: "https://pub.dev"
+ source: hosted
+ version: "10.1.4"
+ share_plus_platform_interface:
+ dependency: transitive
+ description:
+ name: share_plus_platform_interface
+ sha256: cc012a23fc2d479854e6c80150696c4a5f5bb62cb89af4de1c505cf78d0a5d0b
+ url: "https://pub.dev"
+ source: hosted
+ version: "5.0.2"
shared_preferences:
dependency: "direct main"
description:
diff --git a/pubspec.yaml b/pubspec.yaml
index c97277f0..1a65199e 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -68,6 +68,9 @@ dependencies:
# chromecast
flutter_chrome_cast: ^1.2.6
+ # Log sharing
+ share_plus: ^10.0.0
+
dev_dependencies:
flutter_test:
sdk: flutter