From 1ec040ef1e73e76496d56dda3f7b0478110112e1 Mon Sep 17 00:00:00 2001 From: PandaDEV <70103896+0PandaDEV@users.noreply.github.com> Date: Sat, 15 Mar 2025 01:08:53 +0100 Subject: [PATCH] feat: add icon support to app info display and update styles for improved layout in index.scss --- assets/css/index.scss | 9 ++ pages/index.vue | 10 +- src-tauri/Cargo.lock | 182 +++++++------------------------- src-tauri/Cargo.toml | 4 +- src-tauri/src/utils/commands.rs | 26 ++--- 5 files changed, 71 insertions(+), 160 deletions(-) diff --git a/assets/css/index.scss b/assets/css/index.scss index 33ee5d2..8970654 100644 --- a/assets/css/index.scss +++ b/assets/css/index.scss @@ -161,6 +161,15 @@ main { overflow: hidden; white-space: nowrap; margin-left: 32px; + display: flex; + align-items: center; + gap: 4px; + + img { + width: 13px; + height: 13px; + object-fit: contain; + } } } } diff --git a/pages/index.vue b/pages/index.vue index ea85976..de6b002 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -59,6 +59,7 @@ + {{ row.value }} @@ -747,7 +748,12 @@ const infoRows = computed(() => { if (!getInfo.value) return []; const commonRows = [ - { label: "Source", value: getInfo.value.source, isUrl: false }, + { + label: "Source", + value: getInfo.value.source, + isUrl: false, + icon: selectedItem.value?.source_icon ? `data:image/png;base64,${selectedItem.value.source_icon}` : undefined + }, { label: "Content Type", value: @@ -759,7 +765,7 @@ const infoRows = computed(() => { const typeSpecificRows: Record< ContentType, - Array<{ label: string; value: string | number; isUrl?: boolean }> + Array<{ label: string; value: string | number; isUrl?: boolean; icon?: string }> > = { [ContentType.Text]: [ { label: "Characters", value: (getInfo.value as InfoText).characters }, diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index b05593a..b0ed3af 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -2,20 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "active-win-pos-rs" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b37fd8a23464e913e3fcc1ff2d347c06d77f9101ee680c42b32d020508dc834" -dependencies = [ - "appkit-nsworkspace-bindings", - "core-foundation 0.9.4", - "core-graphics 0.23.2", - "objc", - "windows 0.48.0", - "xcb", -] - [[package]] name = "addr2line" version = "0.22.0" @@ -88,20 +74,10 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" -[[package]] -name = "appkit-nsworkspace-bindings" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "062382938604cfa02c03689ab75af0e7eb79175ba0d0b2bcfad18f5190702dd7" -dependencies = [ - "bindgen", - "objc", -] - [[package]] name = "applications" -version = "0.2.3" -source = "git+https://github.com/HuakunShen/applications-rs?branch=dev#ac41b051f0ebeac96213c6c32621b098634219ac" +version = "0.3.0" +source = "git+https://github.com/HuakunShen/applications-rs?branch=load_icon#bcfbebb93a57918aca4ba51257b2788be90892da" dependencies = [ "anyhow", "cocoa 0.25.0", @@ -120,6 +96,8 @@ dependencies = [ "tauri-icns", "thiserror 1.0.63", "walkdir", + "winapi", + "windows-icons", "winreg 0.52.0", ] @@ -401,29 +379,6 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" -[[package]] -name = "bindgen" -version = "0.68.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "726e4313eb6ec35d2730258ad4e15b547ee75d6afaa1361a922e78e59b7d8078" -dependencies = [ - "bitflags 2.8.0", - "cexpr", - "clang-sys", - "lazy_static", - "lazycell", - "log", - "peeking_take_while", - "prettyplease", - "proc-macro2", - "quote", - "regex", - "rustc-hash 1.1.0", - "shlex", - "syn 2.0.87", - "which", -] - [[package]] name = "bit-set" version = "0.5.3" @@ -685,15 +640,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" -[[package]] -name = "cexpr" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" -dependencies = [ - "nom", -] - [[package]] name = "cfb" version = "0.7.3" @@ -742,17 +688,6 @@ dependencies = [ "windows-link", ] -[[package]] -name = "clang-sys" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" -dependencies = [ - "glob", - "libc", - "libloading 0.8.6", -] - [[package]] name = "clipboard-rs" version = "0.2.1" @@ -2017,9 +1952,9 @@ dependencies = [ [[package]] name = "glob" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" +checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2" [[package]] name = "global-hotkey" @@ -2804,12 +2739,6 @@ dependencies = [ "spin", ] -[[package]] -name = "lazycell" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" - [[package]] name = "lebe" version = "0.5.2" @@ -3762,12 +3691,6 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" -[[package]] -name = "peeking_take_while" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" - [[package]] name = "pem-rfc7468" version = "0.7.0" @@ -4029,16 +3952,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" -[[package]] -name = "prettyplease" -version = "0.2.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64d1ec885c64d0457d564db4ec299b2dae3f9c02808b8ad9c3a089c591b18033" -dependencies = [ - "proc-macro2", - "syn 2.0.87", -] - [[package]] name = "proc-macro-crate" version = "1.3.1" @@ -4129,10 +4042,10 @@ dependencies = [ name = "qopy" version = "0.4.0" dependencies = [ - "active-win-pos-rs", "applications", "base64 0.22.1", "chrono", + "glob", "global-hotkey", "image", "include_dir", @@ -4172,15 +4085,6 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3" -[[package]] -name = "quick-xml" -version = "0.30.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eff6510e86862b57b210fd8cbe8ed3f0d7d600b9c2863cd4549a2e033c66e956" -dependencies = [ - "memchr", -] - [[package]] name = "quick-xml" version = "0.32.0" @@ -4209,7 +4113,7 @@ dependencies = [ "pin-project-lite", "quinn-proto", "quinn-udp", - "rustc-hash 2.0.0", + "rustc-hash", "rustls", "socket2", "thiserror 1.0.63", @@ -4226,7 +4130,7 @@ dependencies = [ "bytes", "rand 0.8.5", "ring", - "rustc-hash 2.0.0", + "rustc-hash", "rustls", "slab", "thiserror 1.0.63", @@ -4657,12 +4561,6 @@ version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" -[[package]] -name = "rustc-hash" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" - [[package]] name = "rustc-hash" version = "2.0.0" @@ -5035,12 +4933,6 @@ dependencies = [ "digest", ] -[[package]] -name = "shlex" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" - [[package]] name = "signal-hook-registry" version = "1.4.2" @@ -6926,18 +6818,6 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082" -[[package]] -name = "which" -version = "4.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" -dependencies = [ - "either", - "home", - "once_cell", - "rustix", -] - [[package]] name = "whoami" version = "1.5.1" @@ -7002,11 +6882,12 @@ dependencies = [ [[package]] name = "windows" -version = "0.48.0" +version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" +checksum = "7f919aee0a93304be7f62e8e5027811bbba96bcb1de84d6618be56e43f8a32a1" dependencies = [ - "windows-targets 0.48.5", + "windows-core 0.59.0", + "windows-targets 0.53.0", ] [[package]] @@ -7040,6 +6921,19 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-core" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "810ce18ed2112484b0d4e15d022e5f598113e220c53e373fb31e67e21670c1ce" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-result", + "windows-strings", + "windows-targets 0.53.0", +] + [[package]] name = "windows-core" version = "0.60.1" @@ -7063,6 +6957,19 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-icons" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42db1b1d99853c231d69b7fdc9782e90fa3004afed14a94c2eba79cac43b5f5a" +dependencies = [ + "base64 0.22.1", + "glob", + "image", + "winapi", + "windows 0.59.0", +] + [[package]] name = "windows-implement" version = "0.59.0" @@ -7577,17 +7484,6 @@ dependencies = [ "rustix", ] -[[package]] -name = "xcb" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1e2f212bb1a92cd8caac8051b829a6582ede155ccb60b5d5908b81b100952be" -dependencies = [ - "bitflags 1.3.2", - "libc", - "quick-xml 0.30.0", -] - [[package]] name = "xdg-home" version = "1.2.0" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 1fe01df..bf040c9 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -47,10 +47,10 @@ global-hotkey = "0.6.4" chrono = { version = "0.4.40", features = ["serde"] } log = { version = "0.4.26", features = ["std"] } uuid = "1.16.0" -active-win-pos-rs = "0.9.0" include_dir = "0.7.4" # hyperpolyglot = { git = "https://github.com/0pandadev/hyperpolyglot" } -applications = { git = "https://github.com/HuakunShen/applications-rs", branch = "dev" } +applications = { git = "https://github.com/HuakunShen/applications-rs", branch = "load_icon" } +glob = "0.3.2" meta_fetcher = "0.1.1" parking_lot = "0.12.3" diff --git a/src-tauri/src/utils/commands.rs b/src-tauri/src/utils/commands.rs index 48c84e5..c1cc3bf 100644 --- a/src-tauri/src/utils/commands.rs +++ b/src-tauri/src/utils/commands.rs @@ -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) { - 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> { - 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();