feat: add icon support to app info display and update styles for improved layout in index.scss

This commit is contained in:
PandaDEV 2025-03-15 01:08:53 +01:00
parent f890851a59
commit 1ec040ef1e
No known key found for this signature in database
GPG key ID: 13EFF9BAF70EE75C
5 changed files with 71 additions and 160 deletions

View file

@ -1,6 +1,5 @@
use active_win_pos_rs::get_active_window;
use applications::{AppInfoContext, AppInfo, AppTrait, utils::image::RustImage};
use base64::{ engine::general_purpose::STANDARD, Engine };
use image::codecs::png::PngEncoder;
use tauri::PhysicalPosition;
use meta_fetcher;
@ -37,23 +36,24 @@ pub fn center_window_on_current_monitor(window: &tauri::WebviewWindow) {
}
pub fn get_app_info() -> (String, Option<String>) {
match get_active_window() {
let mut ctx = AppInfoContext::new(vec![]);
ctx.refresh_apps().unwrap();
match ctx.get_frontmost_application() {
Ok(window) => {
let app_name = window.app_name;
(app_name, None)
let name = window.name.clone();
let icon = window
.load_icon()
.ok()
.map(|i| {
let png = i.to_png().unwrap();
STANDARD.encode(png.get_bytes())
});
(name, icon)
}
Err(_) => ("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();