Allow saving empty lyrics in lyrics editor

This commit is contained in:
tranxuanthang
2026-04-24 00:54:57 +07:00
parent de3f8ea0ee
commit fb585da882
4 changed files with 13 additions and 22 deletions

View File

@@ -92,10 +92,19 @@ struct LyricsfileWord {
end_ms: Option<i64>,
}
fn null_as_default<'de, D, T>(deserializer: D) -> Result<T, D::Error>
where
D: serde::Deserializer<'de>,
T: Default + serde::Deserialize<'de>,
{
let opt = Option::<T>::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<LyricsfileLine>,
plain: Option<String>,
}

View File

@@ -954,9 +954,6 @@ async fn save_lyrics(
app_handle: AppHandle,
) -> Result<String, String> {
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())?;

View File

@@ -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

View File

@@ -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,
})
}