From f4e0fb946997832b71316696bc470f5c23e7f1f0 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 9 Sep 2023 22:02:41 -0700 Subject: [PATCH] feat(cli): add opt to stop whkd alongside wm This commit adds a '--whkd' flag to the 'komorebic stop' command, which will also stop any running instance of whkd when stopping the window manager. This flag defaults to false, and should not change the existing behaviour that users are used to. --- komorebic/src/main.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index 7cb24370..888704c3 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -625,6 +625,13 @@ struct Start { whkd: bool, } +#[derive(Parser, AhkFunction)] +struct Stop { + /// Stop whkd if it is running as a background process + #[clap(action, long)] + whkd: bool, +} + #[derive(Parser, AhkFunction)] struct SaveResize { /// File to which the resize layout dimensions should be saved @@ -695,7 +702,7 @@ enum SubCommand { /// Start komorebi.exe as a background process Start(Start), /// Stop the komorebi.exe process and restore all hidden windows - Stop, + Stop(Stop), /// Output various important komorebi-related environment values Check, /// Show a JSON representation of the current window manager state @@ -1496,7 +1503,21 @@ if (!(Get-Process whkd -ErrorAction SilentlyContinue)) } } } - SubCommand::Stop => { + SubCommand::Stop(arg) => { + if arg.whkd { + let script = r#" +Stop-Process -Name:whkd -ErrorAction SilentlyContinue + "#; + match powershell_script::run(script) { + Ok(_) => { + println!("{script}"); + } + Err(error) => { + println!("Error: {error}"); + } + } + } + send_message(&SocketMessage::Stop.as_bytes()?)?; } SubCommand::FloatRule(arg) => {