From 7276dc230936d6bfd439e2569e9fbaefcfa4af39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adinelson=20Br=C3=BChm=C3=BCller?= Date: Mon, 14 Oct 2024 22:37:39 -0300 Subject: [PATCH] feat(cli): add --ahk flag to stop cmd resolve #951 --- komorebic/src/main.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index b7cc2ba4..0bb949ba 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -775,6 +775,9 @@ struct Stop { /// Stop whkd if it is running as a background process #[clap(long)] whkd: bool, + /// Stop ahk if it is running as a background process + #[clap(long)] + ahk: bool, /// Stop komorebi-bar if it is running as a background process #[clap(long)] bar: bool, @@ -2152,6 +2155,35 @@ Stop-Process -Name:komorebi-bar -ErrorAction SilentlyContinue } } + if arg.ahk { + let script = r#" +if (Get-Command Get-CimInstance -ErrorAction SilentlyContinue) { + (Get-CimInstance Win32_Process | Where-Object { + ($_.CommandLine -like '*komorebi.ahk"') -and + ($_.Name -in @('AutoHotkey.exe', 'AutoHotkey64.exe', 'AutoHotkey32.exe')) + } | Select-Object -First 1) | ForEach-Object { + Stop-Process -Id $_.ProcessId -ErrorAction SilentlyContinue + } +} else { + (Get-WmiObject Win32_Process | Where-Object { + ($_.CommandLine -like '*komorebi.ahk"') -and + ($_.Name -in @('AutoHotkey.exe', 'AutoHotkey64.exe', 'AutoHotkey32.exe')) + } | Select-Object -First 1) | ForEach-Object { + Stop-Process -Id $_.ProcessId -ErrorAction SilentlyContinue + } +} +"#; + + match powershell_script::run(script) { + Ok(_) => { + println!("{script}"); + } + Err(error) => { + println!("Error: {error}"); + } + } + } + send_message(&SocketMessage::Stop)?; let mut system = sysinfo::System::new_all(); system.refresh_processes(ProcessesToUpdate::All);