uds ipc working
This commit is contained in:
@ -7,10 +7,10 @@ use std::os::unix::net::UnixListener;
|
||||
use std::path::Path;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
// --- LE CONTRAT (Protocole) ---
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub enum IpcRequest {
|
||||
GetHistory { limit: usize },
|
||||
SetClipboard { content: String },
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
@ -63,6 +63,33 @@ pub fn start_server(db: Arc<Mutex<Database>>, socket_path: &Path) {
|
||||
let response_json = serde_json::to_string(&response).unwrap();
|
||||
let _ = stream.write_all(response_json.as_bytes());
|
||||
}
|
||||
IpcRequest::SetClipboard { content } => {
|
||||
if let Ok(mut clipboard) = arboard::Clipboard::new() {
|
||||
if content.ends_with(".jpg") || content.ends_with(".png") {
|
||||
if let Some(proj_dirs) = directories::ProjectDirs::from(
|
||||
"com", "zefad", "rklipd",
|
||||
) {
|
||||
let img_path = proj_dirs
|
||||
.data_dir()
|
||||
.join("images")
|
||||
.join(&content);
|
||||
if let Ok(img) = image::open(&img_path) {
|
||||
let rgba = img.into_rgba8();
|
||||
let img_data = arboard::ImageData {
|
||||
width: rgba.width() as usize,
|
||||
height: rgba.height() as usize,
|
||||
bytes: std::borrow::Cow::Borrowed(
|
||||
rgba.as_raw(),
|
||||
),
|
||||
};
|
||||
let _ = clipboard.set_image(img_data);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let _ = clipboard.set_text(content);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user