Added yad dialogues if in GUI session, retains the dialog interface if in console.

This commit is contained in:
Storm Dragon
2025-08-01 15:25:53 -04:00
parent 15f90a7979
commit 76f0c66c96
16 changed files with 392 additions and 113 deletions

View File

@ -36,7 +36,7 @@ install_wine() {
# If this goes wrong, bail out
set -e
{ curl -L --output "${installationFile}" "https://www.playonlinux.com/wine/binaries/phoenicis/upstream-linux-x86/PlayOnLinux-wine-${1}-upstream-linux-${v}.tar.gz"
tar xf "${installationFile}" -C "${wineInstallationPath}"; } | dialog --progressbox "Installing $2 bit Wine version $1." -1 -1
tar xf "${installationFile}" -C "${wineInstallationPath}"; } | agm_progressbox "Wine Installation" "Installing $2 bit Wine version $1."
set +e
}

View File

@ -0,0 +1,281 @@
#!/usr/bin/env bash
# Dialog interface wrapper for audiogame-manager
# Automatically switches between dialog (console) and yad (GUI) based on DISPLAY environment
# This provides better accessibility for GUI environments while maintaining console functionality
# Note: dialogType is now detected in the main script before DISPLAY is modified
# This ensures console detection works correctly when AGM sets DISPLAY=":0"
# If dialogType is not set (e.g., when called from standalone scripts), detect it
if [[ -z "$dialogType" ]]; then
if [[ -z "$DISPLAY" ]]; then
dialogType="dialog"
else
dialogType="yad"
fi
fi
# Wrapper function for menu selection
# Usage: agm_menu "title" "backtitle" "text" option1 "description1" option2 "description2" ...
agm_menu() {
local title="$1"
local backTitle="$2"
local text="$3"
shift 3
if [[ "$dialogType" == "yad" ]]; then
# Build yad list format: Display only, then map back to value
local yadList=""
declare -A valueMap
while [[ $# -gt 0 ]]; do
local option="$1"
local description="$2"
valueMap["$description"]="$option"
if [[ -n "$yadList" ]]; then
yadList="$yadList\n"
fi
yadList="${yadList}${description}"
shift 2
done
local selectedDescription
selectedDescription=$(echo -e "$yadList" | yad --list \
--title="$title" \
--text="$text" \
--column="Option" \
--no-headers \
--selectable-labels \
--search-column=1 \
--height=400 \
--width=600)
# Return the mapped value
if [[ -n "$selectedDescription" ]]; then
echo "${valueMap["$selectedDescription"]}"
fi
else
# Build dialog menu format with mapping (same approach as yad)
local dialogArgs=()
declare -A valueMap
while [[ $# -gt 0 ]]; do
local option="$1"
local description="$2"
valueMap["$description"]="$option"
dialogArgs+=("$description" "$description")
shift 2
done
local selectedDescription
selectedDescription=$(dialog --backtitle "$backTitle" \
--title "$title" \
--no-tags \
--menu "$text" 0 0 0 \
"${dialogArgs[@]}" \
--stdout)
# Return the mapped value
if [[ -n "$selectedDescription" ]]; then
echo "${valueMap["$selectedDescription"]}"
fi
fi
}
# Wrapper function for checklist selection
# Usage: agm_checklist "title" "backtitle" "text" option1 "description1" "status1" option2 "description2" "status2" ...
agm_checklist() {
local title="$1"
local backTitle="$2"
local text="$3"
shift 3
if [[ "$dialogType" == "yad" ]]; then
local yadList=""
while [[ $# -gt 0 ]]; do
local option="$1"
local description="$2"
local status="$3"
local checked="FALSE"
[[ "$status" == "on" ]] && checked="TRUE"
if [[ -n "$yadList" ]]; then
yadList="$yadList\n"
fi
yadList="${yadList}${checked}|${description}|${option}"
shift 3
done
echo -e "$yadList" | yad --list \
--title="$title" \
--text="$text" \
--checklist \
--column="Select:CHK" \
--column="Option" \
--column="Value:HD" \
--hide-column=3 \
--print-column=3 \
--no-headers \
--selectable-labels \
--height=400 \
--width=600 \
--separator=" "
else
local dialogArgs=()
while [[ $# -gt 0 ]]; do
dialogArgs+=("$1" "$2" "$3")
shift 3
done
dialog --backtitle "$backTitle" \
--title "$title" \
--checklist "$text" 0 0 0 \
"${dialogArgs[@]}" \
--stdout
fi
}
# Wrapper function for input dialog
# Usage: agm_inputbox "title" "backtitle" "text" "default_value"
agm_inputbox() {
local title="$1"
local backTitle="$2"
local text="$3"
local defaultValue="$4"
if [[ "$dialogType" == "yad" ]]; then
yad --entry \
--title="$title" \
--text="$text" \
--entry-text="$defaultValue" \
--selectable-labels \
--width=400
else
dialog --backtitle "$backTitle" \
--title "$title" \
--inputbox "$text" 0 0 "$defaultValue" \
--stdout
fi
}
# Wrapper function for message box
# Usage: agm_msgbox "title" "backtitle" "text"
agm_msgbox() {
local title="$1"
local backTitle="$2"
local text="$3"
if [[ "$dialogType" == "yad" ]]; then
yad --info \
--title="$title" \
--text="$text" \
--selectable-labels \
--show-cursor \
--width=400
else
dialog --backtitle "$backTitle" \
--title "$title" \
--msgbox "$text" 0 0
fi
}
# Wrapper function for yes/no dialog
# Usage: agm_yesno "title" "backtitle" "text"
agm_yesno() {
local title="$1"
local backTitle="$2"
local text="$3"
if [[ "$dialogType" == "yad" ]]; then
yad --question \
--title="$title" \
--text="$text" \
--selectable-labels \
--width=400
else
dialog --backtitle "$backTitle" \
--title "$title" \
--yesno "$text" 0 0
fi
}
# Wrapper function for info box (non-blocking message)
# Usage: agm_infobox "title" "backtitle" "text"
agm_infobox() {
local title="$1"
local backTitle="$2"
local text="$3"
if [[ "$dialogType" == "yad" ]]; then
# For yad, we'll use a notification since infobox is non-blocking
yad --notification \
--text="$text" \
--timeout=3
else
dialog --backtitle "$backTitle" \
--title "$title" \
--infobox "$text" 0 0
fi
}
# Wrapper function for progress box
# Usage: command | agm_progressbox "title" "text"
agm_progressbox() {
local title="$1"
local text="$2"
if [[ "$dialogType" == "yad" ]]; then
yad --progress \
--title="$title" \
--text="$text" \
--pulsate \
--auto-close \
--no-buttons \
--show-cursor \
--width=400
else
dialog --title "$title" \
--progressbox "$text" 20 70
fi
}
# Wrapper function for file selection
# Usage: agm_fselect "title" "backtitle" "default_path"
agm_fselect() {
local title="$1"
local backTitle="$2"
local defaultPath="$3"
if [[ "$dialogType" == "yad" ]]; then
yad --file \
--title="$title" \
--filename="$defaultPath" \
--width=600 \
--height=400
else
dialog --backtitle "$backTitle" \
--title "$title" \
--fselect "$defaultPath" 0 0 \
--stdout
fi
}
# Wrapper function for directory selection
# Usage: agm_dselect "title" "backtitle" "default_path"
agm_dselect() {
local title="$1"
local backTitle="$2"
local defaultPath="$3"
if [[ "$dialogType" == "yad" ]]; then
yad --file \
--directory \
--title="$title" \
--filename="$defaultPath" \
--width=600 \
--height=400
else
dialog --backtitle "$backTitle" \
--title "$title" \
--dselect "$defaultPath" 0 0 \
--stdout
fi
}

View File

@ -59,18 +59,15 @@ download() {
{ if ! curl -L4 -C - --retry 10 --output "${cache}/${dest}" "${i}" ; then
echo "Could not download \"$i\"..."
exit 1
fi; } | dialog --backtitle "Audio Game Manager" \
--progressbox "Downloading \"$dest\" from \"$i\"" -1 -1
fi; } | agm_progressbox "Audio Game Manager" "Downloading \"$dest\" from \"$i\""
local downloadError=1
case "${dest##*.}" in
"pk3"|"zip")
unzip -tq "${cache}/${dest}" | dialog --backtitle "Audio Game Manager" \
--progressbox "Validating ${dest##*.} file" -1 -1 --stdout
unzip -tq "${cache}/${dest}" | agm_progressbox "Audio Game Manager" "Validating ${dest##*.} file"
downloadError=$?
;;
"7z")
7z t "${cache}/${dest}" | dialog --backtitle "Audio Game Manager" \
--progressbox "Validating 7z file" -1 -1 --stdout
7z t "${cache}/${dest}" | agm_progressbox "Audio Game Manager" "Validating 7z file"
downloadError=$?
;;
"exe")
@ -95,8 +92,7 @@ download() {
esac
if [[ $downloadError -ne 0 ]]; then
rm -fv "${cache}/${dest}"
dialog --backtitle "Audio Game Manager" \
--infobox "Error downloading \"${dest}\". Installation cannot continue." -1 -1 --stdout
agm_infobox "Audio Game Manager" "Audio Game Manager" "Error downloading \"${dest}\". Installation cannot continue."
alert
exit 1
fi
@ -118,9 +114,7 @@ get_installer() {
if echo "$2" | xclip -selection clipboard 2> /dev/null ; then
message+="\n\nThe URL has been copied to the clipboard."
fi
dialog --ok-label "Continue" \
--backtitle "Audiogame Manager" \
--msgbox "$message" -1 -1
agm_msgbox "Audiogame Manager" "Audiogame Manager" "$message"
# Search the Desktop and Downloads directories for the installation file
for i in ~/Downloads ~/Desktop ; do
find $i -type f -name "$1" -exec cp -v {} "${cache}/" \;
@ -137,26 +131,19 @@ get_steam() {
trap "exit 0" SIGINT
echo "manual intervention required."
alert
dialog --backtitle "Audiogame Manager" \
--yes-label "Continue with Steam" \
--no-label "Install manually" \
--extra-button \
--extra-label "Exit" \
--yesno "To install the game manually, place files in \"${WINEPREFIX}/drive_c/Program Files/${game}\"" -1 -1 --stdout
agm_yesno "Audiogame Manager" "Audiogame Manager" "To install the game manually, place files in \"${WINEPREFIX}/drive_c/Program Files/${game}\". Continue with Steam installation?"
case $? in
0) echo "The next steps will install through steamcmd." ;;
1)
mkdir -p "${WINEPREFIX}/drive_c/Program Files/${game}"
dialog --backtitle "Audiogame Manager" \
--msgbox "Place game files in \"${WINEPREFIX}/drive_c/Program Files/${game}\" and press enter to continue." -1 -1 --stdout
agm_msgbox "Audiogame Manager" "Audiogame Manager" "Place game files in \"${WINEPREFIX}/drive_c/Program Files/${game}\" and press enter to continue."
return
;;
*) exit 0 ;;
esac
# Check for steamcmd
if ! command -v steamcmd &> /dev/null ; then
dialog --backtitle "Audiogame Manager" \
--infobox "This installer requires steamcmd. Please install steamcmd and try again." -1 -1
agm_infobox "Audiogame Manager" "Audiogame Manager" "This installer requires steamcmd. Please install steamcmd and try again."
exit 1
fi
# Create message for dialog.
@ -164,17 +151,12 @@ get_steam() {
if echo "$2" | xclip -selection clipboard 2> /dev/null ; then
message+="\n\nThe URL has been copied to the clipboard."
fi
dialog --ok-label "Continue" \
--backtitle "Audiogame Manager" \
--msgbox "$message" -1 -1
agm_msgbox "Audiogame Manager" "Audiogame Manager" "$message"
# Get Steam user name.
steamUser="$(dialog --ok-label "Continue" \
--backtitle "Audiogame Manager" \
--inputbox "Please enter your Steam user name:" -1 -1 --stdout)"
steamUser="$(agm_inputbox "Audiogame Manager" "Audiogame Manager" "Please enter your Steam user name:" "")"
# Download the game
mkdir -p "${WINEPREFIX}/drive_c/Program Files/${game}"
steamcmd +@sSteamCmdForcePlatformType windows +force_install_dir "${WINEPREFIX}/drive_c/Program Files/$game" +login "$steamUser" +app_update "$1" +quit || { dialog --backtitle "Audiogame Manager" \
--infobox "Something went wrong. Please make sure you have a stable internet connection, and if the problem persists, contact audiogame-manager's developers." -1 -1
steamcmd +@sSteamCmdForcePlatformType windows +force_install_dir "${WINEPREFIX}/drive_c/Program Files/$game" +login "$steamUser" +app_update "$1" +quit || { agm_infobox "Audiogame Manager" "Audiogame Manager" "Something went wrong. Please make sure you have a stable internet connection, and if the problem persists, contact audiogame-manager's developers."
exit 1; }
}

View File

@ -12,10 +12,7 @@ check_news() {
fi
local newsOldTag="$(cat "$newsPath" 2> /dev/null)"
if [[ "$newsTag" != "$newsOldTag" ]]; then
dialog --yes-label 'Play' \
--no-label 'Later' \
--backtitle 'Audiogame Manager News' \
--yesno 'Audiogame manager news is available. Please use left and right arrows to navigate and enter to confirm.' -1 -1 || return
agm_yesno 'Audiogame Manager News' 'Audiogame Manager News' 'Audiogame manager news is available. Would you like to play it now?' || return
sox -qV0 "$newsFile" -d &> /dev/null
echo -n "$newsTag" > "$newsPath"
fi
@ -38,8 +35,7 @@ update() {
if [[ "$home" == "$remote" ]]; then
return
fi
dialog --backtitle "Audiogame Manager" \
--yesno "Updates are available. Would you like to update now?" -1 -1 --stdout || return
agm_yesno "Audiogame Manager" "Audiogame Manager" "Updates are available. Would you like to update now?" || return
{ git pull
git log '@{1}..' --pretty=format:'%an: %s' | tac; }
exit $?