PhotoCraft: An open-source, photo editor written by scratch in pure Rust
fix(linux): avoid duplicate AppImage desktop launcher (#3623) (#3641)
Korg1chdc35ce763009
diff --git a/packaging/linux/AppRun b/packaging/linux/AppRunindex e8543ee2b..42008b177 100755--- a/packaging/linux/AppRun+++ b/packaging/linux/AppRun@@ -35,25 +35,47 @@ integrate() {src_desktop="$APPDIR/usr/share/applications/$DESK_ID.desktop"[ -f "$src_desktop" ] || return 0- # Rewrite Exec to this AppImage (the binary is not on the host PATH) and drop- # TryExec, which would hide the entry; everything else is shipped as packaged.+ # 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.apps="$data/applications"mkdir -p "$apps" 2>/dev/null || return 0- tmp="$apps/.$DESK_ID.tmp.$$"- esc="$(printf '%s' "$appimage" | sed 's/[\\&|]/\\&/g')"- if sed -e "s|^Exec=.*|Exec=\"$esc\" %F|" -e '/^TryExec=/d' "$src_desktop" 2>/dev/null >"$tmp"; then- if cmp -s "$tmp" "$apps/$DESK_ID.desktop"; then- rm -f "$tmp"- else- if mv -f "$tmp" "$apps/$DESK_ID.desktop" 2>/dev/null; then- command -v update-desktop-database >/dev/null 2>&1 && update-desktop-database "$apps" >/dev/null 2>&1- else- rm -f "$tmp"+ external=0+ if [ -n "${DESKTOPINTEGRATION:-}" ]; then+ external=1+ else+ for f in "$apps"/*.desktop; do+ [ -f "$f" ] && [ "$f" != "$apps/$DESK_ID.desktop" ] || continue+ if grep '^Exec=' "$f" 2>/dev/null | grep -Fq "$appimage"; then+ external=1+ breakfi+ done+ fi+ if [ "$external" = 1 ]; then+ if [ -f "$apps/$DESK_ID.desktop" ]; then+ rm -f "$apps/$DESK_ID.desktop" 2>/dev/null || true+ command -v update-desktop-database >/dev/null 2>&1 && update-desktop-database "$apps" >/dev/null 2>&1fielse- rm -f "$tmp"- return 0+ # Rewrite Exec to this AppImage (the binary is not on the host PATH) and drop+ # TryExec, which would hide the entry; everything else is shipped as packaged.+ tmp="$apps/.$DESK_ID.tmp.$$"+ esc="$(printf '%s' "$appimage" | sed 's/[\\&|]/\\&/g')"+ if sed -e "s|^Exec=.*|Exec=\"$esc\" %F|" -e '/^TryExec=/d' "$src_desktop" 2>/dev/null >"$tmp"; then+ if cmp -s "$tmp" "$apps/$DESK_ID.desktop"; then+ rm -f "$tmp"+ else+ if mv -f "$tmp" "$apps/$DESK_ID.desktop" 2>/dev/null; then+ command -v update-desktop-database >/dev/null 2>&1 && update-desktop-database "$apps" >/dev/null 2>&1+ else+ rm -f "$tmp"+ fi+ fi+ else+ rm -f "$tmp"+ return 0+ fifi# Icons: per-file compare so an unchanged install costs a handful of cmp calls.diff --git a/packaging/linux/ai.storyteller.photocraft.desktop b/packaging/linux/ai.storyteller.photocraft.desktopindex 70ce82148..a32b55cef 100644--- a/packaging/linux/ai.storyteller.photocraft.desktop+++ b/packaging/linux/ai.storyteller.photocraft.desktop@@ -13,3 +13,6 @@ StartupWMClass=ai.storyteller.photocraftCategories=Graphics;2DGraphics;RasterGraphics;Photography;Keywords=photo;image;editor;psd;layers;retouch;paint;MimeType=application/x-photocraft;image/x-paintnet;image/openraster;image/vnd.adobe.photoshop;image/x-psd;image/x-psb;image/png;image/jpeg;image/tiff;image/webp;image/gif;image/bmp;image/x-tga;image/x-icon;image/vnd.microsoft.icon;image/x-portable-anymap;image/x-portable-bitmap;image/x-portable-graymap;image/x-portable-pixmap;image/x-exr;image/vnd.radiance;image/avif;image/qoi;+# AppRun registers the desktop entry and icons itself (#593); tell external+# AppImage integrators (AppImageLauncher, appimaged) not to add a duplicate (#3623).+X-AppImage-Integrate=falsediff --git a/packaging/linux/apprun-test.sh b/packaging/linux/apprun-test.shindex 0c81a0405..475fb5ee5 100755--- a/packaging/linux/apprun-test.sh+++ b/packaging/linux/apprun-test.sh@@ -48,6 +48,7 @@ expected_exec="Exec=\"$(readlink -f "$APPIMAGE")\" %F"grep -Fxq "$expected_exec" "$DESKTOP" || fail "Exec not rewritten: $(grep '^Exec=' "$DESKTOP")"grep -q '^TryExec=' "$DESKTOP" && fail "TryExec kept, the entry would be hidden"grep -Fxq "Icon=$APP_ID" "$DESKTOP" || fail "Icon line lost"+grep -Fxq "X-AppImage-Integrate=false" "$DESKTOP" || fail "X-AppImage-Integrate=false missing (#3623)"grep -Fxq 'Categories=Graphics;2DGraphics;RasterGraphics;Photography;' "$DESKTOP" || fail "metadata lines lost"if command -v desktop-file-validate >/dev/null; thendesktop-file-validate "$DESKTOP" || fail "generated desktop entry is invalid"@@ -71,23 +72,40 @@ export APPIMAGE="$TMP/moved.AppImage""$APPDIR/AppRun" >/dev/null || fail "launch after move exited non-zero"grep -Fxq "Exec=\"$(readlink -f "$APPIMAGE")\" %F" "$DESKTOP" || fail "Exec not refreshed after move"-# 6. Opt-out installs nothing.+# 6. External AppImage integrator (#3623): if another .desktop file in $XDG_DATA_HOME/applications+# already launches this AppImage (e.g. AppImageLauncher's appimagekit-*.desktop), AppRun removes+# its own duplicate .desktop entry while keeping the hicolor icons installed.+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"+"$APPDIR/AppRun" >/dev/null || fail "launch with external integrator desktop entry exited non-zero"+[ ! -e "$DESKTOP" ] || fail "duplicate desktop entry kept alongside external integrator entry"+[ -f "$ext_desktop" ] || fail "external integrator desktop entry removed"+[ -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.+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 "$XDG_DATA_HOME/icons/hicolor/256x256/apps/$APP_ID.png" ] || fail "icons not installed under DESKTOPINTEGRATION"++# 8. Opt-out installs nothing.rm -rf "$XDG_DATA_HOME"PHOTOCRAFT_NO_DESKTOP_INTEGRATION=1 "$APPDIR/AppRun" >/dev/null || fail "opt-out launch exited non-zero"[ ! -e "$XDG_DATA_HOME" ] || fail "opt-out still integrated"-# 7. An unwritable data dir never blocks the launch.+# 9. An unwritable data dir never blocks the launch.mkdir -p "$TMP/ro" && chmod a-w "$TMP/ro"out="$(XDG_DATA_HOME="$TMP/ro/data" "$APPDIR/AppRun" out.txt)" || fail "launch blocked by unwritable data dir"[ "$out" = "stub: out.txt" ] || fail "stub not run against unwritable data dir: $out"chmod u+w "$TMP/ro"-# 8. No $APPIMAGE (extracted AppDir): launch only, nothing installed.+# 10. No $APPIMAGE (extracted AppDir): launch only, nothing installed.rm -rf "$XDG_DATA_HOME"env -u APPIMAGE "$APPDIR/AppRun" >/dev/null || fail "extracted-AppDir launch exited non-zero"[ ! -e "$XDG_DATA_HOME" ] || fail "integrated without $APPIMAGE"-# 9. A path that would need Exec escaping (here a `$`): launch only, nothing installed.+# 11. A path that would need Exec escaping (here a `$`): launch only, nothing installed.rm -rf "$XDG_DATA_HOME"odd="$TMP/odd\$(id).AppImage": >"$odd"