mirror of
https://github.com/Dangoware/dango-music-player.git
synced 2025-06-22 22:52:59 -05:00
Merge branch 'queue-fix'
This commit is contained in:
commit
1b26558812
7 changed files with 38 additions and 40 deletions
|
@ -144,6 +144,7 @@ pub enum QueueCommand {
|
||||||
Clear,
|
Clear,
|
||||||
Remove(usize),
|
Remove(usize),
|
||||||
PlayNext(QueueItem<QueueSong, QueueAlbum>, bool),
|
PlayNext(QueueItem<QueueSong, QueueAlbum>, bool),
|
||||||
|
MoveTo(usize),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use async_channel::{Receiver, Sender};
|
use async_channel::{Receiver, Sender};
|
||||||
use discord_presence::models::{Command, commands};
|
use rcue::cue::Command;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::music_storage::{
|
use crate::music_storage::{
|
||||||
|
@ -173,6 +173,15 @@ impl ControllerHandle {
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
// The Player Section
|
||||||
pub async fn play_now(&self, uuid: Uuid, location: PlayerLocation) -> Result<Song, QueueError> {
|
pub async fn play_now(&self, uuid: Uuid, location: PlayerLocation) -> Result<Song, QueueError> {
|
||||||
let (command, tx) = PlayerCommandInput::command(PlayerCommand::PlayNow(uuid, location));
|
let (command, tx) = PlayerCommandInput::command(PlayerCommand::PlayNow(uuid, location));
|
||||||
|
|
|
@ -83,6 +83,12 @@ impl Controller {
|
||||||
};
|
};
|
||||||
res_rx.send(QueueResponse::Empty(Ok(()))).await.unwrap();
|
res_rx.send(QueueResponse::Empty(Ok(()))).await.unwrap();
|
||||||
}
|
}
|
||||||
|
QueueCommand::MoveTo(index) => {
|
||||||
|
res_rx
|
||||||
|
.send(QueueResponse::Empty(queue.move_to(index)))
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -323,43 +323,13 @@ impl<T: Debug + Clone + PartialEq, U: Debug + PartialEq + Clone + IntoIterator>
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn move_to(&mut self, index: usize) -> Result<(), QueueError> {
|
pub fn move_to(&mut self, index: usize) -> Result<(), QueueError> {
|
||||||
use QueueState::*;
|
if self.items.is_empty() {
|
||||||
|
|
||||||
let empty = self.items.is_empty();
|
|
||||||
let index = if !empty {
|
|
||||||
index
|
|
||||||
} else {
|
|
||||||
return Err(QueueError::EmptyQueue);
|
|
||||||
};
|
|
||||||
|
|
||||||
if !empty && dbg!(index < self.items.len()) {
|
|
||||||
let to_item = self.items[index].clone();
|
|
||||||
|
|
||||||
if let QueueItemType::Multi(_) = to_item.item {
|
|
||||||
unimplemented!(); //TODO: Add logic for multi items
|
|
||||||
}
|
|
||||||
|
|
||||||
loop {
|
|
||||||
let empty = self.items.is_empty();
|
|
||||||
let item = self.items[0].item.to_owned();
|
|
||||||
|
|
||||||
if item != to_item.item && !empty {
|
|
||||||
if self.items[0].state == AddHere && self.items.get(1).is_some() {
|
|
||||||
self.items[1].state = AddHere;
|
|
||||||
}
|
|
||||||
let item = self.items.remove(0);
|
|
||||||
self.played.push(item);
|
|
||||||
|
|
||||||
// dbg!(&to_item.item, &self.items[ind].item);
|
|
||||||
} else if empty {
|
|
||||||
return Err(QueueError::EmptyQueue);
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return Err(QueueError::EmptyQueue);
|
return Err(QueueError::EmptyQueue);
|
||||||
}
|
}
|
||||||
|
for _ in 0..index {
|
||||||
|
self.next()?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ use wrappers::{_Song, stop};
|
||||||
use crate::wrappers::{
|
use crate::wrappers::{
|
||||||
add_song_to_playlist, clear_queue, delete_playlist, get_library, get_playlist, get_playlists,
|
add_song_to_playlist, clear_queue, delete_playlist, get_library, get_playlist, get_playlists,
|
||||||
get_queue, get_song, import_playlist, next, pause, play, play_next_queue, prev,
|
get_queue, get_song, import_playlist, next, pause, play, play_next_queue, prev,
|
||||||
remove_from_queue, seek, set_volume,
|
remove_from_queue, seek, set_volume, queue_move_to
|
||||||
};
|
};
|
||||||
use commands::{
|
use commands::{
|
||||||
add_song_to_queue, display_album_art, last_fm_init_auth, play_now, remove_from_lib_playlist,
|
add_song_to_queue, display_album_art, last_fm_init_auth, play_now, remove_from_lib_playlist,
|
||||||
|
@ -77,6 +77,7 @@ pub fn run() {
|
||||||
play_next_queue,
|
play_next_queue,
|
||||||
clear_queue,
|
clear_queue,
|
||||||
remove_from_lib_playlist,
|
remove_from_lib_playlist,
|
||||||
|
queue_move_to,
|
||||||
// test_menu,
|
// test_menu,
|
||||||
])
|
])
|
||||||
.manage(tempfile::TempDir::new().unwrap())
|
.manage(tempfile::TempDir::new().unwrap())
|
||||||
|
|
|
@ -319,3 +319,14 @@ pub async fn clear_queue(
|
||||||
_ = app.emit("queue_updated", ());
|
_ = app.emit("queue_updated", ());
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[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())
|
||||||
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ function App() {
|
||||||
const playlistsInfo= useRef<PlaylistInfo[]>([]);
|
const playlistsInfo= useRef<PlaylistInfo[]>([]);
|
||||||
const selectedSongMain = useRef<SongProps>();
|
const selectedSongMain = useRef<SongProps>();
|
||||||
const selectedSongQueue = useRef<selectedQueueSong>({uuid: "0", index: 0, location: "Library"});
|
const selectedSongQueue = useRef<selectedQueueSong>({uuid: "0", index: 0, location: "Library"});
|
||||||
const setSelectedSongMain = (props: SongProps) => {selectedSongMain.current = props;}
|
const setSelectedSongMain = (props: SongProps) => {selectedSongMain.current = props;}
|
||||||
const setSelectedSongQueue = (song: selectedQueueSong) => {selectedSongQueue.current = song; console.log(selectedSongQueue)}
|
const setSelectedSongQueue = (song: selectedQueueSong) => {selectedSongQueue.current = song; console.log(selectedSongQueue)}
|
||||||
|
|
||||||
const [nowPlaying, setNowPlaying] = useState<JSX.Element>(
|
const [nowPlaying, setNowPlaying] = useState<JSX.Element>(
|
||||||
|
@ -132,7 +132,7 @@ interface PlaylistHeadProps {
|
||||||
|
|
||||||
function PlaylistHead({ playlists, setPlaylists, setViewName, setLibrary, playlistsInfo, setSelected }: PlaylistHeadProps) {
|
function PlaylistHead({ playlists, setPlaylists, setViewName, setLibrary, playlistsInfo, setSelected }: PlaylistHeadProps) {
|
||||||
function getPlaylist(playlist: PlaylistInfo) {
|
function getPlaylist(playlist: PlaylistInfo) {
|
||||||
invoke('get_playlist', { uuid: playlist.uuid }).then((list) => {
|
invoke('get_playlist', { uuid: playlist.uuid }).then((list) => {
|
||||||
setLibrary([...(list as any[]).map((song, i) => {
|
setLibrary([...(list as any[]).map((song, i) => {
|
||||||
// console.log(song);
|
// console.log(song);
|
||||||
const reload = () => getPlaylist(playlist)
|
const reload = () => getPlaylist(playlist)
|
||||||
|
@ -244,7 +244,7 @@ interface MainViewProps {
|
||||||
|
|
||||||
function MainView({ lib_ref, viewName, playlistsInfo, setSelected, selectedSong }: MainViewProps) {
|
function MainView({ lib_ref, viewName, playlistsInfo, setSelected, selectedSong }: MainViewProps) {
|
||||||
const [library, setLibrary] = lib_ref;
|
const [library, setLibrary] = lib_ref;
|
||||||
|
|
||||||
|
|
||||||
const addToQueue = (_: string) => {
|
const addToQueue = (_: string) => {
|
||||||
invoke('add_song_to_queue', { uuid: selectedSong.current!.uuid, location: selectedSong.current!.playerLocation }).then(() => {});
|
invoke('add_song_to_queue', { uuid: selectedSong.current!.uuid, location: selectedSong.current!.playerLocation }).then(() => {});
|
||||||
|
|
Loading…
Reference in a new issue