mirror of
https://github.com/Dangoware/dango-music-player.git
synced 2025-04-19 10:02:53 -05:00
Added Queue Navigation and removal
This commit is contained in:
parent
c03df6936f
commit
280b8db49e
3 changed files with 28 additions and 12 deletions
|
@ -6,7 +6,7 @@ use dmp_core::{config::{Config, ConfigLibrary}, music_controller::controller::{C
|
||||||
use tauri::{http::Response, Emitter, Manager, State, WebviewWindowBuilder, Wry};
|
use tauri::{http::Response, Emitter, Manager, State, WebviewWindowBuilder, Wry};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::wrappers::{get_library, play, pause, prev, set_volume, get_song, next, get_queue, import_playlist, get_playlist, get_playlists};
|
use crate::wrappers::{get_library, play, pause, prev, set_volume, get_song, next, get_queue, import_playlist, get_playlist, get_playlists, remove_from_queue};
|
||||||
|
|
||||||
pub mod wrappers;
|
pub mod wrappers;
|
||||||
pub mod commands;
|
pub mod commands;
|
||||||
|
@ -80,7 +80,8 @@ pub fn run() {
|
||||||
play_now,
|
play_now,
|
||||||
import_playlist,
|
import_playlist,
|
||||||
get_playlist,
|
get_playlist,
|
||||||
get_playlists
|
get_playlists,
|
||||||
|
remove_from_queue
|
||||||
]).manage(ConfigRx(rx))
|
]).manage(ConfigRx(rx))
|
||||||
.manage(LibRx(lib_rx))
|
.manage(LibRx(lib_rx))
|
||||||
.manage(HandleTx(handle_tx))
|
.manage(HandleTx(handle_tx))
|
||||||
|
|
|
@ -2,7 +2,7 @@ use std::{collections::BTreeMap, path::PathBuf};
|
||||||
|
|
||||||
use chrono::{DateTime, Utc, serde::ts_milliseconds_option};
|
use chrono::{DateTime, Utc, serde::ts_milliseconds_option};
|
||||||
use crossbeam::channel::Sender;
|
use crossbeam::channel::Sender;
|
||||||
use dmp_core::{music_controller::controller::{ControllerHandle, LibraryCommand, LibraryResponse, PlayerResponse, QueueCommand, QueueResponse}, music_storage::library::{Song, Tag, URI}};
|
use dmp_core::{music_controller::controller::{ControllerHandle, LibraryCommand, LibraryResponse, PlayerLocation, PlayerResponse, QueueCommand, QueueResponse}, music_storage::library::{Song, Tag, URI}};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use kushi::QueueItemType;
|
use kushi::QueueItemType;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
@ -78,7 +78,7 @@ pub async fn now_playing(ctrl_handle: State<'_, ControllerHandle>) -> Result<(),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn get_queue(ctrl_handle: State<'_, ControllerHandle>) -> Result<Vec<_Song>, String> {
|
pub async fn get_queue(ctrl_handle: State<'_, ControllerHandle>) -> Result<Vec<(_Song, PlayerLocation)>, String> {
|
||||||
Ok(
|
Ok(
|
||||||
ctrl_handle
|
ctrl_handle
|
||||||
.queue_get_all()
|
.queue_get_all()
|
||||||
|
@ -86,14 +86,14 @@ pub async fn get_queue(ctrl_handle: State<'_, ControllerHandle>) -> Result<Vec<_
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|item| {
|
.map(|item| {
|
||||||
let QueueItemType::Single(song) = item.item else { unreachable!("There should be no albums in the queue right now") };
|
let QueueItemType::Single(song) = item.item else { unreachable!("There should be no albums in the queue right now") };
|
||||||
_Song::from(&song.song)
|
(_Song::from(&song.song), song.location)
|
||||||
}
|
}
|
||||||
).collect_vec()
|
).collect_vec()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn remove_from_queue(app: AppHandle<Wry>, ctrl_handle: ControllerHandle, index: usize) -> Result<(), String> {
|
pub async fn remove_from_queue(app: AppHandle<Wry>, ctrl_handle: State<'_, ControllerHandle>, index: usize) -> Result<(), String> {
|
||||||
match ctrl_handle.queue_remove(index).await {
|
match ctrl_handle.queue_remove(index).await {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
app.emit("queue_updated", ()).unwrap();
|
app.emit("queue_updated", ()).unwrap();
|
||||||
|
|
27
src/App.tsx
27
src/App.tsx
|
@ -47,7 +47,14 @@ function App() {
|
||||||
invoke('get_queue').then((_songs) => {
|
invoke('get_queue').then((_songs) => {
|
||||||
let songs = _songs as any[]
|
let songs = _songs as any[]
|
||||||
setQueue(
|
setQueue(
|
||||||
songs.filter((_, i) => i != 0).map((song) => <QueueSong song={ song } key={ song.uuid + '_' + Math.floor((Math.random() * 100_000) + 1) + '_' + Date.now() } />)
|
songs.filter((_, i) => i != 0).map((song, i) =>
|
||||||
|
<QueueSong
|
||||||
|
song={ song[0] }
|
||||||
|
location={ song[1] as "Library" | {"Playlist" : string}}
|
||||||
|
index={i+1}
|
||||||
|
key={ song.uuid + '_' + Math.floor((Math.random() * 100_000) + 1) + '_' + Date.now() }
|
||||||
|
/>
|
||||||
|
)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -329,22 +336,30 @@ function Queue({ songs }: QueueProps) {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface QueueSongProps {
|
interface QueueSongProps {
|
||||||
song: any
|
song: any,
|
||||||
|
location: "Library" | {"Playlist": string},
|
||||||
|
index: number,
|
||||||
}
|
}
|
||||||
|
|
||||||
function QueueSong({ song }: QueueSongProps) {
|
function QueueSong({ song, location, index }: QueueSongProps) {
|
||||||
console.log(song.tags);
|
console.log(song.tags);
|
||||||
|
|
||||||
|
let removeFromQueue = () => {
|
||||||
|
invoke('remove_from_queue', { index: index }).then(() => {})
|
||||||
|
}
|
||||||
|
|
||||||
|
let playNow = () => {
|
||||||
|
invoke('play_now', { uuid: song.uuid, location: location }).then(() => {})
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
// <button className="queueSongButton">
|
<div className="queueSong" onAuxClick={ removeFromQueue } onClickCapture={ playNow }>
|
||||||
<div className="queueSong">
|
|
||||||
<img className="queueSongCoverArt" src={ convertFileSrc('abc') + '?' + song.uuid } key={ 'coverArt_' + song.uuid }/>
|
<img className="queueSongCoverArt" src={ convertFileSrc('abc') + '?' + song.uuid } key={ 'coverArt_' + song.uuid }/>
|
||||||
<div className="queueSongTags">
|
<div className="queueSongTags">
|
||||||
<p className="queueSongTitle">{ song.tags.TrackTitle }</p>
|
<p className="queueSongTitle">{ song.tags.TrackTitle }</p>
|
||||||
<p className="queueSongArtist">{ song.tags.TrackArtist }</p>
|
<p className="queueSongArtist">{ song.tags.TrackArtist }</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
// </button>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue