init: initial commit
This commit is contained in:
commit
b803dcb20e
5 changed files with 401 additions and 0 deletions
55
src/main.rs
Normal file
55
src/main.rs
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
use anyhow::{Error, Result};
|
||||
use interprocess::local_socket::{
|
||||
GenericNamespaced, ListenerOptions, NameType, Stream, ToNsName, traits::ListenerExt,
|
||||
};
|
||||
use std::{
|
||||
io::{self, BufRead, BufReader},
|
||||
process,
|
||||
};
|
||||
use tracing::{error, trace};
|
||||
|
||||
fn handle_error(conn: io::Result<Stream>) -> Option<Stream> {
|
||||
match conn {
|
||||
Ok(c) => Some(c),
|
||||
Err(e) => {
|
||||
error!("incoming connection failed: {e:#?}");
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Error> {
|
||||
tracing_subscriber::fmt().init();
|
||||
|
||||
let name = if GenericNamespaced::is_supported() {
|
||||
"honeycomb-mgr.sock".to_ns_name::<GenericNamespaced>()?
|
||||
} else {
|
||||
"/tmp/homeycomb-mgr.sock".to_ns_name::<GenericNamespaced>()?
|
||||
};
|
||||
|
||||
let opts = ListenerOptions::new().name(name);
|
||||
let listener = opts.create_sync()?;
|
||||
let mut buffer = String::new();
|
||||
|
||||
for conn in listener.incoming().filter_map(handle_error) {
|
||||
let mut conn = BufReader::new(conn);
|
||||
|
||||
conn.read_line(&mut buffer)?;
|
||||
match &buffer.clone() as &str {
|
||||
"recents\n" => match process::Command::new("honeycomb-recents").spawn() {
|
||||
Ok(ok) => {
|
||||
trace!("spawned cosmic-recents:\n{ok:#?}");
|
||||
}
|
||||
Err(e) => {
|
||||
error!("unable to spawn recents:\n{e:#?}");
|
||||
}
|
||||
},
|
||||
|
||||
_ => {}
|
||||
};
|
||||
|
||||
buffer.clear();
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue