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
This commit is contained in:
Ilija Chrchev
2026-11-19 20:02:02 -07:00
committed by GitHub
parent 48732aff16
commit 1d28fc6439
2 changed files with 33 additions and 3 deletions
+15 -3
View File
@@ -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 <<EOF
$(cd "$src_icons" && find . -type f)
EOF
# Refresh the icon cache only when an icon actually changed and the desktop
# has already built a cache (don't create one where there is none).
if $icons_changed && [ -f "$icons/icon-theme.cache" ]; then
if command -v gtk-update-icon-cache >/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
+18
View File
@@ -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"