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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user