mirror of
https://github.com/kunkunsh/kunkun.git
synced 2025-04-03 22:26:43 +00:00
feat(desktop): improve app icon handling for cross-platform support
- Add platform-specific icon path selection for Windows - Enhance app command item rendering with dynamic icon resolution - Modify icon loading to use applications-rs for Windows icon extraction - Update Rust icon loading utility to provide more robust error handling
This commit is contained in:
parent
5fc99ca26c
commit
32895a5f0c
@ -65,7 +65,6 @@ cocoa = "0.24.1"
|
||||
mac-security-rs = { workspace = true }
|
||||
objc = "0.2.7"
|
||||
|
||||
|
||||
[target."cfg(not(any(target_os = \"android\", target_os = \"ios\")))".dependencies]
|
||||
tauri-plugin-autostart = "2"
|
||||
tauri-plugin-cli = "2"
|
||||
|
@ -15,7 +15,8 @@
|
||||
</script>
|
||||
|
||||
<DraggableCommandGroup heading="Apps">
|
||||
{#each apps.filter((app) => app.name) as app}
|
||||
{#each apps.filter((app) => app.name) as app, idx}
|
||||
{@const iconPath = platform === "windows" ? (app.icon_path ?? app.app_path_exe) : app.icon_path}
|
||||
<Command.Item
|
||||
class="flex justify-between"
|
||||
onSelect={async () => {
|
||||
@ -39,14 +40,14 @@
|
||||
await getCurrentWindow().hide()
|
||||
appState.clearSearchTerm()
|
||||
}}
|
||||
value={app.app_desktop_path}
|
||||
value={`app:${idx}:${app.app_desktop_path}`}
|
||||
>
|
||||
<span class="flex gap-2">
|
||||
<IconMultiplexer
|
||||
icon={app.icon_path
|
||||
icon={iconPath
|
||||
? {
|
||||
type: IconEnum.RemoteUrl,
|
||||
value: convertFileSrc(app.icon_path, "appicon")
|
||||
value: convertFileSrc(iconPath, "appicon")
|
||||
}
|
||||
: {
|
||||
type: IconEnum.Iconify,
|
||||
@ -55,6 +56,7 @@
|
||||
class="!h-5 !w-5 shrink-0"
|
||||
/>
|
||||
<span>{app.name}</span>
|
||||
<!-- <span>{app.app_path_exe}</span> -->
|
||||
</span>
|
||||
</Command.Item>
|
||||
{/each}
|
||||
|
@ -22,7 +22,7 @@
|
||||
"typescript": "^5.0.0",
|
||||
"verify-package-export": "^0.0.3"
|
||||
},
|
||||
"packageManager": "pnpm@10.4.1",
|
||||
"packageManager": "pnpm@10.5.2",
|
||||
"engines": {
|
||||
"node": ">=22"
|
||||
},
|
||||
|
@ -67,6 +67,7 @@ objc = "0.2.7"
|
||||
tauri-winres = "0.1.1"
|
||||
ico = "0.3.0"
|
||||
|
||||
|
||||
[build-dependencies]
|
||||
tauri-plugin = { version = "2.0.3", features = ["build"] }
|
||||
tonic-build = "0.11"
|
||||
|
@ -7,6 +7,7 @@ use std::{
|
||||
path::PathBuf,
|
||||
};
|
||||
use uuid::Uuid;
|
||||
// use windows_icons::get_icon_by_path;
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
use tauri_icns::{IconFamily, IconType};
|
||||
@ -94,58 +95,21 @@ pub fn load_icon(path: PathBuf) -> tauri::http::Response<Vec<u8>> {
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
pub fn load_icon(path: PathBuf) -> tauri::http::Response<Vec<u8>> {
|
||||
// tauri::http::Response::builder().body(vec![]).unwrap()
|
||||
match path.exists() {
|
||||
true => {
|
||||
let ico_loaded = load_ico(&path);
|
||||
if ico_loaded.is_err() {
|
||||
let res = tauri::http::Response::builder()
|
||||
.status(tauri::http::StatusCode::INTERNAL_SERVER_ERROR)
|
||||
.body("Error loading icon".as_bytes().to_vec())
|
||||
.unwrap();
|
||||
return res;
|
||||
} else {
|
||||
let ico = ico_loaded.unwrap();
|
||||
// write ico to random file name.png, read it and return
|
||||
// Generate a random file name
|
||||
let id = Uuid::new_v4();
|
||||
let file_name = format!("{}.png", id);
|
||||
// get temp folder
|
||||
let temp_dir = std::env::temp_dir();
|
||||
let file_path = temp_dir.join(file_name);
|
||||
// Write the ico to the random file name.png
|
||||
let file = File::create(&file_path).unwrap();
|
||||
ico.write_png(file).unwrap();
|
||||
// Read the file and return the bytes
|
||||
let bytes = std::fs::read(&file_path).expect("Error reading file");
|
||||
// Delete the file
|
||||
std::fs::remove_file(&file_path).unwrap();
|
||||
tauri::http::Response::builder()
|
||||
.header("Content-Type", "image/png")
|
||||
.body(bytes)
|
||||
.unwrap()
|
||||
}
|
||||
match applications::load_icon(&path) {
|
||||
Ok(icon) => {
|
||||
let bytes = icon.to_png().unwrap().get_bytes().to_vec();
|
||||
println!("path: {:?} bytes: {:?}", path, bytes.len());
|
||||
tauri::http::Response::builder()
|
||||
.header("Access-Control-Allow-Origin", "*")
|
||||
.header("Content-Type", "image/png")
|
||||
.body(bytes)
|
||||
.unwrap()
|
||||
}
|
||||
false => {
|
||||
let res = tauri::http::Response::builder()
|
||||
.status(tauri::http::StatusCode::NOT_FOUND)
|
||||
.body("file not found".as_bytes().to_vec())
|
||||
.unwrap();
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Load .ico image
|
||||
#[cfg(target_os = "windows")]
|
||||
pub fn load_ico(path: &Path) -> anyhow::Result<ico::IconImage> {
|
||||
let file = std::fs::File::open(path)?;
|
||||
let icon_dir = ico::IconDir::read(file)?;
|
||||
let image = icon_dir.entries().first();
|
||||
if let Some(image) = image {
|
||||
Ok(image.decode()?)
|
||||
} else {
|
||||
Err(anyhow::anyhow!("No image found"))
|
||||
Err(error) => tauri::http::Response::builder()
|
||||
.header("Access-Control-Allow-Origin", "*")
|
||||
.status(tauri::http::StatusCode::INTERNAL_SERVER_ERROR)
|
||||
.body(error.to_string().as_bytes().to_vec())
|
||||
.unwrap(),
|
||||
}
|
||||
}
|
||||
|
||||
|
2
vendors/applications-rs
vendored
2
vendors/applications-rs
vendored
@ -1 +1 @@
|
||||
Subproject commit b8e85d01100d47cba226a3d65948a2ac4197fc69
|
||||
Subproject commit bcfbebb93a57918aca4ba51257b2788be90892da
|
Loading…
x
Reference in New Issue
Block a user