mirror of
https://github.com/Dangoware/dango-music-player.git
synced 2025-06-22 22:52:59 -05:00
Added "Clear Queue" and "Remove from Queue" buttons to QueueSong context menu
This commit is contained in:
parent
158e80cc8d
commit
5666581c7f
4 changed files with 30 additions and 7 deletions
|
@ -1,7 +1,7 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use async_channel::{Receiver, Sender};
|
||||
use discord_presence::models::Command;
|
||||
use discord_presence::models::{Command, commands};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::music_storage::{
|
||||
|
@ -147,6 +147,15 @@ impl ControllerHandle {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn queue_clear(&self) -> Result<(), QueueError> {
|
||||
let (command, tx) = QueueCommandInput::command(QueueCommand::Clear);
|
||||
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<Song, QueueError> {
|
||||
let (command, tx) = PlayerCommandInput::command(PlayerCommand::PlayNow(uuid, location));
|
||||
|
|
|
@ -24,9 +24,9 @@ use uuid::Uuid;
|
|||
use wrappers::{_Song, stop};
|
||||
|
||||
use crate::wrappers::{
|
||||
add_song_to_playlist, delete_playlist, get_library, get_playlist, get_playlists, get_queue,
|
||||
get_song, import_playlist, next, pause, play, play_next_queue, prev, remove_from_queue, seek,
|
||||
set_volume,
|
||||
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,
|
||||
remove_from_queue, seek, set_volume,
|
||||
};
|
||||
use commands::{add_song_to_queue, display_album_art, last_fm_init_auth, play_now};
|
||||
|
||||
|
@ -73,6 +73,7 @@ pub fn run() {
|
|||
add_song_to_playlist,
|
||||
delete_playlist,
|
||||
play_next_queue,
|
||||
clear_queue,
|
||||
// test_menu,
|
||||
])
|
||||
.manage(tempfile::TempDir::new().unwrap())
|
||||
|
|
|
@ -309,3 +309,13 @@ pub async fn play_next_queue(
|
|||
app.emit("queue_updated", ()).unwrap();
|
||||
res
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn clear_queue(
|
||||
app: AppHandle<Wry>,
|
||||
ctrl_handle: State<'_, ControllerHandle>,
|
||||
) -> Result<(), String> {
|
||||
let res = ctrl_handle.queue_clear().await.map_err(|e| e.to_string());
|
||||
app.emit("queue_updated", ());
|
||||
res
|
||||
}
|
||||
|
|
|
@ -472,15 +472,18 @@ function QueueSong({ song, location, index }: QueueSongProps) {
|
|||
const playNow = () => {
|
||||
invoke('play_now', { uuid: song.uuid, location: location }).then(() => {})
|
||||
}
|
||||
const play_next = () => invoke('play_next_queue', { uuid: song.uuid, location }).then(() => {});
|
||||
const playNext = () => invoke('play_next_queue', { uuid: song.uuid, location }).then(() => {});
|
||||
const clearQueue = () => invoke('clear_queue').then();
|
||||
|
||||
async function menuHandler(event: React.MouseEvent) {
|
||||
event.preventDefault();
|
||||
|
||||
const menu = await Menu.new({
|
||||
items: [
|
||||
{ id: "play_next_" + song.uuid + index, text: "Play Next in Queue", action: play_next },
|
||||
{ id: "remove_queue" + song.uuid + index, text: "Remove from Queue", action: removeFromQueue }
|
||||
{ id: "play_now" + index, text: "Play Now", action: playNow },
|
||||
{ id: "play_next_" + song.uuid + index, text: "Play Next in Queue", action: playNext },
|
||||
{ id: "remove_queue" + song.uuid + index, text: "Remove from Queue", action: removeFromQueue },
|
||||
{ id: "clear_queue", text: "Clear Queue", action: clearQueue },
|
||||
]
|
||||
})
|
||||
menu.popup();
|
||||
|
|
Loading…
Reference in a new issue