diff --git a/crates/komorebi-bar-core/src/platform.rs b/crates/komorebi-bar-core/src/platform.rs index 8176adf4..107f1fb0 100644 --- a/crates/komorebi-bar-core/src/platform.rs +++ b/crates/komorebi-bar-core/src/platform.rs @@ -4,6 +4,7 @@ //! reach it through [`platform`] when they are built or clicked. use crate::widgets::icons::ImageIcon; +use komorebi_protocol::message::SocketMessage; use std::io; use std::sync::OnceLock; @@ -34,6 +35,12 @@ pub trait BarPlatform: Send + Sync { /// macOS: none). fn command_icon(&self, command: &str) -> Option; + /// Runs a command line in the bar's shell session (Windows: its PowerShell session). + fn exec_shell_command(&self, command: &str) -> color_eyre::Result<()>; + + /// Sends messages to the komorebi daemon as one batch. + fn send_komorebi_batch(&self, messages: Vec) -> io::Result<()>; + /// The glyph the date widget shows as its calendar icon. fn calendar_icon(&self) -> &'static str; } diff --git a/komorebi-bar/src/config.rs b/komorebi-bar/src/config.rs index ea8b3917..2529b68e 100644 --- a/komorebi-bar/src/config.rs +++ b/komorebi-bar/src/config.rs @@ -1,7 +1,7 @@ use crate::AUTO_SELECT_FILL_COLOUR; use crate::AUTO_SELECT_TEXT_COLOUR; use crate::DEFAULT_PADDING; -use crate::bar::exec_powershell; +use crate::platform::platform; use crate::render::Grouping; use crate::render::RenderConfig; use crate::render::RenderExt; @@ -497,7 +497,7 @@ impl MouseMessage { tracing::debug!("Sending messages: {messages:?}"); - if komorebi_client::send_batch(messages).is_err() { + if platform().send_komorebi_batch(messages).is_err() { tracing::error!("could not send commands"); } } @@ -506,7 +506,10 @@ impl MouseMessage { let cmd_no_env = cmd.replace_env(); - if exec_powershell(cmd_no_env.to_str().expect("Invalid command")).is_err() { + if platform() + .exec_shell_command(cmd_no_env.to_str().expect("Invalid command")) + .is_err() + { tracing::error!("Failed to execute '{}'", cmd); } } diff --git a/komorebi-bar/src/os.rs b/komorebi-bar/src/os.rs index e59e1680..9dd97e41 100644 --- a/komorebi-bar/src/os.rs +++ b/komorebi-bar/src/os.rs @@ -3,6 +3,7 @@ use egui_phosphor::regular::CALENDAR_DOTS; use komorebi_bar_core::platform::BarPlatform; use komorebi_bar_core::platform::SystemTool; use std::borrow::Cow; +use komorebi_client::SocketMessage; use std::io; use std::path::Path; use std::process::Command; @@ -38,6 +39,14 @@ impl BarPlatform for WindowsBar { CALENDAR_DOTS } + fn exec_shell_command(&self, command: &str) -> color_eyre::Result<()> { + crate::bar::exec_powershell(command) + } + + fn send_komorebi_batch(&self, messages: Vec) -> io::Result<()> { + komorebi_client::send_batch(messages) + } + fn command_icon(&self, command: &str) -> Option { let path = executable_of(command)?; ImageIcon::try_load(path.as_ref(), || { diff --git a/komorebi-for-mac/komorebi-bar/src/os.rs b/komorebi-for-mac/komorebi-bar/src/os.rs index 68a3978f..56d4efab 100644 --- a/komorebi-for-mac/komorebi-bar/src/os.rs +++ b/komorebi-for-mac/komorebi-bar/src/os.rs @@ -2,6 +2,7 @@ use crate::widgets::ImageIcon; use egui_phosphor::regular::CALENDAR; use komorebi_bar_core::platform::BarPlatform; use komorebi_bar_core::platform::SystemTool; +use komorebi_client::SocketMessage; use std::io; use std::process::Command; @@ -40,6 +41,15 @@ impl BarPlatform for MacBar { CALENDAR } + fn exec_shell_command(&self, _command: &str) -> color_eyre::Result<()> { + // the macOS bar has no shell session: the mouse commands are not supported here + Err(io::Error::new(io::ErrorKind::Unsupported, "no shell session on macOS").into()) + } + + fn send_komorebi_batch(&self, messages: Vec) -> io::Result<()> { + komorebi_client::send_batch(messages) + } + fn command_icon(&self, _command: &str) -> Option { None }