From 9217b327983691dd1a8bba185270d0d0e2e03410 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sun, 3 May 2026 17:19:32 +0300 Subject: [PATCH] commands: fix MIME fallback in TUI; improve watch logging Signed-off-by: NotAShelf Change-Id: I67d0486ca9719b334957ff3868da3f0c6a6a6964 --- src/commands/list.rs | 2 +- src/commands/watch.rs | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/commands/list.rs b/src/commands/list.rs index b3041e5..369949c 100644 --- a/src/commands/list.rs +++ b/src/commands/list.rs @@ -698,7 +698,7 @@ impl SqliteClipboardDb { let mime_type = match mime { Some(ref m) if m == "text/plain" => MimeType::Text, Some(ref m) => MimeType::Specific(m.clone().clone()), - None => MimeType::Text, + None => MimeType::Autodetect, }; let copy_result = opts .copy(Source::Bytes(contents.clone().into()), mime_type); diff --git a/src/commands/watch.rs b/src/commands/watch.rs index 71cdc17..111a330 100644 --- a/src/commands/watch.rs +++ b/src/commands/watch.rs @@ -435,6 +435,14 @@ impl WatchCommand for SqliteClipboardDb { log::info!("clipboard entry excluded by app filter"); last_hash = Some(current_hash); }, + Err(crate::db::StashError::AllWhitespace) => { + log::debug!("clipboard entry is all whitespace, skipping"); + last_hash = Some(current_hash); + }, + Err(crate::db::StashError::TooSmall(_)) => { + log::debug!("clipboard entry below minimum size, skipping"); + last_hash = Some(current_hash); + }, Err(e) => { log::error!("failed to store clipboard entry: {e}"); last_hash = Some(current_hash); @@ -518,8 +526,8 @@ mod tests { #[test] fn test_pick_image_preference_falls_back() { + // No image types in offer set; first type is used as fallback. let offered = vec!["text/html".to_string(), "text/plain".to_string()]; - // No image types offered — falls back to first assert_eq!(pick_mime(&offered, "image").unwrap(), "text/html"); } @@ -550,14 +558,14 @@ mod tests { #[test] fn test_pick_html_fallback_when_only_html() { - // When text/html is the only type, pick it + // text/html is used when it is the only offered type. let offered = vec!["text/html".to_string()]; assert_eq!(pick_mime(&offered, "any").unwrap(), "text/html"); } #[test] fn test_pick_text_over_html_when_no_image() { - // Rich text copy: html + plain, no image — prefer plain text + // html + plain with no image type; plain text wins over html. let offered = vec!["text/html".to_string(), "text/plain".to_string()]; assert_eq!(pick_mime(&offered, "any").unwrap(), "text/plain"); }