mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-04-20 11:54:23 +02:00
This is a first pass towards trying to structure things a bit better, with data generally encapsulated under a single hierarchical tree, rather than lots of globals all over the place. Lots of work is still required. The plan is that with this and some more work, #291 should become a lot easier to sort.
37 lines
847 B
Rust
37 lines
847 B
Rust
mod client;
|
|
pub mod commands;
|
|
pub mod responses;
|
|
mod server;
|
|
|
|
use std::path::{Path, PathBuf};
|
|
use tracing::warn;
|
|
|
|
pub use commands::Command;
|
|
pub use responses::Response;
|
|
|
|
#[derive(Debug)]
|
|
pub struct Ipc {
|
|
path: PathBuf,
|
|
}
|
|
|
|
impl Ipc {
|
|
/// Creates a new IPC instance.
|
|
/// This can be used as both a server and client.
|
|
pub fn new() -> Self {
|
|
let ipc_socket_file = std::env::var("XDG_RUNTIME_DIR")
|
|
.map_or_else(|_| PathBuf::from("/tmp"), PathBuf::from)
|
|
.join("ironbar-ipc.sock");
|
|
|
|
if format!("{}", ipc_socket_file.display()).len() > 100 {
|
|
warn!("The IPC socket file's absolute path exceeds 100 bytes, the socket may fail to create.");
|
|
}
|
|
|
|
Self {
|
|
path: ipc_socket_file,
|
|
}
|
|
}
|
|
|
|
pub fn path(&self) -> &Path {
|
|
self.path.as_path()
|
|
}
|
|
}
|