uds ipc working
This commit is contained in:
14
src/ipc.rs
14
src/ipc.rs
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user