mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-07-03 03:31:03 +02:00
feat: ipc server and cli
This commit is contained in:
parent
93baf8f568
commit
f5bdc5a027
10 changed files with 427 additions and 6 deletions
33
src/ipc/mod.rs
Normal file
33
src/ipc/mod.rs
Normal file
|
@ -0,0 +1,33 @@
|
|||
mod client;
|
||||
pub mod commands;
|
||||
pub mod responses;
|
||||
mod server;
|
||||
|
||||
use std::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,
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue