changed the playNow function in the queue to move forward to the selected index

This commit is contained in:
MrDulfin 2025-06-06 23:21:34 -04:00
parent 1b26558812
commit b8280775fa
4 changed files with 80 additions and 42 deletions

View file

@ -1,7 +1,7 @@
use std::path::PathBuf; use std::path::PathBuf;
use async_channel::{Receiver, Sender}; use async_channel::{Receiver, Sender};
use rcue::cue::Command; use discord_presence::models::Command;
use uuid::Uuid; use uuid::Uuid;
use crate::music_storage::{ use crate::music_storage::{
@ -192,6 +192,15 @@ impl ControllerHandle {
res res
} }
pub async fn enqueue(&self, index: usize) -> Result<Song, QueueError> {
let (command, tx) = PlayerCommandInput::command(PlayerCommand::Enqueue(index));
self.player_mail_rx.send(command).await.unwrap();
let PlayerResponse::NowPlaying(song) = tx.recv().await.unwrap() else {
unreachable!()
};
song
}
pub async fn play(&self) -> Result<(), PlayerError> { pub async fn play(&self) -> Result<(), PlayerError> {
let (command, tx) = PlayerCommandInput::command(PlayerCommand::Play); let (command, tx) = PlayerCommandInput::command(PlayerCommand::Play);
self.player_mail_rx.send(command).await.unwrap(); self.player_mail_rx.send(command).await.unwrap();

View file

@ -97,7 +97,8 @@ impl Controller {
LibraryCommandInput::command(LibraryCommand::AllSongs); LibraryCommandInput::command(LibraryCommand::AllSongs);
// Append next song in library // Append next song in library
lib_mail.send(command).await.unwrap(); lib_mail.send(command).await.unwrap();
let LibraryResponse::AllSongs(songs) = tx.recv().await.unwrap() let LibraryResponse::AllSongs(songs) =
tx.recv().await.unwrap()
else { else {
continue; continue;
}; };
@ -105,22 +106,24 @@ impl Controller {
LibraryCommand::Song(np_song.song.uuid), LibraryCommand::Song(np_song.song.uuid),
); );
lib_mail.send(command).await.unwrap(); lib_mail.send(command).await.unwrap();
let LibraryResponse::Song(_, i) = tx.recv().await.unwrap() else { let LibraryResponse::Song(_, i) = tx.recv().await.unwrap()
else {
unreachable!() unreachable!()
}; };
if let Some(song) = songs.get(i + 49) { if let Some(song) = songs.get(i + 49) {
let (command, tx) = let (command, tx) =
QueueCommandInput::command(QueueCommand::Append( QueueCommandInput::command(QueueCommand::Append(
QueueItem::from_item_type(QueueItemType::Single( QueueItem::from_item_type(
QueueSong { QueueItemType::Single(QueueSong {
song: song.clone(), song: song.clone(),
location: np_song.location, location: np_song.location,
}, }),
)), ),
false, false,
)); ));
queue_mail.send(command).await.unwrap(); queue_mail.send(command).await.unwrap();
let QueueResponse::Empty(Ok(())) = tx.recv().await.unwrap() let QueueResponse::Empty(Ok(())) =
tx.recv().await.unwrap()
else { else {
unreachable!() unreachable!()
}; };
@ -133,29 +136,37 @@ impl Controller {
LibraryCommand::ExternalPlaylist(uuid), LibraryCommand::ExternalPlaylist(uuid),
); );
lib_mail.send(command).await.unwrap(); lib_mail.send(command).await.unwrap();
let LibraryResponse::ExternalPlaylist(playlist) = tx.recv().await.unwrap() else { let LibraryResponse::ExternalPlaylist(playlist) =
tx.recv().await.unwrap()
else {
unreachable!() unreachable!()
}; };
let (command, tx) = LibraryCommandInput::command( let (command, tx) = LibraryCommandInput::command(
LibraryCommand::PlaylistSong { list_uuid: playlist.uuid, item_uuid: np_song.song.uuid } LibraryCommand::PlaylistSong {
list_uuid: playlist.uuid,
item_uuid: np_song.song.uuid,
},
); );
lib_mail.send(command).await.unwrap(); lib_mail.send(command).await.unwrap();
let LibraryResponse::PlaylistSong(_, i) = tx.recv().await.unwrap() else { let LibraryResponse::PlaylistSong(_, i) =
tx.recv().await.unwrap()
else {
unreachable!() unreachable!()
}; };
if let Some(song) = playlist.tracks.get(i + 49) { if let Some(song) = playlist.tracks.get(i + 49) {
let (command, tx) = let (command, tx) =
QueueCommandInput::command(QueueCommand::Append( QueueCommandInput::command(QueueCommand::Append(
QueueItem::from_item_type(QueueItemType::Single( QueueItem::from_item_type(
QueueSong { QueueItemType::Single(QueueSong {
song: song.clone(), song: song.clone(),
location: np_song.location, location: np_song.location,
}, }),
)), ),
false, false,
)); ));
queue_mail.send(command).await.unwrap(); queue_mail.send(command).await.unwrap();
let QueueResponse::Empty(Ok(())) = tx.recv().await.unwrap() let QueueResponse::Empty(Ok(())) =
tx.recv().await.unwrap()
else { else {
unreachable!() unreachable!()
}; };
@ -163,7 +174,7 @@ impl Controller {
println!("Playlist Empty"); println!("Playlist Empty");
} }
} }
_ => todo!() _ => todo!(),
} }
res_rx res_rx
.send(PlayerResponse::NowPlaying(Ok(np_song.song.clone()))) .send(PlayerResponse::NowPlaying(Ok(np_song.song.clone())))
@ -234,7 +245,7 @@ impl Controller {
queue_mail.send(command).await.unwrap(); queue_mail.send(command).await.unwrap();
match tx.recv().await.unwrap() { match tx.recv().await.unwrap() {
QueueResponse::Item(Ok(item)) => { QueueResponse::Item(Ok(item)) => {
match item.item { let mut song = match item.item {
QueueItemType::Single(np_song) => { QueueItemType::Single(np_song) => {
let prism_uri = prismriver::utils::path_to_uri( let prism_uri = prismriver::utils::path_to_uri(
&np_song &np_song
@ -251,17 +262,24 @@ impl Controller {
state.now_playing = np_song.song.uuid; state.now_playing = np_song.song.uuid;
_ = state.write_file(); _ = state.write_file();
notify_connections_ notify_connections_
.send(ConnectionsNotification::SongChange(np_song.song)) .send(ConnectionsNotification::SongChange(
np_song.song.clone(),
))
.unwrap(); .unwrap();
np_song.song
} }
_ => unimplemented!(), _ => unimplemented!(),
} };
res_rx.send(PlayerResponse::Empty(Ok(()))).await.unwrap(); res_rx
.send(PlayerResponse::NowPlaying(Ok(song)))
.await
.unwrap();
} }
QueueResponse::Item(Err(e)) => { QueueResponse::Item(Err(e)) => {
res_rx res_rx
.send(PlayerResponse::Empty(Err(e.into()))) .send(PlayerResponse::NowPlaying(Err(e.into())))
.await .await
.unwrap(); .unwrap();
} }

View file

@ -322,11 +322,22 @@ pub async fn clear_queue(
#[tauri::command] #[tauri::command]
pub async fn queue_move_to( pub async fn queue_move_to(
app: AppHandle<Wry>,
ctrl_handle: State<'_, ControllerHandle>, ctrl_handle: State<'_, ControllerHandle>,
index: usize, index: usize,
) -> Result<(), String> { ) -> Result<(), String> {
ctrl_handle ctrl_handle
.queue_move_to(index) .queue_move_to(index)
.await .await
.map_err(|e| e.to_string()) .map_err(|e| e.to_string())?;
match ctrl_handle.enqueue(0).await.map_err(|e| e.to_string()) {
Ok(song) => {
app.emit("queue_updated", ()).unwrap();
app.emit("now_playing_change", _Song::from(&song)).unwrap();
app.emit("playing", true).unwrap();
Ok(())
}
Err(e) => Err(e),
}
} }

View file

@ -496,10 +496,10 @@ interface selectedQueueSong {
function Queue({ songs, selectedSong, }: QueueProps) { function Queue({ songs, selectedSong, }: QueueProps) {
const removeFromQueue = () => { const removeFromQueue = () => {
invoke('remove_from_queue', { index: selectedSong.current.index }).then(() => {}) invoke('remove_from_queue', { index: selectedSong.current.index }).then(() => {});
} }
const playNow = () => { const playNow = () => {
invoke('play_now', { uuid: selectedSong.current.uuid, location: selectedSong.current.location }).then(() => {}) invoke('queue_move_to', { index: selectedSong.current.index }).then(() => {});
} }
const playNext = () => invoke('play_next_queue', { uuid: selectedSong.current.uuid, location: selectedSong.current.location }).then(() => {}); const playNext = () => invoke('play_next_queue', { uuid: selectedSong.current.uuid, location: selectedSong.current.location }).then(() => {});
const clearQueue = () => invoke('clear_queue').then(); const clearQueue = () => invoke('clear_queue').then();