mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-07-03 19:27:57 +02:00
fix(lyrics): sync provider settings to backend before fetch
Expose an awaitable lyrics settings sync on SettingsNotifier and call it before metadata re-enrich, lyrics autofill, and queue/local embed flows so the backend uses the latest provider order and fetch options.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
@@ -96,23 +97,29 @@ class SettingsNotifier extends Notifier<AppSettings> {
|
||||
}
|
||||
|
||||
void _syncLyricsSettingsToBackend() {
|
||||
unawaited(syncLyricsSettingsToBackend());
|
||||
}
|
||||
|
||||
Future<void> syncLyricsSettingsToBackend() async {
|
||||
if (!PlatformBridge.supportsCoreBackend) return;
|
||||
|
||||
PlatformBridge.setLyricsProviders(state.lyricsProviders).catchError((
|
||||
Object e,
|
||||
) {
|
||||
try {
|
||||
await PlatformBridge.setLyricsProviders(state.lyricsProviders);
|
||||
} catch (e) {
|
||||
_log.w('Failed to sync lyrics providers to backend: $e');
|
||||
});
|
||||
}
|
||||
|
||||
PlatformBridge.setLyricsFetchOptions({
|
||||
'include_translation_netease': state.lyricsIncludeTranslationNetease,
|
||||
'include_romanization_netease': state.lyricsIncludeRomanizationNetease,
|
||||
'multi_person_word_by_word': state.lyricsMultiPersonWordByWord,
|
||||
'apple_elrc_word_sync': state.lyricsAppleElrcWordSync,
|
||||
'musixmatch_language': state.musixmatchLanguage,
|
||||
}).catchError((Object e) {
|
||||
try {
|
||||
await PlatformBridge.setLyricsFetchOptions({
|
||||
'include_translation_netease': state.lyricsIncludeTranslationNetease,
|
||||
'include_romanization_netease': state.lyricsIncludeRomanizationNetease,
|
||||
'multi_person_word_by_word': state.lyricsMultiPersonWordByWord,
|
||||
'apple_elrc_word_sync': state.lyricsAppleElrcWordSync,
|
||||
'musixmatch_language': state.musixmatchLanguage,
|
||||
});
|
||||
} catch (e) {
|
||||
_log.w('Failed to sync lyrics fetch options to backend: $e');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _syncNetworkCompatibilitySettingsToBackend() {
|
||||
|
||||
@@ -987,6 +987,7 @@ class _LocalAlbumScreenState extends ConsumerState<LocalAlbumScreen> {
|
||||
final durationMs = (item.duration ?? 0) * 1000;
|
||||
final settings = ref.read(settingsProvider);
|
||||
final artistTagMode = settings.artistTagMode;
|
||||
await ref.read(settingsProvider.notifier).syncLyricsSettingsToBackend();
|
||||
final request = <String, dynamic>{
|
||||
'file_path': item.filePath,
|
||||
'cover_url': '',
|
||||
|
||||
@@ -5155,6 +5155,7 @@ class _QueueTabState extends ConsumerState<QueueTab> {
|
||||
final durationMs = (item.duration ?? 0) * 1000;
|
||||
final settings = ref.read(settingsProvider);
|
||||
final artistTagMode = settings.artistTagMode;
|
||||
await ref.read(settingsProvider.notifier).syncLyricsSettingsToBackend();
|
||||
final request = <String, dynamic>{
|
||||
'file_path': item.filePath,
|
||||
'cover_url': '',
|
||||
|
||||
@@ -664,6 +664,10 @@ class _EditMetadataSheetState extends State<_EditMetadataSheet> {
|
||||
}
|
||||
|
||||
setState(() => _fetching = true);
|
||||
final settingsNotifier = ProviderScope.containerOf(
|
||||
context,
|
||||
listen: false,
|
||||
).read(settingsProvider.notifier);
|
||||
|
||||
try {
|
||||
final title = _titleCtrl.text.trim();
|
||||
@@ -871,6 +875,10 @@ class _EditMetadataSheetState extends State<_EditMetadataSheet> {
|
||||
}
|
||||
|
||||
if (shouldFetchLyrics) {
|
||||
await settingsNotifier.syncLyricsSettingsToBackend();
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
final lyricsTitle =
|
||||
((selectedBest?['name'] ?? selectedBest?['title'] ?? title)
|
||||
.toString())
|
||||
|
||||
@@ -3011,8 +3011,12 @@ class _TrackMetadataScreenState extends ConsumerState<TrackMetadataScreen> {
|
||||
try {
|
||||
final settings = ref.read(settingsProvider);
|
||||
final artistTagMode = settings.artistTagMode;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(context.l10n.trackReEnrichSearching)),
|
||||
final messenger = ScaffoldMessenger.of(context);
|
||||
final l10n = context.l10n;
|
||||
await ref.read(settingsProvider.notifier).syncLyricsSettingsToBackend();
|
||||
if (!mounted) return;
|
||||
messenger.showSnackBar(
|
||||
SnackBar(content: Text(l10n.trackReEnrichSearching)),
|
||||
);
|
||||
|
||||
final durationMs = (duration ?? 0) * 1000;
|
||||
|
||||
Reference in New Issue
Block a user