From 407b53e941aff06872cfe904bac0b3eedebf5cba Mon Sep 17 00:00:00 2001 From: MrDulfin Date: Mon, 26 May 2025 20:09:15 -0400 Subject: [PATCH] changed queue to use move_to instead of play_now when selecting a song from the queue --- dmp-core/src/music_controller/controller.rs | 6 ++---- .../src/music_controller/controller_handle.rs | 10 ++++++++++ dmp-core/src/music_controller/queue_command.rs | 8 ++++++++ dmp-core/src/music_storage/queue.rs | 6 +++--- src-tauri/src/lib.rs | 3 ++- src-tauri/src/wrappers.rs | 11 +++++++++++ src/App.tsx | 15 +-------------- 7 files changed, 37 insertions(+), 22 deletions(-) diff --git a/dmp-core/src/music_controller/controller.rs b/dmp-core/src/music_controller/controller.rs index 8c94836..5bdf3fc 100644 --- a/dmp-core/src/music_controller/controller.rs +++ b/dmp-core/src/music_controller/controller.rs @@ -109,10 +109,7 @@ pub enum LibraryCommand { AllSongs, GetLibrary, ExternalPlaylist(Uuid), - PlaylistSong{ - list_uuid: Uuid, - item_uuid: Uuid - }, + PlaylistSong { list_uuid: Uuid, item_uuid: Uuid }, Playlist(Uuid), ImportM3UPlayList(PathBuf), Save, @@ -142,6 +139,7 @@ pub enum QueueCommand { Get, Clear, Remove(usize), + MoveTo(usize), } #[derive(Debug, PartialEq, Clone)] diff --git a/dmp-core/src/music_controller/controller_handle.rs b/dmp-core/src/music_controller/controller_handle.rs index 146fec4..86fe3ce 100644 --- a/dmp-core/src/music_controller/controller_handle.rs +++ b/dmp-core/src/music_controller/controller_handle.rs @@ -1,6 +1,7 @@ use std::path::PathBuf; use async_channel::{Receiver, Sender}; +use rcue::cue::Command; use uuid::Uuid; use crate::music_storage::{ @@ -108,6 +109,15 @@ impl ControllerHandle { queue } + pub async fn queue_move_to(&self, index: usize) -> Result<(), QueueError> { + let (command, tx) = QueueCommandInput::command(QueueCommand::MoveTo(index)); + self.queue_mail_rx.send(command).await.unwrap(); + let QueueResponse::Empty(res) = tx.recv().await.unwrap() else { + unreachable!() + }; + res + } + // The Player Section pub async fn play_now(&self, uuid: Uuid, location: PlayerLocation) -> Result { let (command, tx) = PlayerCommandInput::command(PlayerCommand::PlayNow(uuid, location)); diff --git a/dmp-core/src/music_controller/queue_command.rs b/dmp-core/src/music_controller/queue_command.rs index caafc48..261cf6c 100644 --- a/dmp-core/src/music_controller/queue_command.rs +++ b/dmp-core/src/music_controller/queue_command.rs @@ -1,3 +1,5 @@ +use rayon::iter::IndexedParallelIterator; + use crate::music_storage::queue::{Queue, QueueError, QueueItemType}; use super::{ @@ -69,6 +71,12 @@ impl Controller { .await .unwrap(); } + QueueCommand::MoveTo(index) => { + res_rx + .send(QueueResponse::Empty(queue.move_to(index))) + .await + .unwrap(); + } } } } diff --git a/dmp-core/src/music_storage/queue.rs b/dmp-core/src/music_storage/queue.rs index 8e4b929..225870a 100644 --- a/dmp-core/src/music_storage/queue.rs +++ b/dmp-core/src/music_storage/queue.rs @@ -30,9 +30,9 @@ pub enum QueueItemType< } impl< - T: Debug + Clone + PartialEq, // T: The Singular Item Type - U: Debug + PartialEq + Clone + IntoIterator, // U: The Multi-Item Type. Needs to be tracked as multiple items - > QueueItemType + T: Debug + Clone + PartialEq, // T: The Singular Item Type + U: Debug + PartialEq + Clone + IntoIterator, // U: The Multi-Item Type. Needs to be tracked as multiple items +> QueueItemType { pub fn from_single(item: T) -> Self { QueueItemType::Single(item) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 2e60e65..efea8db 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -25,7 +25,7 @@ use wrappers::{_Song, stop}; use crate::wrappers::{ get_library, get_playlist, get_playlists, get_queue, get_song, import_playlist, next, pause, - play, prev, remove_from_queue, seek, set_volume, + play, prev, queue_move_to, remove_from_queue, seek, set_volume, }; use commands::{add_song_to_queue, display_album_art, last_fm_init_auth, play_now}; @@ -69,6 +69,7 @@ pub fn run() { save_config, close_window, start_controller, + queue_move_to, // test_menu, ]) .manage(tempfile::TempDir::new().unwrap()) diff --git a/src-tauri/src/wrappers.rs b/src-tauri/src/wrappers.rs index e03f579..e1e6cb9 100644 --- a/src-tauri/src/wrappers.rs +++ b/src-tauri/src/wrappers.rs @@ -272,3 +272,14 @@ pub async fn get_song( pub async fn seek(ctrl_handle: State<'_, ControllerHandle>, time: i64) -> Result<(), String> { ctrl_handle.seek(time).await.map_err(|e| e.to_string()) } + +#[tauri::command] +pub async fn queue_move_to( + ctrl_handle: State<'_, ControllerHandle>, + index: usize, +) -> Result<(), String> { + ctrl_handle + .queue_move_to(index) + .await + .map_err(|e| e.to_string()) +} diff --git a/src/App.tsx b/src/App.tsx index 7bb3fe7..946ca5c 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -277,19 +277,6 @@ function Song(props: SongProps) { menu.popup(pos); } - // useEffect(() => { - // const unlistenPromise = listen("add_song_to_queue", (event) => { - // switch (event.payload) { - // default: - // console.log("Unimplemented application menu id:", event.payload); - // } - // }); - - // return () => { - // unlistenPromise.then((unlisten) => unlisten()); - // }; - // }, []); - return(
{ @@ -424,7 +411,7 @@ function QueueSong({ song, location, index }: QueueSongProps) { } let playNow = () => { - invoke('play_now', { uuid: song.uuid, location: location }).then(() => {}) + invoke('queue_move_to', { index: index }).then(() => {}) } return (