mirror of
https://github.com/arabianq/pipewire-soundpad.git
synced 2026-04-28 06:21:23 +00:00
feat(cli, flatpak): implemented kill action for pwsp-cli.
use it instead of pkill in the flatpak wrapper
This commit is contained in:
@@ -32,4 +32,4 @@ if __name__ == "__main__":
|
|||||||
if args.start:
|
if args.start:
|
||||||
subprocess.Popen("pwsp-daemon")
|
subprocess.Popen("pwsp-daemon")
|
||||||
elif args.kill:
|
elif args.kill:
|
||||||
subprocess.Popen(["pkill", "-f", "pwsp-daemon"])
|
subprocess.Popen(["pwsp-cli", "action", "kill"])
|
||||||
@@ -35,6 +35,8 @@ enum Commands {
|
|||||||
enum Actions {
|
enum Actions {
|
||||||
/// Ping the daemon
|
/// Ping the daemon
|
||||||
Ping,
|
Ping,
|
||||||
|
/// Kill the daemon
|
||||||
|
Kill,
|
||||||
/// Pause audio playback
|
/// Pause audio playback
|
||||||
Pause {
|
Pause {
|
||||||
#[clap(short, long)]
|
#[clap(short, long)]
|
||||||
@@ -131,6 +133,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
let request = match cli.command {
|
let request = match cli.command {
|
||||||
Commands::Action { action } => match action {
|
Commands::Action { action } => match action {
|
||||||
Actions::Ping => Request::ping(),
|
Actions::Ping => Request::ping(),
|
||||||
|
Actions::Kill => Request::kill(),
|
||||||
Actions::Pause { id } => Request::pause(id),
|
Actions::Pause { id } => Request::pause(id),
|
||||||
Actions::Resume { id } => Request::resume(id),
|
Actions::Resume { id } => Request::resume(id),
|
||||||
Actions::TogglePause { id } => Request::toggle_pause(id),
|
Actions::TogglePause { id } => Request::toggle_pause(id),
|
||||||
|
|||||||
@@ -111,6 +111,10 @@ async fn commands_loop(listener: UnixListener) -> Result<(), Box<dyn Error>> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// ---------- Send response (end) ----------
|
// ---------- Send response (end) ----------
|
||||||
|
|
||||||
|
if response.status && response.message.eq("killed") {
|
||||||
|
std::process::exit(0);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ pub trait Executable {
|
|||||||
|
|
||||||
pub struct PingCommand {}
|
pub struct PingCommand {}
|
||||||
|
|
||||||
|
pub struct KillCommand {}
|
||||||
|
|
||||||
pub struct PauseCommand {
|
pub struct PauseCommand {
|
||||||
pub id: Option<u32>,
|
pub id: Option<u32>,
|
||||||
}
|
}
|
||||||
@@ -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]
|
#[async_trait]
|
||||||
impl Executable for PauseCommand {
|
impl Executable for PauseCommand {
|
||||||
async fn execute(&self) -> Response {
|
async fn execute(&self) -> Response {
|
||||||
|
|||||||
@@ -24,6 +24,10 @@ impl Request {
|
|||||||
Request::new("ping", vec![])
|
Request::new("ping", vec![])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn kill() -> Self {
|
||||||
|
Request::new("kill", vec![])
|
||||||
|
}
|
||||||
|
|
||||||
pub fn pause(id: Option<u32>) -> Self {
|
pub fn pause(id: Option<u32>) -> Self {
|
||||||
let mut args = vec![];
|
let mut args = vec![];
|
||||||
let id_str;
|
let id_str;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ pub fn parse_command(request: &Request) -> Option<Box<dyn Executable + Send>> {
|
|||||||
|
|
||||||
match request.name.as_str() {
|
match request.name.as_str() {
|
||||||
"ping" => Some(Box::new(PingCommand {})),
|
"ping" => Some(Box::new(PingCommand {})),
|
||||||
|
"kill" => Some(Box::new(KillCommand {})),
|
||||||
"pause" => Some(Box::new(PauseCommand { id })),
|
"pause" => Some(Box::new(PauseCommand { id })),
|
||||||
"resume" => Some(Box::new(ResumeCommand { id })),
|
"resume" => Some(Box::new(ResumeCommand { id })),
|
||||||
"toggle_pause" => Some(Box::new(TogglePauseCommand { id })),
|
"toggle_pause" => Some(Box::new(TogglePauseCommand { id })),
|
||||||
|
|||||||
Reference in New Issue
Block a user