From 5666581c7f633a7a4f90cdb984c992cb4e48db2d Mon Sep 17 00:00:00 2001 From: MrDulfin Date: Sun, 1 Jun 2025 22:29:24 -0400 Subject: [PATCH] Added "Clear Queue" and "Remove from Queue" buttons to QueueSong context menu --- dmp-core/src/music_controller/controller_handle.rs | 11 ++++++++++- src-tauri/src/lib.rs | 7 ++++--- src-tauri/src/wrappers.rs | 10 ++++++++++ src/App.tsx | 9 ++++++--- 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/dmp-core/src/music_controller/controller_handle.rs b/dmp-core/src/music_controller/controller_handle.rs index 9aa1d36..3a9170d 100644 --- a/dmp-core/src/music_controller/controller_handle.rs +++ b/dmp-core/src/music_controller/controller_handle.rs @@ -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 { let (command, tx) = PlayerCommandInput::command(PlayerCommand::PlayNow(uuid, location)); diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index a86b988..d03cbff 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -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()) diff --git a/src-tauri/src/wrappers.rs b/src-tauri/src/wrappers.rs index f3c5c5c..c6bee53 100644 --- a/src-tauri/src/wrappers.rs +++ b/src-tauri/src/wrappers.rs @@ -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, + ctrl_handle: State<'_, ControllerHandle>, +) -> Result<(), String> { + let res = ctrl_handle.queue_clear().await.map_err(|e| e.to_string()); + app.emit("queue_updated", ()); + res +} diff --git a/src/App.tsx b/src/App.tsx index 7d0340c..372e804 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -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();