refactor(client): the three komorebi-client crates have the same Connection

Windows and macOS had a Connection (messages written a line each in order); KDE had none, and Windows
opened it differently from macOS. All three now have the macOS text (open -> from_stream; KDE's with docs),
and the Windows DATA_DIR is exported like the other two. Additive on KDE and Windows, no change to what
any function does. Preparation for one komorebi-client package; the socket functions were already identical.

Gates run: Windows clippy --all-targets -D warnings PASS (client and its users); KDE cargo test -p
komorebi-client-linux (unit, integration, doctests) PASS. Not run: macOS (file untouched).
This commit is contained in:
LGUG2Z committed 2026-10-31 12:24:30 -07:00
1 parent d1539a0687
commit e69346e918
2 files changed
+45 -2

No files matched your search

+6 -2
View File
@@ -86,7 +86,7 @@ pub use komorebi::workspace::Workspace;
pub use komorebi::workspace::WorkspaceGlobals;
pub use komorebi::workspace::WorkspaceLayer;
use komorebi::DATA_DIR;
pub use komorebi::DATA_DIR;
use std::borrow::Borrow;
use std::io::BufReader;
@@ -117,7 +117,11 @@ pub struct Connection {
impl Connection {
pub fn open() -> std::io::Result<Self> {
let socket = DATA_DIR.join(KOMOREBI);
let stream = UnixStream::connect(socket)?;
Self::from_stream(UnixStream::connect(socket)?)
}
fn from_stream(stream: UnixStream) -> std::io::Result<Self> {
stream.set_write_timeout(Some(Duration::from_secs(1)))?;
Ok(Self { stream })
@@ -140,6 +140,45 @@ pub fn send_message(message: &SocketMessage) -> std::io::Result<()> {
stream.write_all(serde_json::to_string(message)?.as_bytes())
}
/// A connection to komorebi that messages are written to one after the other, which komorebi
/// handles in the order that they were written, as it does the lines of a batch. Messages sent
/// with [`send_message`] are each on a connection of their own, which komorebi handles on a
/// thread of its own, so two that are sent together can be handled in either order.
pub struct Connection {
stream: UnixStream,
}
impl Connection {
/// Opens a connection to the daemon's socket.
///
/// # Errors
///
/// The daemon's socket cannot be connected to, or written to within a second.
pub fn open() -> std::io::Result<Self> {
let socket = DATA_DIR.join(KOMOREBI);
Self::from_stream(UnixStream::connect(socket)?)
}
fn from_stream(stream: UnixStream) -> std::io::Result<Self> {
stream.set_write_timeout(Some(Duration::from_secs(1)))?;
Ok(Self { stream })
}
/// Writes one message as a line.
///
/// # Errors
///
/// The message cannot be written, for example because the daemon let go of the connection.
pub fn send(&mut self, message: &SocketMessage) -> std::io::Result<()> {
let mut line = serde_json::to_string(message)?;
line.push('\n');
self.stream.write_all(line.as_bytes())
}
}
/// Sends several messages to the daemon on one connection, which handles them in order, and does
/// not wait for them to be handled
///