From 398e86fa33a5730fa49756e411299dee6e5b8bd9 Mon Sep 17 00:00:00 2001 From: Naz Date: Sat, 9 Aug 2025 13:51:20 +0100 Subject: =?UTF-8?q?=F0=9F=90=9Bfix:=20add=20fallback=20icon=20resolution?= =?UTF-8?q?=20and=20conditional=20icon=20path=20updates?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/appimage.rs | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) (limited to 'src/appimage.rs') diff --git a/src/appimage.rs b/src/appimage.rs index bf0de6d..62cc8be 100644 --- a/src/appimage.rs +++ b/src/appimage.rs @@ -63,10 +63,16 @@ impl AppImage { .current_dir(&temp_dir) .spawn()? .wait()?; + Command::new(&self.file_path) + .arg("--appimage-extract") + .arg("usr/share/icons/hicolor/256x256/apps/*.png") + .current_dir(&temp_dir) + .spawn()? + .wait()?; Ok(temp_dir) } - async fn fix_desktop(&self, desktop_file_path: &PathBuf) -> Result<()> { + async fn fix_desktop(&self, desktop_file_path: &PathBuf, icon_found: bool) -> Result<()> { let file_content = fs::read_to_string(&desktop_file_path).await?; let appimage_path = self.file_path.to_str().ok_or(Error::InvalidPath)?; @@ -92,7 +98,7 @@ impl AppImage { } else { line.to_string() } - } else if line.contains("Icon=") { + } else if line.contains("Icon=") && icon_found { if let Some(exec_arg) = line.split_once("=") { format!("{}={}", exec_arg.0, icon_path) } else { @@ -124,25 +130,39 @@ impl AppImage { )), ); + let mut icon_found = false; + + if fs::try_exists(&squashfs.join("usr/share/icons/hicolor/512x512/apps")).await? { + let mut squashfs_icon_entries = + fs::read_dir(&squashfs.join("usr/share/icons/hicolor/512x512/apps")).await?; + while let Some(entry) = squashfs_icon_entries.next_entry().await? { + if entry.path().extension() == Some("png".as_ref()) { + fs::copy(entry.path(), &icon_path).await?; + icon_found = true; + } + } + } else if fs::try_exists(&squashfs.join("usr/share/icons/hicolor/256x256/apps")).await? { + let mut squashfs_icon_entries = + fs::read_dir(&squashfs.join("usr/share/icons/hicolor/256x256/apps")).await?; + while let Some(entry) = squashfs_icon_entries.next_entry().await? { + if entry.path().extension() == Some("png".as_ref()) { + fs::copy(entry.path(), &icon_path).await?; + icon_found = true; + } + } + } + let mut squashfs_entries = fs::read_dir(&squashfs).await?; while let Some(entry) = squashfs_entries.next_entry().await? { if entry.path().extension() == Some("desktop".as_ref()) { fs::copy(entry.path(), &desktop_file_paths.0).await?; - self.fix_desktop(&desktop_file_paths.0).await?; + self.fix_desktop(&desktop_file_paths.0, icon_found).await?; fs::copy(&desktop_file_paths.0, &desktop_file_paths.1).await?; } } - let mut squashfs_icon_entries = - fs::read_dir(&squashfs.join("usr/share/icons/hicolor/512x512/apps")).await?; - while let Some(entry) = squashfs_icon_entries.next_entry().await? { - if entry.path().extension() == Some("png".as_ref()) { - fs::copy(entry.path(), &icon_path).await?; - } - } - // Clean up fs::remove_dir_all(temp_dir).await?; -- cgit v1.2.3 From e21127f9b26796cf2ff4380b8b42d2ebd8645a2a Mon Sep 17 00:00:00 2001 From: Naz Date: Sat, 9 Aug 2025 13:58:56 +0100 Subject: =?UTF-8?q?=E2=9C=A8feat:=20hide=20stdout=20of=20--appimage-extrac?= =?UTF-8?q?t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/appimage.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/appimage.rs') diff --git a/src/appimage.rs b/src/appimage.rs index 62cc8be..07fb990 100644 --- a/src/appimage.rs +++ b/src/appimage.rs @@ -1,5 +1,8 @@ use serde::{Deserialize, Serialize}; -use std::{path::PathBuf, process::Command}; +use std::{ + path::PathBuf, + process::{Command, Stdio}, +}; use tokio::fs; use crate::{Error, InstallArgs, Result, desktops_dir, icons_dir}; @@ -53,6 +56,7 @@ impl AppImage { .arg("--appimage-extract") .arg("*.desktop") .current_dir(&temp_dir) + .stdout(Stdio::null()) .spawn()? .wait()?; @@ -61,12 +65,14 @@ impl AppImage { .arg("--appimage-extract") .arg("usr/share/icons/hicolor/512x512/apps/*.png") .current_dir(&temp_dir) + .stdout(Stdio::null()) .spawn()? .wait()?; Command::new(&self.file_path) .arg("--appimage-extract") .arg("usr/share/icons/hicolor/256x256/apps/*.png") .current_dir(&temp_dir) + .stdout(Stdio::null()) .spawn()? .wait()?; -- cgit v1.2.3 From e5577490000f0f0ce99a047f320eefd0e7d3e5c7 Mon Sep 17 00:00:00 2001 From: Naz Date: Sat, 9 Aug 2025 14:23:55 +0100 Subject: =?UTF-8?q?=E2=9C=A8feat:=20check=20all=20icon=20resolutions=20fro?= =?UTF-8?q?m=201024x1024=20to=2016x16?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/appimage.rs | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) (limited to 'src/appimage.rs') diff --git a/src/appimage.rs b/src/appimage.rs index 07fb990..1cb8f52 100644 --- a/src/appimage.rs +++ b/src/appimage.rs @@ -63,14 +63,7 @@ impl AppImage { // Extract icon Command::new(&self.file_path) .arg("--appimage-extract") - .arg("usr/share/icons/hicolor/512x512/apps/*.png") - .current_dir(&temp_dir) - .stdout(Stdio::null()) - .spawn()? - .wait()?; - Command::new(&self.file_path) - .arg("--appimage-extract") - .arg("usr/share/icons/hicolor/256x256/apps/*.png") + .arg("usr/share/icons/hicolor/*/apps/*.png") .current_dir(&temp_dir) .stdout(Stdio::null()) .spawn()? @@ -136,24 +129,27 @@ impl AppImage { )), ); + let icon_resolutions = [ + "1024", "720", "512", "256", "192", "128", "96", "72", "64", "48", "36", "32", "24", + "22", "16", + ]; + let mut icon_found = false; - if fs::try_exists(&squashfs.join("usr/share/icons/hicolor/512x512/apps")).await? { - let mut squashfs_icon_entries = - fs::read_dir(&squashfs.join("usr/share/icons/hicolor/512x512/apps")).await?; - while let Some(entry) = squashfs_icon_entries.next_entry().await? { - if entry.path().extension() == Some("png".as_ref()) { - fs::copy(entry.path(), &icon_path).await?; - icon_found = true; + for res in icon_resolutions { + let icon_dir = squashfs.join(format!("usr/share/icons/hicolor/{}x{}/apps", res, res)); + + if fs::try_exists(&icon_dir).await? { + let mut squashfs_icon_entries = fs::read_dir(&icon_dir).await?; + while let Some(entry) = squashfs_icon_entries.next_entry().await? { + if entry.path().extension() == Some("png".as_ref()) { + fs::copy(entry.path(), &icon_path).await?; + icon_found = true; + break; + } } - } - } else if fs::try_exists(&squashfs.join("usr/share/icons/hicolor/256x256/apps")).await? { - let mut squashfs_icon_entries = - fs::read_dir(&squashfs.join("usr/share/icons/hicolor/256x256/apps")).await?; - while let Some(entry) = squashfs_icon_entries.next_entry().await? { - if entry.path().extension() == Some("png".as_ref()) { - fs::copy(entry.path(), &icon_path).await?; - icon_found = true; + if icon_found { + break; } } } -- cgit v1.2.3