uds ipc working

This commit is contained in:
2026-03-08 18:57:28 +01:00
parent 9e56322705
commit dcc863c451
5 changed files with 174 additions and 95 deletions

View File

@ -5,6 +5,7 @@ use std::os::unix::net::UnixStream;
#[derive(Serialize, Deserialize, Debug)]
pub enum IpcRequest {
GetHistory { limit: usize },
SetClipboard { content: String },
}
#[derive(Serialize, Deserialize, Debug)]
@ -35,3 +36,16 @@ pub fn fetch_history(limit: usize) -> Option<Vec<String>> {
None
}
pub fn set_clipboard(content: String) {
if let Some(base_dir) = directories::ProjectDirs::from("com", "zefad", "rklipd") {
let socket_path = base_dir.data_dir().join("rklip.sock");
if let Ok(mut stream) = UnixStream::connect(&socket_path) {
let req = IpcRequest::SetClipboard { content };
if let Ok(req_json) = serde_json::to_string(&req) {
let _ = stream.write_all(req_json.as_bytes());
let _ = stream.shutdown(std::net::Shutdown::Write);
}
}
}
}