feat(cli): add --ahk flag to stop cmd

resolve #951
This commit is contained in:
Adinelson Brühmüller
2024-10-14 22:37:39 -03:00
committed by LGUG2Z
parent 58d3086615
commit 7276dc2309

View File

@@ -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);