A cross platform Audiobookshelf client for Android and iOS
Dart
Sleep rewind, swipe gestures, podcast subscription fixes, series pagination, socket reconnect offline
Nathan Poulsonfc0bbdf59f18
diff --git a/lib/main.dart b/lib/main.dartindex c2ef0162..1c5c7275 100644--- a/lib/main.dart+++ b/lib/main.dart@@ -55,9 +55,11 @@ class _CertOverrides extends HttpOverrides {@overrideHttpClient createHttpClient(SecurityContext? context) {final client = super.createHttpClient(context);- if (trustAllCerts) {- client.badCertificateCallback = (_, __, ___) => true;- }+ // Always install the callback so it works even for HttpClient instances+ // created before trustAllCerts is loaded from SharedPreferences.+ // flutter_cache_manager (CachedNetworkImage) caches its HttpClient, so+ // checking the flag at validation time (not creation time) is essential.+ client.badCertificateCallback = (_, __, ___) => trustAllCerts;return client;}}diff --git a/lib/screens/settings_screen.dart b/lib/screens/settings_screen.dartindex 8aedc4be..16b9db12 100644--- a/lib/screens/settings_screen.dart+++ b/lib/screens/settings_screen.dart@@ -251,6 +251,7 @@ class _SettingsScreenState extends State<SettingsScreen> {_rectangleCovers = rectCovers;_coverPlayButton = coverPlay;_trustAllCerts = trustCerts;+_loaded = true;});}diff --git a/lib/services/audio_player_service.dart b/lib/services/audio_player_service.dartindex b3883b93..0ada2e40 100644--- a/lib/services/audio_player_service.dart+++ b/lib/services/audio_player_service.dart@@ -204,6 +204,9 @@ class PlayerSettings {static Future<bool> getSleepFadeOut() => _get('sleepFadeOut', true);static Future<void> setSleepFadeOut(bool value) => _set('sleepFadeOut', value);+ static Future<int> getSleepRewindSeconds() => _get('sleepRewindSeconds', 0);+ static Future<void> setSleepRewindSeconds(int seconds) => _set('sleepRewindSeconds', seconds);+static Future<bool> getHideEbookOnly() => _get('hideEbookOnly', false);static Future<void> setHideEbookOnly(bool value) => _set('hideEbookOnly', value, notify: true);diff --git a/lib/services/sleep_timer_service.dart b/lib/services/sleep_timer_service.dartindex 180c3d48..f7fa7fda 100644--- a/lib/services/sleep_timer_service.dart+++ b/lib/services/sleep_timer_service.dart@@ -298,7 +298,7 @@ class SleepTimerService extends ChangeNotifier {bool _isFadingOut = false;bool get isFadingOut => _isFadingOut;- void _triggerSleep() {+ void _triggerSleep() async {debugPrint('[SleepTimer] Triggering sleep — pausing playback');if (_cast.isCasting) {_cast.pause();@@ -306,6 +306,14 @@ class SleepTimerService extends ChangeNotifier {_player.pause();// Restore volume so next playback starts at normal level_player.setVolume(_fadeStartVolume);+ // Auto-rewind so the user resumes from a few seconds back+ final rewindSeconds = await PlayerSettings.getSleepRewindSeconds();+ if (rewindSeconds > 0) {+ final currentPos = _player.position;+ final newPos = currentPos - Duration(seconds: rewindSeconds);+ _player.seekTo(newPos < Duration.zero ? Duration.zero : newPos);+ debugPrint('[SleepTimer] Rewound ${rewindSeconds}s');+ }}_isFadingOut = false;cancel();diff --git a/lib/widgets/sleep_timer_sheet.dart b/lib/widgets/sleep_timer_sheet.dartindex 4247d85c..bb28c601 100644--- a/lib/widgets/sleep_timer_sheet.dart+++ b/lib/widgets/sleep_timer_sheet.dart@@ -24,23 +24,31 @@ class _SleepTimerSheetState extends State<SleepTimerSheet> {int _customChapters = 1;String _shakeMode = 'addTime'; // 'off', 'addTime', 'resetTimer'int _shakeAddMinutes = 5;+ int _sleepRewindSeconds = 0;++ // Rewind presets in seconds - filtered by timer duration at build time+ static const _rewindStops = [0, 15, 30, 60, 120, 300, 600, 900, 1200, 1800];@overridevoid initState() {super.initState();- _loadShakeSettings();+ _loadSettings();}- Future<void> _loadShakeSettings() async {- final mode = await PlayerSettings.getShakeMode();- final mins = await PlayerSettings.getShakeAddMinutes();- final timerMins = await PlayerSettings.getSleepTimerMinutes();- final timerCh = await PlayerSettings.getSleepTimerChapters();+ Future<void> _loadSettings() async {+ final results = await Future.wait([+ PlayerSettings.getShakeMode(),+ PlayerSettings.getShakeAddMinutes(),+ PlayerSettings.getSleepTimerMinutes(),+ PlayerSettings.getSleepTimerChapters(),+ PlayerSettings.getSleepRewindSeconds(),+ ]);if (mounted) setState(() {- _shakeMode = mode;- _shakeAddMinutes = mins;- _customMinutes = timerMins.toDouble();- _customChapters = timerCh;+ _shakeMode = results[0] as String;+ _shakeAddMinutes = results[1] as int;+ _customMinutes = (results[2] as int).toDouble();+ _customChapters = results[3] as int;+ _sleepRewindSeconds = results[4] as int;});}@@ -98,6 +106,13 @@ class _SleepTimerSheetState extends State<SleepTimerSheet> {Container(height: 0.5, color: cs.onSurface.withValues(alpha: 0.08)),const SizedBox(height: 12),+ // Rewind on sleep+ _buildRewindSection(accent, tt),++ const SizedBox(height: 12),+ Container(height: 0.5, color: cs.onSurface.withValues(alpha: 0.08)),+ const SizedBox(height: 12),+// Shake toggle_buildShakeToggle(accent, tt),],@@ -307,6 +322,54 @@ class _SleepTimerSheetState extends State<SleepTimerSheet> {]);}+ /// Format seconds as a human-readable label (e.g. "30s", "5m", "1m 30s").+ String _rewindLabel(int seconds) {+ if (seconds == 0) return 'Off';+ if (seconds < 60) return '${seconds}s';+ final m = seconds ~/ 60;+ final s = seconds % 60;+ return s > 0 ? '${m}m ${s}s' : '${m}m';+ }++ Widget _buildRewindSection(Color accent, TextTheme tt) {+ final cs = Theme.of(context).colorScheme;+ final isEnabled = _sleepRewindSeconds > 0;++ // Filter stops to those <= 2/3 of the timer duration (in seconds)+ final timerSeconds = _tabIndex == 0+ ? (_customMinutes * 60).round()+ : _customChapters * 600; // rough estimate: ~10 min per chapter+ final maxRewind = (timerSeconds * 2 ~/ 3).clamp(15, 1800);+ final stops = _rewindStops.where((s) => s == 0 || s <= maxRewind).toList();++ // Snap current value to nearest valid stop+ if (_sleepRewindSeconds > 0 && !stops.contains(_sleepRewindSeconds)) {+ final nearest = stops.where((s) => s > 0).reduce((a, b) =>+ (a - _sleepRewindSeconds).abs() <= (b - _sleepRewindSeconds).abs() ? a : b);+ _sleepRewindSeconds = nearest;+ }++ return Column(crossAxisAlignment: CrossAxisAlignment.start, children: [+ Row(children: [+ Icon(Icons.replay_rounded, size: 18, color: isEnabled ? accent : cs.onSurface.withValues(alpha: 0.24)),+ const SizedBox(width: 10),+ Expanded(child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [+ Text('Rewind on sleep', style: TextStyle(color: isEnabled ? cs.onSurface.withValues(alpha: 0.7) : cs.onSurfaceVariant, fontSize: 13, fontWeight: FontWeight.w500)),+ Text(isEnabled ? 'Rewinds ${_rewindLabel(_sleepRewindSeconds)} when timer stops' : 'Disabled',+ style: TextStyle(color: cs.onSurface.withValues(alpha: 0.3), fontSize: 11)),+ ])),+ ]),+ const SizedBox(height: 10),+ Wrap(spacing: 8, runSpacing: 8, alignment: WrapAlignment.center, children: [+ for (final s in stops)+ _presetChip(accent, _rewindLabel(s), _sleepRewindSeconds == s, () {+ setState(() => _sleepRewindSeconds = s);+ PlayerSettings.setSleepRewindSeconds(s);+ }),+ ]),+ ]);+ }+Widget _buildShakeToggle(Color accent, TextTheme tt) {final cs = Theme.of(context).colorScheme;final isEnabled = _shakeMode != 'off';diff --git a/pubspec.yaml b/pubspec.yamlindex 7237624d..9f22549a 100644--- a/pubspec.yaml+++ b/pubspec.yaml@@ -1,7 +1,7 @@name: absorbdescription: An Audiobookshelf Clientpublish_to: 'none'-version: 1.8.28+54+version: 1.8.29+55environment:sdk: '>=3.1.0 <4.0.0'