Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

fix(linux): install the AppImage menu entry when AppImageLauncher skips it (#5551)

nrq6993-a11y9a905959ed7b
diff --git a/packaging/linux/AppRun b/packaging/linux/AppRun
index f04c5f4ea..43d0eeef7 100755
--- a/packaging/linux/AppRun
+++ b/packaging/linux/AppRun
@@ -35,25 +35,24 @@ integrate() {
src_desktop="$APPDIR/usr/share/applications/$DESK_ID.desktop"
[ -f "$src_desktop" ] || return 0
- # If an external AppImage integrator (AppImageLauncher, appimaged, Gear Lever) is
- # already managing this AppImage, do not write a second launcher (#3623); remove our
- # own if left over from an earlier run, and still install the hicolor icons below.
+ # If another integrator already registered a .desktop whose Exec points at this
+ # AppImage, do not write a second launcher (#3623); remove our own if one is left
+ # over, and still install the hicolor icons below. $DESKTOPINTEGRATION is not that
+ # signal: PhotoCraft sets X-AppImage-Integrate=false, so AppImageLauncher skips the
+ # AppImage and still exports the variable on its binfmt bypass. Treating it as
+ # "already integrated" left the menu with no entry (#5534).
apps="$data/applications"
mkdir -p "$apps" 2>/dev/null || return 0
external=0
- if [ -n "${DESKTOPINTEGRATION:-}" ]; then
- external=1
- else
- for f in "$apps"/*.desktop; do
- if [ ! -f "$f" ] || [ "$f" = "$apps/$DESK_ID.desktop" ]; then
- continue
- fi
- if grep '^Exec=' "$f" 2>/dev/null | grep -Fq "$appimage"; then
- external=1
- break
- fi
- done
- fi
+ for f in "$apps"/*.desktop; do
+ if [ ! -f "$f" ] || [ "$f" = "$apps/$DESK_ID.desktop" ]; then
+ continue
+ fi
+ if grep '^Exec=' "$f" 2>/dev/null | grep -Fq "$appimage"; then
+ external=1
+ break
+ fi
+ done
if [ "$external" = 1 ]; then
if [ -f "$apps/$DESK_ID.desktop" ]; then
rm -f "$apps/$DESK_ID.desktop" 2>/dev/null || true
diff --git a/packaging/linux/apprun-test.sh b/packaging/linux/apprun-test.sh
index 475fb5ee5..8c9e33e6b 100755
--- a/packaging/linux/apprun-test.sh
+++ b/packaging/linux/apprun-test.sh
@@ -83,11 +83,27 @@ printf '[Desktop Entry]\nType=Application\nName=PhotoCraft\nExec="%s" %%F\nIcon=
[ -f "$XDG_DATA_HOME/icons/hicolor/256x256/apps/$APP_ID.png" ] || fail "icons missing with external integrator"
rm -f "$ext_desktop"
-# 7. DESKTOPINTEGRATION set by an external integrator skips creating a second .desktop entry.
+# 7. AppImageLauncher exports DESKTOPINTEGRATION even after X-AppImage-Integrate=false
+# made it skip the AppImage. That is not an existing launcher, so AppRun still
+# writes its own entry and a later launch must not delete it (#5534).
rm -rf "$XDG_DATA_HOME"
DESKTOPINTEGRATION=AppImageLauncher "$APPDIR/AppRun" >/dev/null || fail "DESKTOPINTEGRATION launch exited non-zero"
-[ ! -e "$DESKTOP" ] || fail "DESKTOPINTEGRATION still wrote duplicate desktop entry"
+[ -f "$DESKTOP" ] || fail "DESKTOPINTEGRATION suppressed the desktop entry (#5534)"
+grep -Fxq "Exec=\"$(readlink -f "$APPIMAGE")\" %F" "$DESKTOP" || fail "Exec missing under DESKTOPINTEGRATION"
+grep -Fxq "X-AppImage-Integrate=false" "$DESKTOP" || fail "X-AppImage-Integrate=false missing under DESKTOPINTEGRATION"
[ -f "$XDG_DATA_HOME/icons/hicolor/256x256/apps/$APP_ID.png" ] || fail "icons not installed under DESKTOPINTEGRATION"
+before="$(stat -c %i "$DESKTOP")"
+DESKTOPINTEGRATION=AppImageLauncher "$APPDIR/AppRun" >/dev/null || fail "second DESKTOPINTEGRATION launch exited non-zero"
+[ -f "$DESKTOP" ] || fail "DESKTOPINTEGRATION removed the desktop entry on a later launch"
+[ "$before" = "$(stat -c %i "$DESKTOP")" ] || fail "desktop entry rewritten under DESKTOPINTEGRATION although unchanged"
+# A real integrator entry still wins, including when DESKTOPINTEGRATION is also set (#3623).
+ext_desktop="$XDG_DATA_HOME/applications/appimagekit-photocraft.desktop"
+printf '[Desktop Entry]\nType=Application\nName=PhotoCraft\nExec="%s" %%F\nIcon=%s\n' "$(readlink -f "$APPIMAGE")" "$APP_ID" >"$ext_desktop"
+DESKTOPINTEGRATION=AppImageLauncher "$APPDIR/AppRun" >/dev/null || fail "launch with integrator entry and DESKTOPINTEGRATION exited non-zero"
+[ ! -e "$DESKTOP" ] || fail "duplicate desktop entry kept when an integrator entry exists"
+[ -f "$ext_desktop" ] || fail "external integrator desktop entry removed"
+[ -f "$XDG_DATA_HOME/icons/hicolor/256x256/apps/$APP_ID.png" ] || fail "icons missing when DESKTOPINTEGRATION and an integrator entry coexist"
+rm -f "$ext_desktop"
# 8. Opt-out installs nothing.
rm -rf "$XDG_DATA_HOME"