mirror of
https://github.com/tranxuanthang/lrcget.git
synced 2026-05-29 19:24:42 -04:00
Allow saving empty lyrics in lyrics editor
This commit is contained in:
@@ -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>,
|
||||
}
|
||||
|
||||
@@ -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())?;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user