diff --git a/dmp-core/src/music_controller/controller.rs b/dmp-core/src/music_controller/controller.rs index 41411eb..1b40033 100644 --- a/dmp-core/src/music_controller/controller.rs +++ b/dmp-core/src/music_controller/controller.rs @@ -117,7 +117,8 @@ pub enum QueueCommand { pub enum QueueResponse { Ok, Item(QueueItem), - Get(Vec>) + GetAll(Vec>), + Err(QueueError), } @@ -185,7 +186,7 @@ impl<'c, P: Player + Send + Sync> Controller<'c, P> { loop_: false, shuffle: None, }; - + // for testing porpuses // for song in &library.library { // queue.add_item( // QueueSong { @@ -267,10 +268,12 @@ impl<'c, P: Player + Send + Sync> Controller<'c, P> { 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") }; player.write().unwrap().enqueue_next(song.song.primary_uri().unwrap().0).unwrap(); + player_mail.send(PlayerResponse::NowPlaying(song.song)).await.unwrap(); first = false + } else { + player.write().unwrap().play().unwrap(); + player_mail.send(PlayerResponse::Empty).await.unwrap(); } - player.write().unwrap().play().unwrap(); - player_mail.send(PlayerResponse::Empty).await.unwrap(); } PlayerCommand::Pause => { player.write().unwrap().pause().unwrap(); @@ -441,7 +444,7 @@ impl<'c, P: Player + Send + Sync> Controller<'c, P> { .unwrap(); } QueueCommand::Get => { - queue_mail.send(QueueResponse::Get(queue.items.clone())).await.unwrap(); + queue_mail.send(QueueResponse::GetAll(queue.items.clone())).await.unwrap(); } } } diff --git a/dmp-core/src/music_storage/library.rs b/dmp-core/src/music_storage/library.rs index 284f6d5..587419d 100644 --- a/dmp-core/src/music_storage/library.rs +++ b/dmp-core/src/music_storage/library.rs @@ -1,4 +1,4 @@ -use super::playlist::PlaylistFolder; +use super::playlist::{Playlist, PlaylistFolder}; // Crate things use super::utils::{find_images, normalize, read_file, write_file}; use crate::config::Config; @@ -822,6 +822,7 @@ impl MusicLibrary { fn query_path(&self, path: PathBuf) -> Option> { let result: Arc>> = Arc::new(Mutex::new(Vec::new())); self.library.par_iter().for_each(|track| { + // dbg!(&track); if path == track.primary_uri().unwrap().0.path() { //TODO: make this also not unwrap Arc::clone(&result).lock().unwrap().push(track); @@ -1235,6 +1236,10 @@ impl MusicLibrary { Ok(albums) } + + pub fn query_playlist_uuid(&self, uuid: &Uuid) -> Result> { + todo!() + } } #[cfg(test)] diff --git a/dmp-core/src/music_storage/playlist.rs b/dmp-core/src/music_storage/playlist.rs index c4c0d8c..30611d0 100644 --- a/dmp-core/src/music_storage/playlist.rs +++ b/dmp-core/src/music_storage/playlist.rs @@ -48,6 +48,7 @@ pub struct Playlist { play_count: i32, play_time: Duration, } + impl Playlist { pub fn new() -> Self { Default::default() diff --git a/kushi-queue/src/lib.rs b/kushi-queue/src/lib.rs index 8bd2668..bbe466b 100644 --- a/kushi-queue/src/lib.rs +++ b/kushi-queue/src/lib.rs @@ -425,7 +425,7 @@ impl< use thiserror::Error; -#[derive(Error, Debug)] +#[derive(Error, Debug, Clone)] pub enum QueueError { #[error("Index out of bounds! Index {index} is over len {len}")] OutOfBounds { index: usize, len: usize }, diff --git a/src-tauri/icons/icon-stickless.png b/src-tauri/icons/icon-stickless.png new file mode 100644 index 0000000..f87568c Binary files /dev/null and b/src-tauri/icons/icon-stickless.png differ diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index bebbf7b..937b6af 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -11,6 +11,8 @@ use crate::wrappers::{get_library, play, pause, prev, set_volume, get_song, next pub mod wrappers; pub mod commands; +const DEFAULT_IMAGE: &[u8] = include_bytes!("../icons/icon.png"); + #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { let (rx, tx) = unbounded::(); @@ -32,9 +34,9 @@ pub fn run() { ).unwrap(); 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() { + library.scan_folder(&scan_path).unwrap(); config.push_library( ConfigLibrary::new(save_path.clone(), String::from("Library"), Some(vec![scan_path.clone()]))); } if library.library.is_empty() { @@ -86,23 +88,24 @@ pub fn run() { .unwrap() .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::(); 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!() }; - 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( Response::builder() - .header("Origin", "*") - .header("Content-Length", bytes.len()) - .status(200) - .body(bytes) - .unwrap() + .header("Origin", "*") + .header("Content-Length", bytes.len()) + .status(200) + .body(bytes) + .unwrap() ); - println!("res sent") }) .build(tauri::generate_context!()) .expect("error while building tauri application"); @@ -121,6 +124,7 @@ struct ConfigRx(Sender); struct LibRx(Sender>); struct HandleTx(Receiver); +struct DefaultImage<'a>(&'a [u8]); #[tauri::command] diff --git a/src-tauri/src/wrappers.rs b/src-tauri/src/wrappers.rs index cbbbfb2..e591705 100644 --- a/src-tauri/src/wrappers.rs +++ b/src-tauri/src/wrappers.rs @@ -12,9 +12,13 @@ use uuid::Uuid; pub struct ArtworkRx(pub Sender>); #[tauri::command] -pub async fn play(ctrl_handle: State<'_, ControllerHandle>) -> Result<(), String> { +pub async fn play(app: AppHandle, ctrl_handle: State<'_, ControllerHandle>) -> Result<(), String> { 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!() }; Ok(()) @@ -78,7 +82,7 @@ pub async fn now_playing(ctrl_handle: State<'_, ControllerHandle>) -> Result<(), #[tauri::command] pub async fn get_queue(ctrl_handle: State<'_, ControllerHandle>) -> Result, String> { 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!() }; Ok(queue.into_iter().map(|item| { diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index caddea4..ae2c4d3 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,6 +1,7 @@ { "$schema": "https://schema.tauri.app/config/2", "productName": "Dango Music Player", + "mainBinaryName": "DMP", "version": "0.0.1", "identifier": "com.dango-music-player.app", "build": { diff --git a/src/App.tsx b/src/App.tsx index 5f0ebe2..a354661 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -18,7 +18,7 @@ function App() { title="Title" album="Album" artist="Artist" - artwork={<>} + artwork={Now Playing Artwork} /> ); diff --git a/src/main.tsx b/src/main.tsx index 6c54cf6..37ea778 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -1,7 +1,10 @@ -import React from "react"; +import React, { StrictMode } from "react"; import ReactDOM from "react-dom/client"; import App from "./App"; ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render( - , + // + // + // + );