Added default image when none is present

This commit is contained in:
MrDulfin 2024-12-15 15:34:20 -05:00
parent d8cf8eeb2b
commit 2d9f441a76
10 changed files with 44 additions and 23 deletions

View file

@ -117,7 +117,8 @@ pub enum QueueCommand {
pub enum QueueResponse { pub enum QueueResponse {
Ok, Ok,
Item(QueueItem<QueueSong, QueueAlbum>), Item(QueueItem<QueueSong, QueueAlbum>),
Get(Vec<QueueItem<QueueSong, QueueAlbum>>) GetAll(Vec<QueueItem<QueueSong, QueueAlbum>>),
Err(QueueError),
} }
@ -185,7 +186,7 @@ impl<'c, P: Player + Send + Sync> Controller<'c, P> {
loop_: false, loop_: false,
shuffle: None, shuffle: None,
}; };
// for testing porpuses
// for song in &library.library { // for song in &library.library {
// queue.add_item( // queue.add_item(
// QueueSong { // QueueSong {
@ -267,11 +268,13 @@ impl<'c, P: Player + Send + Sync> Controller<'c, P> {
let QueueResponse::Item(item) = queue_mail.recv().await.unwrap() else { unimplemented!() }; let QueueResponse::Item(item) = queue_mail.recv().await.unwrap() else { unimplemented!() };
let QueueItemType::Single(song) = item.item else { unimplemented!("This is temporary, handle queueItemTypes at some point") }; let QueueItemType::Single(song) = item.item else { unimplemented!("This is temporary, handle queueItemTypes at some point") };
player.write().unwrap().enqueue_next(song.song.primary_uri().unwrap().0).unwrap(); player.write().unwrap().enqueue_next(song.song.primary_uri().unwrap().0).unwrap();
player_mail.send(PlayerResponse::NowPlaying(song.song)).await.unwrap();
first = false first = false
} } else {
player.write().unwrap().play().unwrap(); player.write().unwrap().play().unwrap();
player_mail.send(PlayerResponse::Empty).await.unwrap(); player_mail.send(PlayerResponse::Empty).await.unwrap();
} }
}
PlayerCommand::Pause => { PlayerCommand::Pause => {
player.write().unwrap().pause().unwrap(); player.write().unwrap().pause().unwrap();
player_mail.send(PlayerResponse::Empty).await.unwrap(); player_mail.send(PlayerResponse::Empty).await.unwrap();
@ -441,7 +444,7 @@ impl<'c, P: Player + Send + Sync> Controller<'c, P> {
.unwrap(); .unwrap();
} }
QueueCommand::Get => { QueueCommand::Get => {
queue_mail.send(QueueResponse::Get(queue.items.clone())).await.unwrap(); queue_mail.send(QueueResponse::GetAll(queue.items.clone())).await.unwrap();
} }
} }
} }

View file

@ -1,4 +1,4 @@
use super::playlist::PlaylistFolder; use super::playlist::{Playlist, PlaylistFolder};
// Crate things // Crate things
use super::utils::{find_images, normalize, read_file, write_file}; use super::utils::{find_images, normalize, read_file, write_file};
use crate::config::Config; use crate::config::Config;
@ -822,6 +822,7 @@ impl MusicLibrary {
fn query_path(&self, path: PathBuf) -> Option<Vec<&Song>> { fn query_path(&self, path: PathBuf) -> Option<Vec<&Song>> {
let result: Arc<Mutex<Vec<&Song>>> = Arc::new(Mutex::new(Vec::new())); let result: Arc<Mutex<Vec<&Song>>> = Arc::new(Mutex::new(Vec::new()));
self.library.par_iter().for_each(|track| { self.library.par_iter().for_each(|track| {
// dbg!(&track);
if path == track.primary_uri().unwrap().0.path() { if path == track.primary_uri().unwrap().0.path() {
//TODO: make this also not unwrap //TODO: make this also not unwrap
Arc::clone(&result).lock().unwrap().push(track); Arc::clone(&result).lock().unwrap().push(track);
@ -1235,6 +1236,10 @@ impl MusicLibrary {
Ok(albums) Ok(albums)
} }
pub fn query_playlist_uuid(&self, uuid: &Uuid) -> Result<Playlist, Box<dyn Error>> {
todo!()
}
} }
#[cfg(test)] #[cfg(test)]

View file

@ -48,6 +48,7 @@ pub struct Playlist {
play_count: i32, play_count: i32,
play_time: Duration, play_time: Duration,
} }
impl Playlist { impl Playlist {
pub fn new() -> Self { pub fn new() -> Self {
Default::default() Default::default()

View file

@ -425,7 +425,7 @@ impl<
use thiserror::Error; use thiserror::Error;
#[derive(Error, Debug)] #[derive(Error, Debug, Clone)]
pub enum QueueError { pub enum QueueError {
#[error("Index out of bounds! Index {index} is over len {len}")] #[error("Index out of bounds! Index {index} is over len {len}")]
OutOfBounds { index: usize, len: usize }, OutOfBounds { index: usize, len: usize },

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

View file

@ -11,6 +11,8 @@ use crate::wrappers::{get_library, play, pause, prev, set_volume, get_song, next
pub mod wrappers; pub mod wrappers;
pub mod commands; pub mod commands;
const DEFAULT_IMAGE: &[u8] = include_bytes!("../icons/icon.png");
#[cfg_attr(mobile, tauri::mobile_entry_point)] #[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() { pub fn run() {
let (rx, tx) = unbounded::<Config>(); let (rx, tx) = unbounded::<Config>();
@ -32,9 +34,9 @@ pub fn run() {
).unwrap(); ).unwrap();
let scan_path = scan_path.unwrap_or_else(|| config.libraries.get_default().unwrap().scan_folders.as_ref().unwrap()[0].clone()); let scan_path = scan_path.unwrap_or_else(|| config.libraries.get_default().unwrap().scan_folders.as_ref().unwrap()[0].clone());
// library.scan_folder(&scan_path).unwrap();
if config.libraries.get_default().is_err() { if config.libraries.get_default().is_err() {
library.scan_folder(&scan_path).unwrap();
config.push_library( ConfigLibrary::new(save_path.clone(), String::from("Library"), Some(vec![scan_path.clone()]))); config.push_library( ConfigLibrary::new(save_path.clone(), String::from("Library"), Some(vec![scan_path.clone()])));
} }
if library.library.is_empty() { if library.library.is_empty() {
@ -86,12 +88,14 @@ pub fn run() {
.unwrap() .unwrap()
.to_string(); .to_string();
let bytes = futures::executor::block_on(async move { let bytes = if query.as_str() == "default" { DEFAULT_IMAGE.to_vec() }
else {
futures::executor::block_on(async move {
let controller = ctx.app_handle().state::<ControllerHandle>(); let controller = ctx.app_handle().state::<ControllerHandle>();
controller.lib_mail.send(dmp_core::music_controller::controller::LibraryCommand::Song(Uuid::parse_str(query.as_str()).unwrap())).await.unwrap(); controller.lib_mail.send(dmp_core::music_controller::controller::LibraryCommand::Song(Uuid::parse_str(query.as_str()).unwrap())).await.unwrap();
let LibraryResponse::Song(song) = controller.lib_mail.recv().await.unwrap() else { unreachable!() }; let LibraryResponse::Song(song) = controller.lib_mail.recv().await.unwrap() else { unreachable!() };
song.album_art(0).unwrap_or_else(|_| None).unwrap_or_default() song.album_art(0).unwrap_or_else(|_| None).unwrap_or(DEFAULT_IMAGE.to_vec())
}); })};
res.respond( res.respond(
@ -102,7 +106,6 @@ pub fn run() {
.body(bytes) .body(bytes)
.unwrap() .unwrap()
); );
println!("res sent")
}) })
.build(tauri::generate_context!()) .build(tauri::generate_context!())
.expect("error while building tauri application"); .expect("error while building tauri application");
@ -121,6 +124,7 @@ struct ConfigRx(Sender<Config>);
struct LibRx(Sender<Option<PathBuf>>); struct LibRx(Sender<Option<PathBuf>>);
struct HandleTx(Receiver<ControllerHandle>); struct HandleTx(Receiver<ControllerHandle>);
struct DefaultImage<'a>(&'a [u8]);
#[tauri::command] #[tauri::command]

View file

@ -12,9 +12,13 @@ use uuid::Uuid;
pub struct ArtworkRx(pub Sender<Vec<u8>>); pub struct ArtworkRx(pub Sender<Vec<u8>>);
#[tauri::command] #[tauri::command]
pub async fn play(ctrl_handle: State<'_, ControllerHandle>) -> Result<(), String> { pub async fn play(app: AppHandle<Wry>, ctrl_handle: State<'_, ControllerHandle>) -> Result<(), String> {
ctrl_handle.player_mail.send(dmp_core::music_controller::controller::PlayerCommand::Play).await.unwrap(); ctrl_handle.player_mail.send(dmp_core::music_controller::controller::PlayerCommand::Play).await.unwrap();
let PlayerResponse::Empty = ctrl_handle.player_mail.recv().await.unwrap() else { let res = ctrl_handle.player_mail.recv().await.unwrap();
if let PlayerResponse::Empty = res {}
else if let PlayerResponse::NowPlaying(song) = res {
app.emit("now_playing_change", _Song::from(&song)).unwrap();
} else {
unreachable!() unreachable!()
}; };
Ok(()) Ok(())
@ -78,7 +82,7 @@ pub async fn now_playing(ctrl_handle: State<'_, ControllerHandle>) -> Result<(),
#[tauri::command] #[tauri::command]
pub async fn get_queue(ctrl_handle: State<'_, ControllerHandle>) -> Result<Vec<_Song>, String> { pub async fn get_queue(ctrl_handle: State<'_, ControllerHandle>) -> Result<Vec<_Song>, String> {
ctrl_handle.queue_mail.send(QueueCommand::Get).await.unwrap(); ctrl_handle.queue_mail.send(QueueCommand::Get).await.unwrap();
let QueueResponse::Get(queue) = ctrl_handle.queue_mail.recv().await.unwrap() else { let QueueResponse::GetAll(queue) = ctrl_handle.queue_mail.recv().await.unwrap() else {
unreachable!() unreachable!()
}; };
Ok(queue.into_iter().map(|item| { Ok(queue.into_iter().map(|item| {

View file

@ -1,6 +1,7 @@
{ {
"$schema": "https://schema.tauri.app/config/2", "$schema": "https://schema.tauri.app/config/2",
"productName": "Dango Music Player", "productName": "Dango Music Player",
"mainBinaryName": "DMP",
"version": "0.0.1", "version": "0.0.1",
"identifier": "com.dango-music-player.app", "identifier": "com.dango-music-player.app",
"build": { "build": {

View file

@ -18,7 +18,7 @@ function App() {
title="Title" title="Title"
album="Album" album="Album"
artist="Artist" artist="Artist"
artwork={<></>} artwork={<img src={convertFileSrc("abc") + "?" + "default" } id="nowPlayingArtwork" alt="Now Playing Artwork" key={'default_image'} />}
/> />
); );

View file

@ -1,7 +1,10 @@
import React from "react"; import React, { StrictMode } from "react";
import ReactDOM from "react-dom/client"; import ReactDOM from "react-dom/client";
import App from "./App"; import App from "./App";
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render( ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
<App />, // <StrictMode>
// <App />
// </StrictMode>
<App />
); );