refactor(bar): reach exec_powershell and send_batch through BarPlatform hooks

The mouse code in config.rs called `crate::bar::exec_powershell` and
`komorebi_client::send_batch` directly, which ties config.rs to the Windows
shell. Two new hooks, `exec_shell_command(&str)` and
`send_komorebi_batch(Vec<SocketMessage>)`, carry them: Windows os.rs calls
exactly `crate::bar::exec_powershell` and `komorebi_client::send_batch`;
macOS os.rs forwards send_batch the same way and answers
exec_shell_command with an Unsupported error (the macOS bar has no shell
session, and its mouse block was commented out), which nothing calls yet.
Windows behaviour is unchanged (same calls); config.rs of Windows now only
depends on the platform seam.

Verified: Windows clippy -D warnings --locked clean; macOS fake-CC check
--locked 0 errors (files touched first). Not run: the bars.
This commit is contained in:
LGUG2Z committed 2026-10-31 10:52:09 -07:00
1 parent 4831a6c3ab
commit 7e61c3a934
4 files changed
+32 -3

No files matched your search

+7
View File
@@ -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<ImageIcon>;
/// 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<SocketMessage>) -> io::Result<()>;
/// The glyph the date widget shows as its calendar icon.
fn calendar_icon(&self) -> &'static str;
}
+6 -3
View File
@@ -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);
}
}
+9
View File
@@ -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<SocketMessage>) -> io::Result<()> {
komorebi_client::send_batch(messages)
}
fn command_icon(&self, command: &str) -> Option<ImageIcon> {
let path = executable_of(command)?;
ImageIcon::try_load(path.as_ref(), || {
+10
View File
@@ -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<SocketMessage>) -> io::Result<()> {
komorebi_client::send_batch(messages)
}
fn command_icon(&self, _command: &str) -> Option<ImageIcon> {
None
}