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).
This commit is contained in:
LGUG2Z committed 2026-10-31 01:37:54 -07:00
1 parent 086833af96
commit b8de056b28
2 files changed
+6 -7

No files matched your search

@@ -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}")
}
+3 -3
View File
@@ -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}")
}