feat: add support for additional MIME types in image processing

This commit is contained in:
2026-03-17 21:53:14 +01:00
parent 271d55ba57
commit 308867b2d9
4 changed files with 29 additions and 8 deletions

View File

@@ -4,6 +4,7 @@ use tracing::{debug, info, trace};
pub fn process_once(
provider: &dyn ClipboardProvider,
opts: &ShrinkOptions,
extra_mimes: &[String],
last_hash: &mut Option<[u8; 32]>,
) -> Result<(), Box<dyn std::error::Error>> {
let (data, mime_type) = match provider.capture() {
@@ -38,10 +39,15 @@ pub fn process_once(
result.mime_type
);
provider.distribute(&[(&result.data, result.mime_type.as_str())])?;
// Primary MIME type first, then any aliases the user wants to lie about.
let mut items: Vec<(&[u8], &str)> = vec![(&result.data, result.mime_type.as_str())];
for alias in extra_mimes {
if alias != &result.mime_type {
items.push((&result.data, alias.as_str()));
}
}
provider.distribute(&items)?;
// Track hash of OUTPUT. After distributing webp-only, next capture will
// find image/webp (from our subprocess) → same hash → skip. No loop.
*last_hash = Some(image_hash(&result.data));
Ok(())
}

View File

@@ -17,6 +17,7 @@ async fn main() {
};
let poll = Duration::from_millis(cfg.general.poll_ms);
let extra_mimes = cfg.general.extra_mimes.clone();
let opts = ShrinkOptions {
quality: cfg.general.quality,
target_format: cfg.general.format.into(),
@@ -27,7 +28,7 @@ async fn main() {
info!("k-shrink daemon started (poll={}ms)", cfg.general.poll_ms);
loop {
if let Err(e) = k_shrink::process_once(&backend, &opts, &mut last_hash) {
if let Err(e) = k_shrink::process_once(&backend, &opts, &extra_mimes, &mut last_hash) {
error!("error: {e}");
}
tokio::time::sleep(poll).await;