uds ipc working

This commit is contained in:
2026-03-08 19:07:37 +01:00
parent dcc863c451
commit 54ddc9851c
6 changed files with 64 additions and 2 deletions

View File

@ -112,4 +112,10 @@ impl Database {
Ok(entries)
}
pub fn delete_entry_by_content(&self, content: &str) -> Result<(), Box<dyn Error>> {
self.conn
.execute("DELETE FROM history WHERE content = ?1", [content])?;
Ok(())
}
}

View File

@ -11,6 +11,7 @@ use std::sync::{Arc, Mutex};
pub enum IpcRequest {
GetHistory { limit: usize },
SetClipboard { content: String },
DeleteEntry { content: String },
}
#[derive(Serialize, Deserialize, Debug)]
@ -90,6 +91,29 @@ pub fn start_server(db: Arc<Mutex<Database>>, socket_path: &Path) {
}
}
}
IpcRequest::DeleteEntry { content } => {
{
let db_lock = db_clone.lock().unwrap();
let _ = db_lock.delete_entry_by_content(&content);
}
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 img_path.exists() {
if let Err(e) = std::fs::remove_file(&img_path) {
eprintln!("Error while deleting image: {}", e);
} else {
println!("Image deleted : {}", content);
}
}
}
}
}
}
}
}