2023-06-22 23:06:45 +01:00
|
|
|
mod client;
|
|
|
|
pub mod commands;
|
|
|
|
pub mod responses;
|
|
|
|
mod server;
|
|
|
|
|
2023-07-16 18:57:00 +01:00
|
|
|
use std::path::{Path, PathBuf};
|
2023-06-22 23:06:45 +01:00
|
|
|
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.
|
2023-12-08 22:39:27 +00:00
|
|
|
pub fn new() -> Self {
|
2023-06-22 23:06:45 +01:00
|
|
|
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,
|
|
|
|
}
|
|
|
|
}
|
2023-07-16 18:57:00 +01:00
|
|
|
|
|
|
|
pub fn path(&self) -> &Path {
|
|
|
|
self.path.as_path()
|
|
|
|
}
|
2023-06-22 23:06:45 +01:00
|
|
|
}
|