diff --git a/crates/komorebi-bar-core/src/platform.rs b/crates/komorebi-bar-core/src/platform.rs index 635e5dc3..8e0d56e4 100644 --- a/crates/komorebi-bar-core/src/platform.rs +++ b/crates/komorebi-bar-core/src/platform.rs @@ -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 { diff --git a/komorebi-bar/src/os.rs b/komorebi-bar/src/os.rs index 2fca94c4..dcce88d4 100644 --- a/komorebi-bar/src/os.rs +++ b/komorebi-bar/src/os.rs @@ -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::>()[0]]) + .spawn(), } .map(|_| ()) } diff --git a/komorebi-bar/src/widgets/storage.rs b/komorebi-bar/src/widgets/storage.rs index 12d3c440..942b75e2 100644 --- a/komorebi-bar/src/widgets/storage.rs +++ b/komorebi-bar/src/widgets/storage.rs @@ -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::>()[0], - ]) - .spawn() + && let Err(error) = platform() + .open_system_tool(SystemTool::StorageLocation(output.label.clone())) { eprintln!("{error}") } diff --git a/komorebi-for-mac/komorebi-bar/src/os.rs b/komorebi-for-mac/komorebi-bar/src/os.rs index c3df076a..2dd84e6e 100644 --- a/komorebi-for-mac/komorebi-bar/src/os.rs +++ b/komorebi-for-mac/komorebi-bar/src/os.rs @@ -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(|_| ()) } diff --git a/komorebi-for-mac/komorebi-bar/src/widgets/storage.rs b/komorebi-for-mac/komorebi-bar/src/widgets/storage.rs index 830e06f8..942b75e2 100644 --- a/komorebi-for-mac/komorebi-bar/src/widgets/storage.rs +++ b/komorebi-for-mac/komorebi-bar/src/widgets/storage.rs @@ -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 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}") } }); }