From 58e5f039be783f6a0460e767adec22d9adec1b49 Mon Sep 17 00:00:00 2001 From: arabian Date: Mon, 23 Feb 2026 13:40:41 +0300 Subject: [PATCH] feat(cli, flatpak): implemented kill action for pwsp-cli. use it instead of pkill in the flatpak wrapper --- packages/flatpak/pwsp-wrapper.py | 2 +- src/bin/cli.rs | 3 +++ src/bin/daemon.rs | 4 ++++ src/types/commands.rs | 9 +++++++++ src/types/socket.rs | 4 ++++ src/utils/commands.rs | 1 + 6 files changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/flatpak/pwsp-wrapper.py b/packages/flatpak/pwsp-wrapper.py index 806163e..db03f0d 100755 --- a/packages/flatpak/pwsp-wrapper.py +++ b/packages/flatpak/pwsp-wrapper.py @@ -32,4 +32,4 @@ if __name__ == "__main__": if args.start: subprocess.Popen("pwsp-daemon") elif args.kill: - subprocess.Popen(["pkill", "-f", "pwsp-daemon"]) \ No newline at end of file + subprocess.Popen(["pwsp-cli", "action", "kill"]) \ No newline at end of file diff --git a/src/bin/cli.rs b/src/bin/cli.rs index 3981ad9..74e71b8 100644 --- a/src/bin/cli.rs +++ b/src/bin/cli.rs @@ -35,6 +35,8 @@ enum Commands { enum Actions { /// Ping the daemon Ping, + /// Kill the daemon + Kill, /// Pause audio playback Pause { #[clap(short, long)] @@ -131,6 +133,7 @@ async fn main() -> Result<(), Box> { let request = match cli.command { Commands::Action { action } => match action { Actions::Ping => Request::ping(), + Actions::Kill => Request::kill(), Actions::Pause { id } => Request::pause(id), Actions::Resume { id } => Request::resume(id), Actions::TogglePause { id } => Request::toggle_pause(id), diff --git a/src/bin/daemon.rs b/src/bin/daemon.rs index af70969..a2ae678 100644 --- a/src/bin/daemon.rs +++ b/src/bin/daemon.rs @@ -111,6 +111,10 @@ async fn commands_loop(listener: UnixListener) -> Result<(), Box> { return; } // ---------- Send response (end) ---------- + + if response.status && response.message.eq("killed") { + std::process::exit(0); + } }); } } diff --git a/src/types/commands.rs b/src/types/commands.rs index a93bbe4..ea0baac 100644 --- a/src/types/commands.rs +++ b/src/types/commands.rs @@ -18,6 +18,8 @@ pub trait Executable { pub struct PingCommand {} +pub struct KillCommand {} + pub struct PauseCommand { pub id: Option, } @@ -93,6 +95,13 @@ impl Executable for PingCommand { } } +#[async_trait] +impl Executable for KillCommand { + async fn execute(&self) -> Response { + Response::new(true, "killed") + } +} + #[async_trait] impl Executable for PauseCommand { async fn execute(&self) -> Response { diff --git a/src/types/socket.rs b/src/types/socket.rs index 390e917..6b69534 100644 --- a/src/types/socket.rs +++ b/src/types/socket.rs @@ -24,6 +24,10 @@ impl Request { Request::new("ping", vec![]) } + pub fn kill() -> Self { + Request::new("kill", vec![]) + } + pub fn pause(id: Option) -> Self { let mut args = vec![]; let id_str; diff --git a/src/utils/commands.rs b/src/utils/commands.rs index 7e68d67..0a42b8a 100644 --- a/src/utils/commands.rs +++ b/src/utils/commands.rs @@ -7,6 +7,7 @@ pub fn parse_command(request: &Request) -> Option> { match request.name.as_str() { "ping" => Some(Box::new(PingCommand {})), + "kill" => Some(Box::new(KillCommand {})), "pause" => Some(Box::new(PauseCommand { id })), "resume" => Some(Box::new(ResumeCommand { id })), "toggle_pause" => Some(Box::new(TogglePauseCommand { id })),