fix(cli): use force-quit if stop signal fails

This commit ensures that the komorebic stop command will force-quit
komorebi if the Stop SocketMessage handler fails.
This commit is contained in:
LGUG2Z
2024-04-20 13:26:09 -07:00
parent eac4c8e9b1
commit 793e81d43d
6 changed files with 39 additions and 7 deletions

View File

@@ -17,6 +17,7 @@ dunce = "1"
dirs = "5"
color-eyre = "0.6"
serde_json = { package = "serde_json_lenient", version = "0.1" }
sysinfo = "0.30"
[workspace.dependencies.windows]
version = "0.54"

View File

@@ -35,7 +35,7 @@ schemars = "0.8"
serde = { version = "1", features = ["derive"] }
serde_json = { workspace = true }
strum = { version = "0.26", features = ["derive"] }
sysinfo = "0.30"
sysinfo = { workspace = true }
tracing = "0.1"
tracing-appender = "0.2"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }

View File

@@ -727,7 +727,7 @@ impl StaticConfig {
value.apply_globals()?;
let stackbar_mode = STACKBAR_MODE.lock().clone();
let stackbar_mode = *STACKBAR_MODE.lock();
for m in wm.monitors_mut() {
for w in m.workspaces_mut() {

View File

@@ -327,10 +327,13 @@ impl Workspace {
}
if let Some(stackbar) = container_topbar {
if let Ok(_) = stackbar.set_position(
&stackbar.get_position_from_container_layout(layout),
false,
) {
if stackbar
.set_position(
&stackbar.get_position_from_container_layout(layout),
false,
)
.is_ok()
{
stackbar.update(&container_windows, focused_hwnd)?;
let tab_height = STACKBAR_TAB_HEIGHT.load(Ordering::SeqCst);
let total_height = tab_height + container_padding;

View File

@@ -28,7 +28,7 @@ reqwest = { version = "0.12", features = ["blocking"] }
serde = { version = "1", features = ["derive"] }
serde_json = { workspace = true }
serde_yaml = "0.9"
sysinfo = "0.30"
sysinfo = { workspace = true }
thiserror = "1"
uds_windows = "1"
which = "6"

View File

@@ -1897,6 +1897,34 @@ Stop-Process -Name:whkd -ErrorAction SilentlyContinue
}
send_message(&SocketMessage::Stop.as_bytes()?)?;
let mut system = sysinfo::System::new_all();
system.refresh_processes();
if system.processes_by_name("komorebi.exe").count() >= 1 {
println!("komorebi is still running, attempting to force-quit");
let script = r"
Stop-Process -Name:komorebi -ErrorAction SilentlyContinue
";
match powershell_script::run(script) {
Ok(_) => {
println!("{script}");
let hwnd_json = DATA_DIR.join("komorebi.hwnd.json");
let file = File::open(hwnd_json)?;
let reader = BufReader::new(file);
let hwnds: Vec<isize> = serde_json::from_reader(reader)?;
for hwnd in hwnds {
restore_window(HWND(hwnd));
}
}
Err(error) => {
println!("Error: {error}");
}
}
}
}
SubCommand::FloatRule(arg) => {
send_message(&SocketMessage::FloatRule(arg.identifier, arg.id).as_bytes()?)?;