From 17894a24e3e6bd5cf73f5aad0eb7dae268dc05f5 Mon Sep 17 00:00:00 2001 From: pandadev <70103896+0PandaDEV@users.noreply.github.com> Date: Sat, 15 Mar 2025 16:29:57 +0100 Subject: [PATCH] feat: add logging for app info retrieval and implement icon processing to base64 --- src-tauri/src/utils/commands.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src-tauri/src/utils/commands.rs b/src-tauri/src/utils/commands.rs index c1cc3bf..2579abe 100644 --- a/src-tauri/src/utils/commands.rs +++ b/src-tauri/src/utils/commands.rs @@ -36,24 +36,43 @@ pub fn center_window_on_current_monitor(window: &tauri::WebviewWindow) { } pub fn get_app_info() -> (String, Option) { + println!("Getting app info"); let mut ctx = AppInfoContext::new(vec![]); + println!("Created AppInfoContext"); ctx.refresh_apps().unwrap(); + println!("Refreshed apps"); match ctx.get_frontmost_application() { Ok(window) => { + println!("Found frontmost application: {}", window.name); let name = window.name.clone(); let icon = window .load_icon() .ok() .map(|i| { + println!("Loading icon for {}", name); let png = i.to_png().unwrap(); - STANDARD.encode(png.get_bytes()) + let encoded = STANDARD.encode(png.get_bytes()); + println!("Icon encoded successfully"); + encoded }); + println!("Returning app info: {} with icon: {}", name, icon.is_some()); (name, icon) } - Err(_) => ("System".to_string(), None), + Err(e) => { + println!("Failed to get frontmost application: {:?}", e); + ("System".to_string(), None) + } } } +fn _process_icon_to_base64(path: &str) -> Result> { + let img = image::open(path)?; + let resized = img.resize(128, 128, image::imageops::FilterType::Lanczos3); + let mut png_buffer = Vec::new(); + resized.write_with_encoder(PngEncoder::new(&mut png_buffer))?; + Ok(STANDARD.encode(png_buffer)) +} + pub fn detect_color(color: &str) -> bool { let color = color.trim().to_lowercase();