Skip to content
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

Fix e improve --launcher option and related functions #1139

Merged
merged 5 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
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
52 changes: 28 additions & 24 deletions APP-MANAGER
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

AMVERSION="9.1.1-4"
AMVERSION="9.1.1-6"

# Determine main repository and branch
AMREPO="https://raw.githubusercontent.com/ivan-hc/AM/main"
Expand Down Expand Up @@ -612,34 +612,38 @@ function _clean_all_tmp_directories_from_appspath() {
done
}

function _clean_determine_removable_launchers() {
if ! test -f "$APPIMAGENAME" 2>/dev/null; then
if ! test -d "$MOUNTPOINTS" 2>/dev/null; then
if echo "$MOUNTPOINTS" | grep -q "/media/"; then
unmounted_poin="/media"
elif echo "$MOUNTPOINTS" | grep -q "/mnt/"; then
unmounted_poin="/mnt"
fi
echo " ✖ ERROR: cannot remove \"$(basename "$var")\""
echo " related AppImage is located in an unmounted path of $unmounted_poin"
else
rm -f "$var"
rm -f "$HOME"/.local/bin/"$launcher2del"*
cd "$HOME"/.local/bin && find . -xtype l -delete
fi
fi
}

function _clean_launchers() {
if test -d "$DATADIR"/applications/AppImages 2>/dev/null; then
if test -d "$DATADIR"/applications/AppImages; then
for var in "$DATADIR"/applications/AppImages/*.desktop; do
APPIMAGENAME=$(grep "Exec=" 0<"$var" 2>/dev/null | head -1 | cut -c 6- | sed 's/\s.*$//')
launcher2del=$(basename -- "$(echo "$APPIMAGENAME" | tr '[:upper:]' '[:lower:]')")
MOUNTPOINTS=$(echo "$APPIMAGENAME" | cut -d'/' -f1-4)
_clean_determine_removable_launchers
# full path to appimage
appimagename=$(grep "Exec=" 0<"$var" 2>/dev/null | head -1 | cut -c 6- | sed 's/\s.*$//')
# name of the appimage
launcher2del=$(basename -- "$(echo "$appimagename" | tr '[:upper:]' '[:lower:]')")
# removable mount point where the appimage may be stored
mountpoint=$(echo "$appimagename" | cut -d'/' -f1-4)
if ! test -f "$appimagename"; then
if echo "$mountpoint" | grep -q "^/media/\|^/mnt/\|^/run/media/" && ! test -d "$mountpoint"; then
if echo "$mountpoint" | grep -q "^/media/"; then
unmounted_point="/media"
elif echo "$mountpoint" | grep -q "^/mnt/"; then
unmounted_point="/mnt"
elif echo "$mountpoint" | grep -q "^/run/media/"; then
unmounted_point="/run/media"
fi
echo " ✖ ERROR: cannot remove \"$(basename "$var")\""
echo " related AppImage is located in an unmounted path of $unmounted_point"
else
rm -f "$var"
rm -f "$HOME"/.local/bin/"$launcher2del"*
fi
fi
done
grep -q "^Exec=/media/\|^^Exec=/mnt/\|^^Exec=/run/media/" "$DATADIR"/applications/AppImages/* && mountpoint_enabled=1
[ -z "$mountpoint_enabled" ] && cd "$HOME"/.local/bin && find . -xtype l -delete
echo ' ✔ Removed orphaned launchers produced with the "--launcher" option'
rmdir "$DATADIR"/applications/AppImages
else
cd "$HOME"/.local/bin && find . -xtype l -delete
fi
}

Expand Down
6 changes: 5 additions & 1 deletion modules/management.am
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,11 @@ function _launcher_appimage_integration() {

function _launcher_appimage_bin() {
mkdir -p "$HOME"/.local/bin
_check_if_home_local_bin_is_not_in_path
if ! echo "$PATH" | grep "$BINDIR" >/dev/null 2>&1; then
echo "$DIVIDING_LINE"
echo "WARNING: \"$BINDIR\" is not in PATH, apps may not run from command line." | fold -sw 77 | sed 's/^/ /g'
echo "$DIVIDING_LINE"
fi
read -r -p " Write a custom command to launch the app, or leave blank: " response
if [ -z "$response" ]; then
appimage_cmd=$(echo "$appimage" | tr '[:upper:]' '[:lower:]')
Expand Down