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 async_channel::{Receiver, Sender};
use rcue::cue::Command;
use discord_presence::models::Command;
use uuid::Uuid;
use crate::music_storage::{
@ -192,6 +192,15 @@ impl ControllerHandle {
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> {
let (command, tx) = PlayerCommandInput::command(PlayerCommand::Play);
self.player_mail_rx.send(command).await.unwrap();

View file

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

View file

@ -322,11 +322,22 @@ pub async fn clear_queue(
#[tauri::command]
pub async fn queue_move_to(
app: AppHandle<Wry>,
ctrl_handle: State<'_, ControllerHandle>,
index: usize,
) -> Result<(), String> {
ctrl_handle
.queue_move_to(index)
.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) {
const removeFromQueue = () => {
invoke('remove_from_queue', { index: selectedSong.current.index }).then(() => {})
invoke('remove_from_queue', { index: selectedSong.current.index }).then(() => {});
}
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 clearQueue = () => invoke('clear_queue').then();