diff --git a/lib/app/pages/source_page.dart b/lib/app/pages/source_page.dart index a9ea0d9..eb3a033 100644 --- a/lib/app/pages/source_page.dart +++ b/lib/app/pages/source_page.dart @@ -12,6 +12,7 @@ import '../../log.dart'; import '../../models/settings.dart'; import '../../services/settings_service.dart'; import '../items.dart'; +import '../snackbars.dart'; class SourcePage extends HookConsumerWidget { final int? id; @@ -164,6 +165,7 @@ class SourcePage extends HookConsumerWidget { } } catch (e, st) { // TOOD: toast the error or whatever + showErrorSnackbar(context, e.toString()); log.severe('Saving source', e, st); error = true; } finally { diff --git a/lib/app/snackbars.dart b/lib/app/snackbars.dart new file mode 100644 index 0000000..ffc0bd4 --- /dev/null +++ b/lib/app/snackbars.dart @@ -0,0 +1,14 @@ +import 'package:flutter/material.dart'; + +void showErrorSnackbar(BuildContext context, String message) { + final colors = Theme.of(context).colorScheme; + + ScaffoldMessenger.of(context).showSnackBar(SnackBar( + content: Text(message, style: TextStyle(color: colors.onErrorContainer)), + backgroundColor: colors.errorContainer, + showCloseIcon: true, + closeIconColor: colors.onErrorContainer, + behavior: SnackBarBehavior.floating, + duration: const Duration(seconds: 10), + )); +} diff --git a/lib/services/settings_service.dart b/lib/services/settings_service.dart index 264e930..cfcbc50 100644 --- a/lib/services/settings_service.dart +++ b/lib/services/settings_service.dart @@ -53,6 +53,8 @@ class SettingsService extends _$SettingsService { ref.read(httpClientProvider), ); + await client.test(); + final features = IList([ if (await client.testFeature(SubsonicFeature.emptyQuerySearch)) SubsonicFeature.emptyQuerySearch, @@ -66,6 +68,10 @@ class SettingsService extends _$SettingsService { } Future updateSource(SubsonicSettings source) async { + final client = SubsonicClient(source, ref.read(httpClientProvider)); + + await client.test(); + await _db.updateSource(source); await init(); } diff --git a/lib/sources/subsonic/client.dart b/lib/sources/subsonic/client.dart index 6d51738..0e1128a 100644 --- a/lib/sources/subsonic/client.dart +++ b/lib/sources/subsonic/client.dart @@ -98,6 +98,8 @@ class SubsonicClient { return subsonicResponse; } + Future test() => get('ping'); + Future testFeature(SubsonicFeature feature) async { switch (feature) { case SubsonicFeature.emptyQuerySearch: