mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-17 06:11:21 +01:00
refactor(bar): converge storage.rs of both bars behind a platform hook
The two storage.rs differed in the click handler and in four doc strings. The click now asks the platform (new SystemTool::StorageLocation(label)) and each shell keeps exactly what it spawned: Windows `cmd.exe /C explorer.exe <first word of the label>`, macOS `open <label without its last word>`. The macOS doc strings take the Windows spelling (C:\, Local Disk); the macOS schema view sets the macOS text back, so komorebi-for-mac/schema.bar.json and nix/komorebi-bar-options.nix do not change. Verified: schema harness S/bar2/regen.sh: macOS byte-identical (3,774 lines), Windows byte-identical (9,091 lines); the two storage.rs are now byte-identical to each other; Windows clippy -D warnings clean; macOS fake-CC check 0 errors. No click was exercised (cannot here).
This commit is contained in:
1 parent
352cda3be3
commit
bfddb6f0c3
5 files changed
+25
-19
No files matched your search
@@ -17,6 +17,9 @@ pub enum SystemTool {
|
||||
NetworkSettings,
|
||||
/// A URL, in the default browser
|
||||
Url(String),
|
||||
/// The location a storage widget label names (the label text, as shown: the platform
|
||||
/// knows how its labels are built), in the file manager
|
||||
StorageLocation(String),
|
||||
}
|
||||
|
||||
pub trait BarPlatform: Send + Sync {
|
||||
|
||||
@@ -15,6 +15,9 @@ impl BarPlatform for WindowsBar {
|
||||
.spawn(),
|
||||
SystemTool::NetworkSettings => Command::new("cmd.exe").args(["/C", "ncpa"]).spawn(),
|
||||
SystemTool::Url(url) => Command::new("explorer.exe").args([url]).spawn(),
|
||||
SystemTool::StorageLocation(label) => Command::new("cmd.exe")
|
||||
.args(["/C", "explorer.exe", label.split(' ').collect::<Vec<&str>>()[0]])
|
||||
.spawn(),
|
||||
}
|
||||
.map(|_| ())
|
||||
}
|
||||
|
||||
@@ -11,7 +11,8 @@ use eframe::egui::Ui;
|
||||
use eframe::egui::text::LayoutJob;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use std::process::Command;
|
||||
use crate::platform::SystemTool;
|
||||
use crate::platform::platform;
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
use sysinfo::Disks;
|
||||
@@ -190,13 +191,8 @@ impl BarWidget for Storage {
|
||||
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",
|
||||
"explorer.exe",
|
||||
output.label.split(' ').collect::<Vec<&str>>()[0],
|
||||
])
|
||||
.spawn()
|
||||
&& let Err(error) = platform()
|
||||
.open_system_tool(SystemTool::StorageLocation(output.label.clone()))
|
||||
{
|
||||
eprintln!("{error}")
|
||||
}
|
||||
|
||||
@@ -21,6 +21,12 @@ impl BarPlatform for MacBar {
|
||||
.spawn(),
|
||||
// explorer.exe does not exist on macOS: this is what the update widget does today
|
||||
SystemTool::Url(url) => Command::new("explorer.exe").args([url]).spawn(),
|
||||
SystemTool::StorageLocation(label) => {
|
||||
let parts: Vec<&str> = label.split(' ').collect();
|
||||
let path = parts[..parts.len() - 1].join(" ");
|
||||
|
||||
Command::new("open").args([path]).spawn()
|
||||
}
|
||||
}
|
||||
.map(|_| ())
|
||||
}
|
||||
|
||||
@@ -11,7 +11,8 @@ use eframe::egui::Ui;
|
||||
use eframe::egui::text::LayoutJob;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use std::process::Command;
|
||||
use crate::platform::SystemTool;
|
||||
use crate::platform::platform;
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
use sysinfo::Disks;
|
||||
@@ -63,13 +64,13 @@ impl From<StorageConfig> for Storage {
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
pub enum StorageDisplayName {
|
||||
/// Display label as mount point eg. /
|
||||
/// Display label as mount point eg. C:\
|
||||
Mount,
|
||||
/// Display label as name eg. Macintosh HD
|
||||
/// Display label as name eg. Local Disk
|
||||
Name,
|
||||
/// Display label as mount then name eg. / Macintosh HD
|
||||
/// Display label as mount then name eg. C:\ Local Disk
|
||||
MountAndName,
|
||||
/// Display label as name then mount eg. Macintosh HD /
|
||||
/// Display label as name then mount eg. Local Disk C:\
|
||||
NameAndMount,
|
||||
}
|
||||
|
||||
@@ -190,13 +191,10 @@ impl BarWidget for Storage {
|
||||
if SelectableFrame::new_auto(output.selected, auto_focus_fill)
|
||||
.show(ui, |ui| ui.add(Label::new(layout_job).selectable(false)))
|
||||
.clicked()
|
||||
&& let Err(error) = platform()
|
||||
.open_system_tool(SystemTool::StorageLocation(output.label.clone()))
|
||||
{
|
||||
let parts: Vec<&str> = output.label.split(' ').collect();
|
||||
let path = parts[..parts.len() - 1].join(" ");
|
||||
|
||||
if let Err(error) = Command::new("open").args([path]).spawn() {
|
||||
eprintln!("{error}")
|
||||
}
|
||||
eprintln!("{error}")
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user