2022-12-18 21:07:33 -08:00
|
|
|
use serde::{Deserialize, Serialize};
|
2022-12-18 18:26:13 -08:00
|
|
|
|
2022-12-18 21:07:33 -08:00
|
|
|
#[derive(Deserialize, Serialize)]
|
|
|
|
pub struct PartialTag {
|
|
|
|
pub path: Option<String>,
|
|
|
|
pub title: Option<String>,
|
|
|
|
pub artist: Option<String>,
|
|
|
|
pub album: Option<String>,
|
|
|
|
pub album_artist: Option<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for PartialTag {
|
|
|
|
fn default() -> Self {
|
|
|
|
PartialTag {
|
|
|
|
path: None,
|
|
|
|
title: None,
|
|
|
|
artist: None,
|
|
|
|
album: None,
|
|
|
|
album_artist: None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PartialTag {
|
|
|
|
pub fn has_path(self: &Self) -> bool {
|
|
|
|
self.path.is_some()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn has_title(self: &Self) -> bool {
|
|
|
|
self.title.is_some()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn has_artist(self: &Self) -> bool {
|
|
|
|
self.artist.is_some()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn has_album(self: &Self) -> bool {
|
|
|
|
self.album.is_some()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn has_album_artist(self: &Self) -> bool {
|
|
|
|
self.album_artist.is_some()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_empty(self: &Self) -> bool {
|
|
|
|
return self.path.is_none()
|
|
|
|
&& self.title.is_none()
|
|
|
|
&& self.artist.is_none()
|
|
|
|
&& self.album.is_none()
|
|
|
|
&& self.album_artist.is_none();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
2022-12-18 18:26:13 -08:00
|
|
|
pub enum SkipDirection {
|
|
|
|
Forward,
|
|
|
|
Backward,
|
|
|
|
}
|
|
|
|
|
2022-12-18 21:07:33 -08:00
|
|
|
#[derive(Serialize, Deserialize)]
|
2022-12-18 18:26:13 -08:00
|
|
|
pub enum UIRequest {
|
|
|
|
Play,
|
|
|
|
Pause,
|
|
|
|
Skip(SkipDirection),
|
2022-12-18 21:07:33 -08:00
|
|
|
GetList(String),
|
2022-12-18 18:26:13 -08:00
|
|
|
SwitchTo(PartialTag),
|
|
|
|
GetStatus,
|
|
|
|
}
|
|
|
|
|
2022-12-18 21:07:33 -08:00
|
|
|
pub fn handle_request(socket_message: String) -> Result<UIRequest, serde_json::Error> {
|
2022-12-18 18:26:13 -08:00
|
|
|
println!("Recieved a socket message: {}", socket_message);
|
2022-12-18 21:07:33 -08:00
|
|
|
let request: UIRequest = serde_json::from_str(&socket_message)?;
|
|
|
|
Ok(request)
|
2022-12-18 18:26:13 -08:00
|
|
|
}
|