mirror of
https://github.com/0PandaDEV/Qopy.git
synced 2025-04-21 21:24:05 +02:00
feat: add logging for app info retrieval and implement icon processing to base64
This commit is contained in:
parent
8bc27fc888
commit
17894a24e3
1 changed files with 21 additions and 2 deletions
|
@ -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();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue