feat: add logging for app info retrieval and implement icon processing to base64

This commit is contained in:
pandadev 2025-03-15 16:29:57 +01:00
parent 8bc27fc888
commit 17894a24e3
No known key found for this signature in database
GPG key ID: C39629DACB8E762F

View file

@ -36,24 +36,43 @@ pub fn center_window_on_current_monitor(window: &tauri::WebviewWindow) {
}
pub fn get_app_info() -> (String, Option<String>) {
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<String, Box<dyn std::error::Error>> {
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();