From fce55c315ae4f9fdb1b48a889c723db86232d66d Mon Sep 17 00:00:00 2001 From: NK2552003 Date: Thu, 19 Nov 2026 06:55:52 +0530 Subject: [PATCH 1/2] packaging(linux): refresh Hicolor icon cache in AppRun and support gtk4-update-icon-cache --- packaging/linux/AppRun | 33 ++++++++++++++++++++---- packaging/linux/apprun-test.sh | 47 +++++++++++++++++++++++++++++++++- packaging/linux/postinst.sh | 2 ++ 3 files changed, 76 insertions(+), 6 deletions(-) diff --git a/packaging/linux/AppRun b/packaging/linux/AppRun index f32928930..fe6a6c3bf 100755 --- a/packaging/linux/AppRun +++ b/packaging/linux/AppRun @@ -17,6 +17,15 @@ set -u APPDIR="$(dirname "$(readlink -f "$0")")" DESK_ID=ai.storyteller.figcraft +refresh_icon_cache() { + if command -v gtk-update-icon-cache >/dev/null 2>&1; then + # A per-user hicolor directory need not have index.theme; -t permits that. + gtk-update-icon-cache -f -t "$1" >/dev/null 2>&1 || true + elif command -v gtk4-update-icon-cache >/dev/null 2>&1; then + gtk4-update-icon-cache -f -t "$1" >/dev/null 2>&1 || true + fi +} + integrate() { case "${FIGCRAFT_NO_DESKTOP_INTEGRATION:-}" in 1 | true | yes) return 0 ;; @@ -63,12 +72,26 @@ integrate() { 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 - 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 + (cd "$src_icons" && find . -type f) | { + 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 + if cp "$src_icons/$rel" "$icons/$rel" 2>/dev/null; then + changed=true + fi + fi + done + cache="$icons/icon-theme.cache" + if [ "$changed" = false ] && [ -f "$cache" ]; then + if [ -n "$(find "$icons" -type f -name "$DESK_ID.*" -newer "$cache" 2>/dev/null)" ]; then + changed=true + fi fi - done + if [ "$changed" = true ]; then + refresh_icon_cache "$icons" + fi + } } # The CLI is headless and its stdout may be a protocol stream (`cli mcp`): no diff --git a/packaging/linux/apprun-test.sh b/packaging/linux/apprun-test.sh index 75625480b..ac6d9f494 100755 --- a/packaging/linux/apprun-test.sh +++ b/packaging/linux/apprun-test.sh @@ -29,6 +29,27 @@ export APPIMAGE export HOME="$TMP/home" export XDG_DATA_HOME="$HOME/.local/share" mkdir -p "$HOME" +unset FIGCRAFT_NO_DESKTOP_INTEGRATION + +# Record icon-cache refreshes without requiring a desktop session or GTK install. +export REAL_CACHE_UPDATER +REAL_CACHE_UPDATER="$(command -v gtk-update-icon-cache || true)" +mkdir -p "$TMP/tools" +cat >"$TMP/tools/gtk-update-icon-cache" <<'EOF' +#!/bin/sh +printf '%s\n' "$*" >>"$CACHE_CALLS" +if [ "${CACHE_UPDATER_FAIL:-0}" = 1 ]; then + exit 1 +fi +if [ -n "$REAL_CACHE_UPDATER" ]; then + "$REAL_CACHE_UPDATER" "$@" +else + for dir do :; done + : >"$dir/icon-theme.cache" +fi +EOF +chmod +x "$TMP/tools/gtk-update-icon-cache" +export PATH="$TMP/tools:$PATH" CACHE_CALLS="$TMP/cache-calls" fail() { echo "FAIL: $*" >&2 @@ -53,10 +74,16 @@ if command -v desktop-file-validate >/dev/null; then desktop-file-validate "$DESKTOP" || fail "generated desktop entry is invalid" fi -# 3. Icons landed under the name the .desktop entry references. +# 3. Icons landed under the name the .desktop entry references and refreshed the cache. for f in "16x16/apps/$APP_ID.png" "256x256/apps/$APP_ID.png" "scalable/apps/$APP_ID.svg"; do [[ -f "$XDG_DATA_HOME/icons/hicolor/$f" ]] || fail "icon missing: $f" done +[[ -f "$CACHE_CALLS" ]] || fail "installed icons did not refresh the icon cache" +[[ "$(wc -l <"$CACHE_CALLS")" -eq 1 ]] || fail "icon cache refreshed more than once" +grep -Fxq -- "-f -t $XDG_DATA_HOME/icons/hicolor" "$CACHE_CALLS" || fail "wrong icon cache arguments" +if [[ -n "$REAL_CACHE_UPDATER" ]]; then + [[ -f "$XDG_DATA_HOME/icons/hicolor/icon-theme.cache" ]] || fail "GTK did not build the icon cache" +fi # 4. Idempotent: a second launch must not rewrite anything (inode unchanged). before="$(stat -c %i "$DESKTOP")" @@ -64,6 +91,7 @@ out="$("$APPDIR/AppRun")" || fail "second launch exited non-zero" [[ "$out" = "stub: " ]] || fail "second launch output: $out" after="$(stat -c %i "$DESKTOP")" [[ "$before" = "$after" ]] || fail "desktop entry rewritten although unchanged" +[[ "$(wc -l <"$CACHE_CALLS")" -eq 1 ]] || fail "unchanged icons refreshed the cache" # 5. Moving the AppImage refreshes Exec. mv "$APPIMAGE" "$TMP/moved.AppImage" @@ -110,4 +138,21 @@ out="$("$APPDIR/AppRun" cli)" || fail "bare cli launch exited non-zero" out="$("$APPDIR/AppRun" file.figcraft cli)" || fail "app launch with a later cli argument exited non-zero" [[ "$out" = "stub: file.figcraft cli" ]] || fail "later cli argument hijacked the launch: $out" +# 11. Pre-existing stale Hicolor cache is rebuilt even when icon bytes are unchanged, +# and a subsequent launch does not rebuild again. +rm -rf "$XDG_DATA_HOME" "$CACHE_CALLS" +"$APPDIR/AppRun" >/dev/null || fail "setup launch for stale-cache test exited non-zero" +touch -t 202001010000 "$XDG_DATA_HOME/icons/hicolor/icon-theme.cache" +: >"$CACHE_CALLS" +"$APPDIR/AppRun" >/dev/null || fail "stale-cache repair launch exited non-zero" +[[ "$(wc -l <"$CACHE_CALLS")" -eq 1 ]] || fail "stale icon-theme.cache was not refreshed" +grep -Fxq -- "-f -t $XDG_DATA_HOME/icons/hicolor" "$CACHE_CALLS" || fail "wrong stale-cache refresh arguments" +"$APPDIR/AppRun" >/dev/null || fail "post-repair launch exited non-zero" +[[ "$(wc -l <"$CACHE_CALLS")" -eq 1 ]] || fail "repaired icon-theme.cache refreshed again" + +# 12. A failing icon-cache updater never blocks the launch. +rm -rf "$XDG_DATA_HOME" "$CACHE_CALLS" +out="$(CACHE_UPDATER_FAIL=1 "$APPDIR/AppRun" ok)" || fail "failing icon-cache updater blocked launch" +[[ "$out" = "stub: ok" ]] || fail "failing icon-cache updater altered launch output: $out" + echo "AppRun desktop integration ok" diff --git a/packaging/linux/postinst.sh b/packaging/linux/postinst.sh index 775e4df91..567d63c27 100755 --- a/packaging/linux/postinst.sh +++ b/packaging/linux/postinst.sh @@ -9,5 +9,7 @@ if command -v update-mime-database >/dev/null 2>&1; then fi if command -v gtk-update-icon-cache >/dev/null 2>&1; then gtk-update-icon-cache -q -t -f /usr/share/icons/hicolor || true +elif command -v gtk4-update-icon-cache >/dev/null 2>&1; then + gtk4-update-icon-cache -q -t -f /usr/share/icons/hicolor || true fi exit 0 From ef957a61c818b98d7118873b05a20986945e89c7 Mon Sep 17 00:00:00 2001 From: NK2552003 Date: Thu, 19 Nov 2026 07:10:24 +0530 Subject: [PATCH 2/2] packaging(linux): add GTK 4-only icon-cache fallback test for AppRun and postinst.sh --- packaging/linux/apprun-test.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/packaging/linux/apprun-test.sh b/packaging/linux/apprun-test.sh index ac6d9f494..b4861afaa 100755 --- a/packaging/linux/apprun-test.sh +++ b/packaging/linux/apprun-test.sh @@ -155,4 +155,29 @@ rm -rf "$XDG_DATA_HOME" "$CACHE_CALLS" out="$(CACHE_UPDATER_FAIL=1 "$APPDIR/AppRun" ok)" || fail "failing icon-cache updater blocked launch" [[ "$out" = "stub: ok" ]] || fail "failing icon-cache updater altered launch output: $out" +# 13. GTK 4-only fallback: when gtk-update-icon-cache is unavailable, both AppRun +# and postinst.sh invoke gtk4-update-icon-cache with the expected arguments. +GTK4_BIN="$TMP/gtk4-only" +GTK4_CALLS="$TMP/gtk4-calls" +mkdir -p "$GTK4_BIN" +for cmd in dirname readlink mkdir sed cmp rm mv find cp; do + ln -s "$(command -v "$cmd")" "$GTK4_BIN/$cmd" +done +cat >"$GTK4_BIN/gtk4-update-icon-cache" <<'EOF' +#!/bin/sh +printf 'gtk4-update-icon-cache %s\n' "$*" >>"$GTK4_CALLS" +EOF +chmod +x "$GTK4_BIN/gtk4-update-icon-cache" + +rm -rf "$XDG_DATA_HOME" "$GTK4_CALLS" +out="$(PATH="$GTK4_BIN" GTK4_CALLS="$GTK4_CALLS" "$APPDIR/AppRun" gtk4)" || fail "GTK 4-only AppRun launch failed" +[[ "$out" = "stub: gtk4" ]] || fail "GTK 4-only AppRun altered launch output: $out" +[[ "$(wc -l <"$GTK4_CALLS")" -eq 1 ]] || fail "GTK 4-only AppRun did not invoke gtk4-update-icon-cache once" +grep -Fxq -- "gtk4-update-icon-cache -f -t $XDG_DATA_HOME/icons/hicolor" "$GTK4_CALLS" || fail "wrong GTK 4 AppRun arguments" + +: >"$GTK4_CALLS" +PATH="$GTK4_BIN" GTK4_CALLS="$GTK4_CALLS" "$HERE/postinst.sh" || fail "GTK 4-only postinst.sh failed" +[[ "$(wc -l <"$GTK4_CALLS")" -eq 1 ]] || fail "GTK 4-only postinst.sh did not invoke gtk4-update-icon-cache once" +grep -Fxq -- "gtk4-update-icon-cache -q -t -f /usr/share/icons/hicolor" "$GTK4_CALLS" || fail "wrong GTK 4 postinst.sh arguments" + echo "AppRun desktop integration ok"