From 1d28fc6439b282c458e08573265cc118c18aada1 Mon Sep 17 00:00:00 2001 From: Ilija Chrchev Date: Fri, 20 Nov 2026 04:02:02 +0100 Subject: [PATCH] Refresh user icon cache after AppImage desktop integration (#1877) (#2115) On Fedora (and other GTK desktops), the hicolor icon cache is not rebuilt after the AppImage copies its icons into $XDG_DATA_HOME. The desktop keeps showing a generic icon until the user logs out or manually runs gtk-update-icon-cache. Add a conditional cache refresh to the AppRun integration step: - Track whether any icon file was actually copied (changed). - Only refresh if the cache file (icon-theme.cache) already exists, so we never create one where the desktop hasn't built one yet. - Skip silently when gtk-update-icon-cache is not installed. The fix lives in the AppImage's own AppRun rather than in the launcher because the launcher (appimagelauncher) is a separate project with its own release cycle, and many users run AppImages directly without it. Both fixes are complementary. Tested on Fedora 41 (GNOME 47, Wayland) by launching from the app grid after clearing the icon cache. The correct icon appeared on the first launch without a logout. Closes #1877 --- packaging/linux/AppRun | 18 +++++++++++++++--- packaging/linux/apprun-test.sh | 18 ++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/packaging/linux/AppRun b/packaging/linux/AppRun index c3004f2f6..9eb5876b6 100755 --- a/packaging/linux/AppRun +++ b/packaging/linux/AppRun @@ -57,15 +57,27 @@ integrate() { fi # Icons: per-file compare so an unchanged install costs a handful of cmp calls. + # Track whether any icon was actually copied so the cache is refreshed only when + # something changed (#1877). src_icons="$APPDIR/usr/share/icons/hicolor" [ -d "$src_icons" ] || return 0 icons="$data/icons/hicolor" - (cd "$src_icons" && find . -type f) | while IFS= read -r rel; do + icons_changed=false + while IFS= read -r rel; do mkdir -p "$icons/$(dirname "$rel")" 2>/dev/null || continue if ! cmp -s "$src_icons/$rel" "$icons/$rel"; then - cp "$src_icons/$rel" "$icons/$rel" 2>/dev/null || true + cp "$src_icons/$rel" "$icons/$rel" 2>/dev/null && icons_changed=true fi - done + done </dev/null 2>&1; then + gtk-update-icon-cache -q "$icons" >/dev/null 2>&1 || true + fi + fi } # The command-line tool ships beside the app but nothing puts it on PATH, and the launcher renames diff --git a/packaging/linux/apprun-test.sh b/packaging/linux/apprun-test.sh index 498999249..c6602fd63 100755 --- a/packaging/linux/apprun-test.sh +++ b/packaging/linux/apprun-test.sh @@ -112,4 +112,22 @@ out="$(ARGV0="/home/u/.local/bin/craft-anything-cli" "$APPDIR/AppRun" --version) out="$(ARGV0="craft-anything" "$APPDIR/AppRun" open --cli)" || fail "app launch exited non-zero" [[ "$out" = "stub: open --cli" ]] || fail "app launch routed to the CLI: $out" +# 13. No icon cache is created where there was none (#1877). +[[ ! -f "$XDG_DATA_HOME/icons/hicolor/icon-theme.cache" ]] || fail "icon cache created where there was none" + +# 14. When no icon changed, the cache file is not touched (#1877). +icons_dir="$XDG_DATA_HOME/icons/hicolor" +mkdir -p "$icons_dir" +echo "sentinel" >"$icons_dir/icon-theme.cache" +"$APPDIR/AppRun" >/dev/null || fail "launch with unchanged icons exited non-zero" +[[ "$(cat "$icons_dir/icon-theme.cache")" = "sentinel" ]] || fail "icon cache refreshed although nothing changed" + +# 15. When an icon changed and a cache exists, the cache may be refreshed (#1877). +src_icon="$APPDIR/usr/share/icons/hicolor/16x16/apps/$APP_ID.png" +cp "$src_icon" "$src_icon.bak" +printf 'x' >>"$src_icon" +echo "old" >"$icons_dir/icon-theme.cache" +"$APPDIR/AppRun" >/dev/null || fail "launch with changed icon exited non-zero" +mv "$src_icon.bak" "$src_icon" + echo "AppRun desktop integration and CLI routing ok"