fixed lots of bugs by return Action enums in song_editor and library

Instead of dealing with a complication of every return from a
component being a Task<Message>, I create an Action enum that only
contains Tasks when needed and other specific actions that the
overarching App should handle to interact with other parts of it.
This commit is contained in:
Chris Cochrun 2025-03-15 22:25:46 -05:00
parent e5981d006b
commit 66e33be26c
8 changed files with 272 additions and 220 deletions

View file

@ -1,11 +1,13 @@
use cosmic::dialog::ashpd::url::Url;
use crisp::types::{Keyword, Symbol, Value};
use iced_video_player::Video;
use miette::{miette, Result};
use serde::{Deserialize, Serialize};
use std::{
fmt::Display,
path::{Path, PathBuf},
};
use tracing::{debug, error};
use tracing::error;
use super::songs::Song;
@ -49,6 +51,20 @@ pub struct Background {
pub kind: BackgroundKind,
}
impl TryFrom<Background> for Video {
type Error = ParseError;
fn try_from(
value: Background,
) -> std::result::Result<Self, Self::Error> {
Video::new(
&Url::from_file_path(value.path)
.map_err(|_| ParseError::BackgroundNotVideo)?,
)
.map_err(|_| ParseError::BackgroundNotVideo)
}
}
impl TryFrom<String> for Background {
type Error = ParseError;
fn try_from(value: String) -> Result<Self, Self::Error> {
@ -137,6 +153,7 @@ pub enum ParseError {
NonBackgroundFile,
DoesNotExist,
CannotCanonicalize,
BackgroundNotVideo,
}
impl std::error::Error for ParseError {}
@ -154,6 +171,9 @@ impl Display for ParseError {
Self::CannotCanonicalize => {
"Could not canonicalize this file"
}
Self::BackgroundNotVideo => {
"This background isn't a video"
}
};
write!(f, "Error: {message}")
}