This commit is contained in:
2026-03-08 18:37:23 +01:00
parent 5f691c2e2f
commit 9e56322705
8 changed files with 132 additions and 10 deletions

View File

@ -1,7 +1,7 @@
use crate::ipc;
use fuzzy_matcher::{FuzzyMatcher, skim::SkimMatcherV2};
use ratatui::widgets::ListState;
use ratatui_image::{picker::Picker, protocol};
use std::path::Path;
#[derive(PartialEq)]
pub enum Mode {
@ -27,13 +27,9 @@ impl App {
pub fn new() -> Self {
let mut list_state = ListState::default();
list_state.select(Some(0));
let items = vec![
"Ceci est un texte copié.".to_string(),
"https://github.com/ratatui-org/ratatui".to_string(),
"30426b4d-26e0-45af-9fa4-25f4476387a8.jpg".to_string(),
"35789d6a-dea4-46de-90da-aee693a16031.jpg".to_string(),
"fn main() {\n println!(\"Hello\");\n}".to_string(),
];
let items = ipc::fetch_history(100)
.unwrap_or_else(|| vec!["rklipd deamon unaccessible".to_string()]);
let picker = Picker::from_query_stdio().unwrap_or_else(|_| Picker::halfblocks());

View File

@ -0,0 +1,37 @@
use serde::{Deserialize, Serialize};
use std::io::{Read, Write};
use std::os::unix::net::UnixStream;
#[derive(Serialize, Deserialize, Debug)]
pub enum IpcRequest {
GetHistory { limit: usize },
}
#[derive(Serialize, Deserialize, Debug)]
pub enum IpcResponse {
History(Vec<String>),
}
pub fn fetch_history(limit: usize) -> Option<Vec<String>> {
let base_dir = directories::ProjectDirs::from("com", "zefad", "rklipd")?
.data_dir()
.to_path_buf();
let socket_path = base_dir.join("rklip.sock");
if let Ok(mut stream) = UnixStream::connect(&socket_path) {
let req = IpcRequest::GetHistory { limit };
let req_json = serde_json::to_string(&req).unwrap();
let _ = stream.write_all(req_json.as_bytes());
let _ = stream.shutdown(std::net::Shutdown::Write);
let mut response_buffer = String::new();
if stream.read_to_string(&mut response_buffer).is_ok() {
if let Ok(IpcResponse::History(items)) = serde_json::from_str(&response_buffer) {
return Some(items);
}
}
}
None
}