Add icon preview to drag-and-drop dialog

Fast icon extraction pulls .DirIcon from the squashfs without full
analysis. Single-file drops show a 64px preview in the dialog while
the user chooses an import option.
This commit is contained in:
lashman
2026-02-27 23:58:09 +02:00
parent 843af0a8a5
commit 00a1ed3599
2 changed files with 67 additions and 0 deletions

View File

@@ -603,6 +603,50 @@ fn make_app_id(name: &str) -> String {
.to_string()
}
/// Quickly extract just the icon from an AppImage (for preview).
/// Only extracts .DirIcon and root-level .png/.svg files.
/// Returns the path to the cached icon if successful.
pub fn extract_icon_fast(appimage_path: &Path) -> Option<PathBuf> {
if !has_unsquashfs() {
return None;
}
let offset = find_squashfs_offset(appimage_path).ok()?;
let tmp = tempfile::tempdir().ok()?;
let dest = tmp.path().join("icon_extract");
let status = Command::new("unsquashfs")
.arg("-offset")
.arg(offset.to_string())
.arg("-no-progress")
.arg("-force")
.arg("-dest")
.arg(&dest)
.arg(appimage_path)
.arg(".DirIcon")
.arg("*.png")
.arg("*.svg")
.stdout(std::process::Stdio::null())
.stderr(std::process::Stdio::null())
.status()
.ok()?;
if !status.success() {
return None;
}
let icon_path = find_icon(&dest, None)?;
// Generate app_id from filename
let stem = appimage_path
.file_stem()
.and_then(|s| s.to_str())
.unwrap_or("unknown");
let app_id = make_app_id(stem);
cache_icon(&icon_path, &app_id)
}
/// Inspect an AppImage and extract its metadata.
pub fn inspect_appimage(
path: &Path,