Skip to content

Fix for #11 #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 57 additions & 10 deletions linuxdeploy-plugin-gtk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ search_tool() {
local tool="$1"
local directory="$2"

if command -v "$tool" > /dev/null; then
echo "$tool"
if command -v "$tool"; then
return 0
fi

Expand All @@ -48,9 +47,6 @@ search_tool() {
return 0
fi
done

echo "$0: $tool not found, aborting" > /dev/stderr
{ exit 1; }
}

APPDIR=
Expand Down Expand Up @@ -117,6 +113,9 @@ APPIMAGE_GTK_THEME="${APPIMAGE_GTK_THEME:-"Adwaita:$GTK_THEME_VARIANT"}" # Allow
CACHEDIR="$(mktemp --tmpdir --directory .AppRun.XXXXXXXX)"

export APPDIR="${APPDIR:-"$(dirname "$(realpath "$0")")"}" # Workaround to run extracted AppImage
export OLDPATH="$PATH"
export PATH="$APPDIR/usr/bin:$PATH"

export GTK_DATA_PREFIX="$APPDIR"
export GTK_THEME="$APPIMAGE_GTK_THEME" # Custom themes are broken
export GDK_BACKEND=x11 # Crash with Wayland backend on Wayland
Expand Down Expand Up @@ -151,10 +150,10 @@ if [ -x "$gtk3_immodules_query" ]; then
echo "Updating immodules cache in $APPDIR/$gtk3_immodules_cache_file"
"$gtk3_immodules_query" > "$APPDIR/$gtk3_immodules_cache_file"
else
echo "Warning: gtk-query-immodules-3.0 not found"
echo "WARNING: gtk-query-immodules-3.0 not found"
fi
if [ ! -f "$APPDIR/$gtk3_immodules_cache_file" ]; then
echo "Warning: immodules.cache file is missing"
echo "WARNING: immodules.cache file is missing"
fi

echo "Installing GDK PixBufs"
Expand All @@ -168,17 +167,16 @@ copy_tree "$gdk_pixbuf_binarydir" "$APPDIR/"
cat >> "$HOOKFILE" <<EOF
export GDK_PIXBUF_MODULEDIR="\$APPDIR/$gdk_pixbuf_moduledir"
export GDK_PIXBUF_MODULE_FILE="\$CACHEDIR/loaders.cache"
export LD_LIBRARY_PATH="\$GDK_PIXBUF_MODULEDIR:\$LD_LIBRARY_PATH"
sed "s|$gdk_pixbuf_moduledir|\$APPDIR/$gdk_pixbuf_moduledir|g" "\$APPDIR/$gdk_pixbuf_cache_file" > "\$GDK_PIXBUF_MODULE_FILE"
EOF
if [ -x "$gdk_pixbuf_query" ]; then
echo "Updating pixbuf cache in $APPDIR/$gdk_pixbuf_cache_file"
"$gdk_pixbuf_query" > "$APPDIR/$gdk_pixbuf_cache_file"
else
echo "Warning: gdk-pixbuf-query-loaders not found"
echo "WARNING: gdk-pixbuf-query-loaders not found"
fi
if [ ! -f "$APPDIR/$gdk_pixbuf_cache_file" ]; then
echo "Warning: loaders.cache file is missing"
echo "WARNING: loaders.cache file is missing"
fi

echo "Copying more libraries"
Expand Down Expand Up @@ -213,3 +211,52 @@ for directory in "${PATCH_ARRAY[@]}"; do
patchelf --set-rpath '$ORIGIN/../../../..' "$APPDIR/$file"
done < <(find "$directory" -name '*.so' -print0)
done

echo "Add a wrapper for some binaries"
# Note: some files on system must not be started with overrides above
# See https://github.com/linuxdeploy/linuxdeploy-plugin-gtk/issues/11#issuecomment-761788064
BINDIR="$APPDIR/usr/bin"
EOAFILE="$BINDIR/exec-outside-appimage"
mkdir -p "$BINDIR"
cat > "$EOAFILE" <<\EOF
#! /bin/bash

export PATH="$OLDPATH"

unset OLDPATH
unset GTK_DATA_PREFIX
unset GTK_THEME
unset GDK_BACKEND
unset XDG_DATA_DIRS
unset GSETTINGS_SCHEMA_DIR
unset GTK_EXE_PREFIX
unset GTK_PATH
unset GTK_IM_MODULE_DIR
unset GTK_IM_MODULE_FILE
unset GDK_PIXBUF_MODULEDIR
unset GDK_PIXBUF_MODULE_FILE

# Enter 'if' when '$0' is 'exec-outside-appimage' script itself
# Symbolic links to 'exec-outside-appimage' should not enter in 'if'
app="$(basename "$0")"
if ! command -v "$app" &> /dev/null; then
app="$1"
shift
if [ -z "$app" ]; then
echo "$0: this script requires a command as argument"
exit 1
elif ! command -v "$app" &> /dev/null; then
echo "'$app' not found in PATH ($PATH)"
exit 1
fi
fi
"$app" "$@"
EOF
chmod $verbose 755 "$EOAFILE"
EOA_ARRAY=(
"xdg-open"
"eog"
)
for file in "${EOA_ARRAY[@]}"; do
ln $verbose -s "$(basename "$EOAFILE")" "$BINDIR/$file"
done