mirror of
https://github.com/arabianq/pipewire-soundpad.git
synced 2026-04-28 06:21:23 +00:00
feat: implemented toggle-loop
This commit is contained in:
@@ -45,6 +45,8 @@ enum Actions {
|
|||||||
Stop,
|
Stop,
|
||||||
/// Play a file
|
/// Play a file
|
||||||
Play { file_path: PathBuf },
|
Play { file_path: PathBuf },
|
||||||
|
/// Toggle loop
|
||||||
|
ToggleLoop,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Subcommand, Debug)]
|
#[derive(Subcommand, Debug)]
|
||||||
@@ -95,6 +97,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
Actions::TogglePause => Request::toggle_pause(),
|
Actions::TogglePause => Request::toggle_pause(),
|
||||||
Actions::Stop => Request::stop(),
|
Actions::Stop => Request::stop(),
|
||||||
Actions::Play { file_path } => Request::play(file_path.to_str().unwrap()),
|
Actions::Play { file_path } => Request::play(file_path.to_str().unwrap()),
|
||||||
|
Actions::ToggleLoop => Request::toggle_loop(),
|
||||||
},
|
},
|
||||||
Commands::Get { parameter } => match parameter {
|
Commands::Get { parameter } => match parameter {
|
||||||
GetCommands::IsPaused => Request::get_is_paused(),
|
GetCommands::IsPaused => Request::get_is_paused(),
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ pub struct SetLoopCommand {
|
|||||||
pub enabled: Option<bool>,
|
pub enabled: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct ToggleLoopCommand {}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Executable for PingCommand {
|
impl Executable for PingCommand {
|
||||||
async fn execute(&self) -> Response {
|
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))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -95,6 +95,10 @@ impl Request {
|
|||||||
pub fn set_loop(enabled: &str) -> Self {
|
pub fn set_loop(enabled: &str) -> Self {
|
||||||
Request::new("set_loop", vec![("enabled", enabled)])
|
Request::new("set_loop", vec![("enabled", enabled)])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn toggle_loop() -> Self {
|
||||||
|
Request::new("toggle_loop", vec![])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
|
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ pub fn parse_command(request: &Request) -> Option<Box<dyn Executable + Send>> {
|
|||||||
.ok();
|
.ok();
|
||||||
Some(Box::new(SetLoopCommand { enabled }))
|
Some(Box::new(SetLoopCommand { enabled }))
|
||||||
}
|
}
|
||||||
|
"toggle_loop" => Some(Box::new(ToggleLoopCommand {})),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user