From 5bcc23b6f986e1946186036453edd1edc6a2e945 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Tue, 12 Aug 2025 21:47:03 +0300 Subject: [PATCH] stash: don't initialize watch daemon with `None` Fixes the daemon always updating the latest entry. Signed-off-by: NotAShelf Change-Id: I6a6a696489a2e9a0928ff799a4210c160014c485 --- src/main.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 196954c..03b78ea 100644 --- a/src/main.rs +++ b/src/main.rs @@ -101,7 +101,22 @@ fn report_error(result: Result, context: &str) -> async fn run_daemon(db: &db::SqliteClipboardDb, max_dedupe_search: u64, max_items: u64) { log::info!("Starting clipboard watch daemon"); - let mut last_contents: Option> = None; + // Initialize with current clipboard to avoid duplicating on startup + let mut last_contents: Option> = match get_contents( + ClipboardType::Regular, + Seat::Unspecified, + wl_clipboard_rs::paste::MimeType::Any, + ) { + Ok((mut reader, _)) => { + let mut buf = Vec::new(); + if reader.read_to_end(&mut buf).is_ok() && !buf.is_empty() { + Some(buf) + } else { + None + } + } + Err(_) => None, + }; loop { match get_contents(