From b8de056b28fa195a000a49bc371b42be7445c75e Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Fri, 30 Oct 2026 23:45:49 -0700 Subject: [PATCH] refactor(bar-core): the cpu and battery widgets open their tools through the platform hook The click on the cpu widget (task manager) and on the battery widget (power settings) now calls platform().open_system_tool(...) instead of spawning cmd.exe in shared code. The Windows hook spawns the same commands as before; the macOS hook still spawns the same (broken there) cmd.exe commands, so neither platform's behaviour changes. Fixing macOS is now a change to one function of komorebi-for-mac/komorebi-bar/src/platform.rs. Verified: Windows cargo clippy --workspace --locked --all-targets -D warnings clean; macOS fake-CC cargo check --locked --workspace --all-targets finished, 0 errors; native cargo test -p komorebi-bar-core 3 unit + 2 oracle passed; harness regeneration byte-identical for both. Not verified: that a click still opens the tool (no screen). --- crates/komorebi-bar-core/src/widgets/battery.rs | 7 +++---- crates/komorebi-bar-core/src/widgets/cpu.rs | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/crates/komorebi-bar-core/src/widgets/battery.rs b/crates/komorebi-bar-core/src/widgets/battery.rs index dcd8bd15..424b67c7 100644 --- a/crates/komorebi-bar-core/src/widgets/battery.rs +++ b/crates/komorebi-bar-core/src/widgets/battery.rs @@ -1,4 +1,6 @@ use crate::config::LabelPrefix; +use crate::platform::SystemTool; +use crate::platform::platform; use crate::render::RenderConfig; use crate::selected_frame::SelectableFrame; use crate::widgets::widget::BarWidget; @@ -13,7 +15,6 @@ use serde::Serialize; use starship_battery::Manager; use starship_battery::State; use starship_battery::units::ratio::percent; -use std::process::Command; use std::time::Duration; use std::time::Instant; @@ -178,9 +179,7 @@ impl BarWidget for Battery { if SelectableFrame::new_auto(output.selected, auto_focus_fill) .show(ui, |ui| ui.add(Label::new(layout_job).selectable(false))) .clicked() - && let Err(error) = Command::new("cmd.exe") - .args(["/C", "start", "ms-settings:batterysaver"]) - .spawn() + && let Err(error) = platform().open_system_tool(SystemTool::PowerSettings) { eprintln!("{error}") } diff --git a/crates/komorebi-bar-core/src/widgets/cpu.rs b/crates/komorebi-bar-core/src/widgets/cpu.rs index bcf3e796..3dd934f5 100644 --- a/crates/komorebi-bar-core/src/widgets/cpu.rs +++ b/crates/komorebi-bar-core/src/widgets/cpu.rs @@ -1,4 +1,6 @@ use crate::config::LabelPrefix; +use crate::platform::SystemTool; +use crate::platform::platform; use crate::render::RenderConfig; use crate::selected_frame::SelectableFrame; use crate::widgets::widget::BarWidget; @@ -10,7 +12,6 @@ use eframe::egui::Ui; use eframe::egui::text::LayoutJob; use serde::Deserialize; use serde::Serialize; -use std::process::Command; use std::time::Duration; use std::time::Instant; use sysinfo::RefreshKind; @@ -122,8 +123,7 @@ impl BarWidget for Cpu { if SelectableFrame::new_auto(output.selected, auto_focus_fill) .show(ui, |ui| ui.add(Label::new(layout_job).selectable(false))) .clicked() - && let Err(error) = - Command::new("cmd.exe").args(["/C", "taskmgr.exe"]).spawn() + && let Err(error) = platform().open_system_tool(SystemTool::TaskManager) { eprintln!("{error}") }