From 6c06da7b0d2eec19107b7af8100e2a752d051d54 Mon Sep 17 00:00:00 2001 From: arabian Date: Fri, 2 Jan 2026 04:39:48 +0300 Subject: [PATCH] feat: implemented toggle-loop --- src/bin/cli.rs | 3 +++ src/types/commands.rs | 11 +++++++++++ src/types/socket.rs | 4 ++++ src/utils/commands.rs | 1 + 4 files changed, 19 insertions(+) diff --git a/src/bin/cli.rs b/src/bin/cli.rs index 8cea7ed..0caed1b 100644 --- a/src/bin/cli.rs +++ b/src/bin/cli.rs @@ -45,6 +45,8 @@ enum Actions { Stop, /// Play a file Play { file_path: PathBuf }, + /// Toggle loop + ToggleLoop, } #[derive(Subcommand, Debug)] @@ -95,6 +97,7 @@ async fn main() -> Result<(), Box> { Actions::TogglePause => Request::toggle_pause(), Actions::Stop => Request::stop(), Actions::Play { file_path } => Request::play(file_path.to_str().unwrap()), + Actions::ToggleLoop => Request::toggle_loop(), }, Commands::Get { parameter } => match parameter { GetCommands::IsPaused => Request::get_is_paused(), diff --git a/src/types/commands.rs b/src/types/commands.rs index 82c4075..d6b2a67 100644 --- a/src/types/commands.rs +++ b/src/types/commands.rs @@ -58,6 +58,8 @@ pub struct SetLoopCommand { pub enabled: Option, } +pub struct ToggleLoopCommand {} + #[async_trait] impl Executable for PingCommand { async fn execute(&self) -> Response { @@ -285,3 +287,12 @@ impl Executable for SetLoopCommand { } } } + +#[async_trait] +impl Executable for ToggleLoopCommand { + async fn execute(&self) -> Response { + let mut audio_player = get_audio_player().await.lock().await; + audio_player.looped = !audio_player.looped; + Response::new(true, format!("Loop was set to {}", audio_player.looped)) + } +} diff --git a/src/types/socket.rs b/src/types/socket.rs index 3d184d5..ac5db2d 100644 --- a/src/types/socket.rs +++ b/src/types/socket.rs @@ -95,6 +95,10 @@ impl Request { pub fn set_loop(enabled: &str) -> Self { Request::new("set_loop", vec![("enabled", enabled)]) } + + pub fn toggle_loop() -> Self { + Request::new("toggle_loop", vec![]) + } } #[derive(Default, Debug, Clone, Serialize, Deserialize)] diff --git a/src/utils/commands.rs b/src/utils/commands.rs index 5998c62..46b2889 100644 --- a/src/utils/commands.rs +++ b/src/utils/commands.rs @@ -58,6 +58,7 @@ pub fn parse_command(request: &Request) -> Option> { .ok(); Some(Box::new(SetLoopCommand { enabled })) } + "toggle_loop" => Some(Box::new(ToggleLoopCommand {})), _ => None, } }