diff --git a/src-tauri/src/lyricsfile.rs b/src-tauri/src/lyricsfile.rs index cbecd15..24f499f 100644 --- a/src-tauri/src/lyricsfile.rs +++ b/src-tauri/src/lyricsfile.rs @@ -92,10 +92,19 @@ struct LyricsfileWord { end_ms: Option, } +fn null_as_default<'de, D, T>(deserializer: D) -> Result +where + D: serde::Deserializer<'de>, + T: Default + serde::Deserialize<'de>, +{ + let opt = Option::::deserialize(deserializer)?; + Ok(opt.unwrap_or_default()) +} + #[derive(Debug, Deserialize)] struct ParsedLyricsfileDocument { metadata: ParsedLyricsfileMetadata, - #[serde(default)] + #[serde(default, deserialize_with = "null_as_default")] lines: Vec, plain: Option, } diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 2c23d03..af51509 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -954,9 +954,6 @@ async fn save_lyrics( app_handle: AppHandle, ) -> Result { let lyricsfile = lyricsfile.trim(); - if lyricsfile.is_empty() { - return Err("Lyricsfile content cannot be empty".to_string()); - } // Parse the lyricsfile content to validate it let _parsed = lyricsfile::parse_lyricsfile(lyricsfile).map_err(|err| err.to_string())?; diff --git a/src/composables/edit-lyrics-v2/useEditLyricsV2Document.js b/src/composables/edit-lyrics-v2/useEditLyricsV2Document.js index 6fafec0..379804f 100644 --- a/src/composables/edit-lyrics-v2/useEditLyricsV2Document.js +++ b/src/composables/edit-lyrics-v2/useEditLyricsV2Document.js @@ -264,12 +264,6 @@ export function useEditLyricsV2Document({ audioSource, lyricsfile, trackId, prog try { const serializedContent = serializedLyricsfile.value - // serializedLyricsfile returns empty string if there's nothing to serialize - // In that case, we treat it as a successful save (nothing to save) - if (!serializedContent) { - return true - } - // Determine if this is a library track or a standalone lyricsfile // trackId is passed separately from audioSource to handle temporary associations // where a library track might be used for playback but the lyricsfile should not diff --git a/src/utils/lyricsfile.js b/src/utils/lyricsfile.js index 1ad1fb3..e5180d4 100644 --- a/src/utils/lyricsfile.js +++ b/src/utils/lyricsfile.js @@ -258,15 +258,6 @@ export const serializeLyricsfile = ({ const normalizedSynced = normalizeNonEmpty(syncedLyrics) const normalizedSyncedLines = cloneSyncedLines(syncedLines) - if ( - !normalizedPlain && - normalizedSyncedLines.length === 0 && - !normalizedSynced && - !forceInstrumental - ) { - return null - } - const isInstrumental = forceInstrumental || (normalizedSynced ? isInstrumentalLyrics(normalizedSynced) : false) const baseMetadata = baseDocument?.metadata || {} @@ -288,8 +279,8 @@ export const serializeLyricsfile = ({ } const plain = isInstrumental - ? undefined - : normalizedPlain || normalizeNonEmpty(stripTimestamp(normalizedSynced || '')) || undefined + ? null + : normalizedPlain || normalizeNonEmpty(stripTimestamp(normalizedSynced || '')) || null const metadata = { title: track?.title || baseMetadata.title || '', @@ -318,7 +309,7 @@ export const serializeLyricsfile = ({ return YAML.stringify({ version: LYRICSFILE_VERSION, metadata, - lines, + lines: lines.length > 0 ? lines : null, plain, }) }