refactor(bar): memory, date and update use the platform hooks

The three widgets that differ between the bars only by a platform fact now read it from the hook, in both trees identically: memory opens the task manager through open_system_tool(TaskManager) (was cmd.exe /C taskmgr.exe on Windows, open -a 'Activity Monitor' on macOS: the same commands, now in each platform.rs); date takes its calendar glyph from calendar_icon() (CALENDAR_DOTS on Windows, CALENDAR on macOS); update polls latest_release_api_url() (the komorebi and komorebi-for-mac release APIs) and opens the release page through open_system_tool(Url(..)) (explorer.exe on Windows; on macOS the same explorer.exe it spawns today, broken there, unchanged). After this the memory.rs, date.rs and update.rs of the two bars are byte-identical.

Verified: Windows cargo clippy --workspace --locked --all-targets -D warnings clean; macOS fake-CC cargo check --locked --workspace --all-targets finished, 0 errors; memory.rs, date.rs and update.rs byte-identical across the trees (diff). Note kept as it was: update.rs has a second GitHub API URL (the periodic refresh thread, line 85) that is the komorebi repo in both bars, also on macOS; only the first check goes through the hook. Not verified: clicks and the update check (no screen, no daemon).
This commit is contained in:
LGUG2Z committed 2026-10-31 01:37:54 -07:00
1 parent b8de056b28
commit 7cd85bd446
6 files changed
+24 -25

No files matched your search

+2 -1
View File
@@ -1,4 +1,5 @@
use crate::config::LabelPrefix;
use crate::platform::platform;
use crate::render::RenderConfig;
use crate::selected_frame::SelectableFrame;
use crate::widgets::widget::BarWidget;
@@ -202,7 +203,7 @@ impl BarWidget for Date {
let mut layout_job = LayoutJob::simple(
match self.label_prefix {
LabelPrefix::Icon | LabelPrefix::IconAndText => {
egui_phosphor::regular::CALENDAR_DOTS.to_string()
platform().calendar_icon().to_string()
}
LabelPrefix::None | LabelPrefix::Text => String::new(),
},
+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;
@@ -126,8 +127,7 @@ impl BarWidget for Memory {
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}")
}
+7 -8
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;
@@ -35,7 +36,7 @@ impl From<UpdateConfig> for Update {
let client = reqwest::blocking::Client::new();
if let Ok(response) = client
.get("https://api.github.com/repos/LGUG2Z/komorebi/releases/latest")
.get(platform().latest_release_api_url())
.header("User-Agent", "komorebi-bar-version-checker")
.send()
{
@@ -142,12 +143,10 @@ impl BarWidget for Update {
if SelectableFrame::new(false)
.show(ui, |ui| ui.add(Label::new(layout_job).selectable(false)))
.clicked()
&& let Err(error) = Command::new("explorer.exe")
.args([format!(
"https://github.com/LGUG2Z/komorebi/releases/v{}",
self.latest_version
)])
.spawn()
&& let Err(error) = platform().open_system_tool(SystemTool::Url(format!(
"https://github.com/LGUG2Z/komorebi/releases/v{}",
self.latest_version
)))
{
eprintln!("{error}")
}
@@ -1,4 +1,5 @@
use crate::config::LabelPrefix;
use crate::platform::platform;
use crate::render::RenderConfig;
use crate::selected_frame::SelectableFrame;
use crate::widgets::widget::BarWidget;
@@ -202,7 +203,7 @@ impl BarWidget for Date {
let mut layout_job = LayoutJob::simple(
match self.label_prefix {
LabelPrefix::Icon | LabelPrefix::IconAndText => {
egui_phosphor::regular::CALENDAR.to_string()
platform().calendar_icon().to_string()
}
LabelPrefix::None | LabelPrefix::Text => String::new(),
},
@@ -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;
@@ -126,9 +127,7 @@ impl BarWidget for Memory {
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("open")
.args(["-a", "Activity Monitor"])
.spawn()
&& let Err(error) = platform().open_system_tool(SystemTool::TaskManager)
{
eprintln!("{error}")
}
@@ -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;
@@ -35,7 +36,7 @@ impl From<UpdateConfig> for Update {
let client = reqwest::blocking::Client::new();
if let Ok(response) = client
.get("https://api.github.com/repos/LGUG2Z/komorebi-for-mac/releases/latest")
.get(platform().latest_release_api_url())
.header("User-Agent", "komorebi-bar-version-checker")
.send()
{
@@ -142,12 +143,10 @@ impl BarWidget for Update {
if SelectableFrame::new(false)
.show(ui, |ui| ui.add(Label::new(layout_job).selectable(false)))
.clicked()
&& let Err(error) = Command::new("explorer.exe")
.args([format!(
"https://github.com/LGUG2Z/komorebi/releases/v{}",
self.latest_version
)])
.spawn()
&& let Err(error) = platform().open_system_tool(SystemTool::Url(format!(
"https://github.com/LGUG2Z/komorebi/releases/v{}",
self.latest_version
)))
{
eprintln!("{error}")
}