A cross platform Audiobookshelf client for Android and iOS
Dart
Local server UX: toast on switch, simplified settings, version bump to 1.8.16
Nathan Poulsonf71c008c7bb8
diff --git a/lib/providers/auth_provider.dart b/lib/providers/auth_provider.dartindex e9707393..cb38fb99 100644--- a/lib/providers/auth_provider.dart+++ b/lib/providers/auth_provider.dart@@ -6,6 +6,7 @@ import '../services/android_auto_service.dart';import '../services/audio_player_service.dart';import '../services/socket_service.dart';import '../services/user_account_service.dart';+import '../main.dart' show scaffoldMessengerKey;class AuthProvider extends ChangeNotifier {String? _token;@@ -300,6 +301,9 @@ class AuthProvider extends ChangeNotifier {if (_useLocalServer != wasLocal) {debugPrint('[Auth] Local server switch: useLocal=$_useLocalServer');SocketService().switchServer(activeServerUrl!);+ _showServerToast(_useLocalServer+ ? 'Switched to local server'+ : 'Switched to remote server');notifyListeners();}}@@ -312,9 +316,25 @@ class AuthProvider extends ChangeNotifier {if (_serverUrl != null) {SocketService().switchServer(_serverUrl!);}+ _showServerToast('Switched to remote server');notifyListeners();}+ void _showServerToast(String message) {+ try {+ scaffoldMessengerKey.currentState?.showSnackBar(SnackBar(+ content: Row(children: [+ const Icon(Icons.dns_rounded, color: Colors.white, size: 18),+ const SizedBox(width: 8),+ Text(message),+ ]),+ duration: const Duration(seconds: 3),+ behavior: SnackBarBehavior.floating,+ shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),+ ));+ } catch (_) {}+ }+/// Update local server settings from the UI.Future<void> setLocalServerConfig({required bool enabled, required String url}) async {_localServerEnabled = enabled;diff --git a/lib/screens/settings_screen.dart b/lib/screens/settings_screen.dartindex 85d3823e..bff9888b 100644--- a/lib/screens/settings_screen.dart+++ b/lib/screens/settings_screen.dart@@ -10,7 +10,6 @@ import 'package:package_info_plus/package_info_plus.dart';import 'package:just_audio/just_audio.dart' show AudioPlayer;import '../providers/auth_provider.dart';import '../providers/library_provider.dart';-import '../services/api_service.dart';import '../services/audio_player_service.dart';import '../services/download_service.dart';import '../services/sleep_timer_service.dart';@@ -65,6 +64,7 @@ class _SettingsScreenState extends State<SettingsScreen> {int _streamingCacheSizeMb = 0;bool _localServerEnabled = false;String _localServerUrl = '';+ late final TextEditingController _localServerController;bool _disableAudioFocus = false;bool _loaded = false;String _downloadLocationLabel = 'App Internal Storage (Default)';@@ -100,9 +100,16 @@ class _SettingsScreenState extends State<SettingsScreen> {@overridevoid initState() {super.initState();+ _localServerController = TextEditingController();_loadSettings();}+ @override+ void dispose() {+ _localServerController.dispose();+ super.dispose();+ }+Future<void> _loadSettings() async {final results = await Future.wait([AutoRewindSettings.load(), // 0@@ -219,6 +226,7 @@ class _SettingsScreenState extends State<SettingsScreen> {_streamingCacheSizeMb = cacheSizeMb;_localServerEnabled = localEnabled;_localServerUrl = localUrl;+ _localServerController.text = localUrl;_disableAudioFocus = audioFocusOff;_startScreen = startScreen;_loaded = true;@@ -1669,75 +1677,43 @@ class _SettingsScreenState extends State<SettingsScreen> {Padding(padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),child: TextField(- controller: TextEditingController(text: _localServerUrl),+ controller: _localServerController,decoration: InputDecoration(labelText: 'Local server URL',hintText: 'http://192.168.1.100:13378',border: OutlineInputBorder(borderRadius: BorderRadius.circular(12)),suffixIcon: IconButton(icon: const Icon(Icons.check_rounded),- tooltip: 'Save',- onPressed: () {- // URL is saved via onChanged+ tooltip: 'Set',+ onPressed: () async {+ final url = _localServerController.text.trim();+ if (url.isEmpty) return;+ _localServerUrl = url;+ await auth.setLocalServerConfig(enabled: _localServerEnabled, url: _localServerUrl);FocusScope.of(context).unfocus();- ScaffoldMessenger.of(context).showSnackBar(- SnackBar(- content: const Text('Local server URL saved'),- behavior: SnackBarBehavior.floating,- shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),- ),- );+ if (!mounted) return;+ ScaffoldMessenger.of(context).showSnackBar(SnackBar(+ content: const Text('Local server URL set - will connect automatically when on your home network'),+ behavior: SnackBarBehavior.floating,+ shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),+ ));+ // Try connecting right away+ await auth.checkLocalServer();+ if (mounted) setState(() {});},),),- onChanged: (v) {- _localServerUrl = v.trim();- auth.setLocalServerConfig(enabled: _localServerEnabled, url: _localServerUrl);- },),),- const Divider(height: 1, indent: 16, endIndent: 16),- ListTile(- leading: Icon(Icons.wifi_find_rounded, color: cs.primary),- title: const Text('Test local connection'),- subtitle: Text(- auth.useLocalServer ? 'Currently using local server' : 'Tap to ping the local server',- style: tt.bodySmall?.copyWith(color: cs.onSurfaceVariant)),- trailing: auth.useLocalServer- ? Icon(Icons.check_circle_rounded, color: Colors.greenAccent.shade400)- : Icon(Icons.chevron_right_rounded, color: cs.onSurfaceVariant),- onTap: () async {- if (_localServerUrl.isEmpty) {- ScaffoldMessenger.of(context).showSnackBar(SnackBar(- content: const Text('Enter a local server URL first'),- behavior: SnackBarBehavior.floating,- shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),- ));- return;- }- ScaffoldMessenger.of(context).showSnackBar(SnackBar(- content: const Text('Pinging local server...'),- duration: const Duration(seconds: 1),- behavior: SnackBarBehavior.floating,- shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),- ));- final reachable = await ApiService.pingServer(_localServerUrl)- .timeout(const Duration(seconds: 3), onTimeout: () => false);- if (!mounted) return;- ScaffoldMessenger.of(context).clearSnackBars();- ScaffoldMessenger.of(context).showSnackBar(SnackBar(- content: Text(reachable- ? 'Local server is reachable'- : 'Could not reach local server'),- behavior: SnackBarBehavior.floating,- shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),- ));- if (reachable) {- await auth.checkLocalServer();- if (mounted) setState(() {});- }- },- ),+ if (auth.useLocalServer) ...[+ const Divider(height: 1, indent: 16, endIndent: 16),+ ListTile(+ leading: Icon(Icons.check_circle_rounded, color: Colors.greenAccent.shade400),+ title: const Text('Connected via local server'),+ subtitle: Text(_localServerUrl,+ style: tt.bodySmall?.copyWith(color: cs.onSurfaceVariant)),+ ),+ ],],const Divider(height: 1, indent: 16, endIndent: 16),SwitchListTile(diff --git a/pubspec.yaml b/pubspec.yamlindex 2c6e68bb..55d3c5a2 100644--- a/pubspec.yaml+++ b/pubspec.yaml@@ -1,7 +1,7 @@name: absorbdescription: A Material 3 Audiobookshelf client.publish_to: 'none'-version: 1.8.14+44+version: 1.8.16+45environment:sdk: '>=3.1.0 <4.0.0'