More improvements to ui dialogs.
This commit is contained in:
@ -183,14 +183,102 @@ ui_progressbox() {
|
||||
local text="$2"
|
||||
|
||||
if [[ "$dialog_type" == "yad" ]]; then
|
||||
# Start audio feedback for accessibility
|
||||
local beep_pid
|
||||
local yad_pid
|
||||
|
||||
# Cleanup function for traps
|
||||
cleanup_progress() {
|
||||
[[ -n "$beep_pid" ]] && kill "$beep_pid" 2>/dev/null
|
||||
[[ -n "$yad_pid" ]] && kill "$yad_pid" 2>/dev/null
|
||||
}
|
||||
|
||||
# Set trap to ensure cleanup on interruption
|
||||
trap cleanup_progress EXIT INT TERM
|
||||
|
||||
if command -v sox >/dev/null 2>&1; then
|
||||
{
|
||||
while true; do
|
||||
# Generate a short, pleasant progress beep (440Hz for 0.1s)
|
||||
sox -q -n -d synth 0.1 sine 440 vol 0.3 2>/dev/null
|
||||
sleep 2 # Beep every 2 seconds
|
||||
done
|
||||
} &
|
||||
beep_pid=$!
|
||||
fi
|
||||
|
||||
# Start visual progress dialog with auto-close
|
||||
yad --progress \
|
||||
--title="$title" \
|
||||
--text="$text" \
|
||||
--pulsate \
|
||||
--auto-close \
|
||||
--no-buttons \
|
||||
--show-cursor \
|
||||
--width=400
|
||||
--pulsate \
|
||||
--width=400 \
|
||||
--height=100 &
|
||||
yad_pid=$!
|
||||
|
||||
# Process command output
|
||||
local line_count=0
|
||||
while IFS= read -r line; do
|
||||
((line_count++))
|
||||
done < <(stdbuf -oL cat)
|
||||
|
||||
# Clean up background processes
|
||||
cleanup_progress
|
||||
trap - EXIT INT TERM # Remove traps
|
||||
else
|
||||
dialog --title "$title" \
|
||||
--progressbox "$text" 20 70
|
||||
fi
|
||||
}
|
||||
|
||||
# Simple progress box that just shows the operation is running (no command output)
|
||||
# Usage: command | ui_simple_progressbox "title" "text"
|
||||
ui_simple_progressbox() {
|
||||
local title="$1"
|
||||
local text="$2"
|
||||
|
||||
if [[ "$dialog_type" == "yad" ]]; then
|
||||
# Start audio feedback for accessibility
|
||||
local beep_pid
|
||||
local yad_pid
|
||||
|
||||
# Cleanup function for traps
|
||||
cleanup_simple_progress() {
|
||||
[[ -n "$beep_pid" ]] && kill "$beep_pid" 2>/dev/null
|
||||
[[ -n "$yad_pid" ]] && kill "$yad_pid" 2>/dev/null
|
||||
}
|
||||
|
||||
# Set trap to ensure cleanup on interruption
|
||||
trap cleanup_simple_progress EXIT INT TERM
|
||||
|
||||
if command -v sox >/dev/null 2>&1; then
|
||||
{
|
||||
while true; do
|
||||
# Generate a short, pleasant progress beep (440Hz for 0.1s)
|
||||
sox -q -n -d synth 0.1 sine 440 vol 0.3 2>/dev/null
|
||||
sleep 2 # Beep every 2 seconds
|
||||
done
|
||||
} &
|
||||
beep_pid=$!
|
||||
fi
|
||||
|
||||
# Show progress dialog with pulsating
|
||||
yad --progress \
|
||||
--title="$title" \
|
||||
--text="$text" \
|
||||
--auto-close \
|
||||
--pulsate \
|
||||
--width=400 \
|
||||
--height=100 &
|
||||
yad_pid=$!
|
||||
|
||||
# Read from stdin and discard, but keep dialogs open until command finishes
|
||||
cat > /dev/null
|
||||
|
||||
# Clean up background processes
|
||||
cleanup_simple_progress
|
||||
trap - EXIT INT TERM # Remove traps
|
||||
else
|
||||
dialog --title "$title" \
|
||||
--progressbox "$text" 20 70
|
||||
@ -199,24 +287,46 @@ ui_progressbox() {
|
||||
|
||||
# Check for updates
|
||||
check_update() {
|
||||
local url="$(git ls-remote --get-url)"
|
||||
if [[ "$url" =~ ^[[:alnum:]]+@ ]] || [[ -z "$url" ]]; then
|
||||
if ! [[ -d ".git" ]]; then
|
||||
return
|
||||
fi
|
||||
git remote update > /dev/null 2>&1
|
||||
local url
|
||||
url="$(git ls-remote --get-url)"
|
||||
if [[ "$url" =~ ^ssh://|git@|gitea@ ]] || [[ -z "$url" ]]; then
|
||||
return
|
||||
fi
|
||||
git remote update &> /dev/null
|
||||
local upstream='@{u}'
|
||||
local home="$(git rev-parse @)"
|
||||
local remote="$(git rev-parse "$upstream")"
|
||||
local home
|
||||
local remote
|
||||
home="$(git rev-parse @)"
|
||||
remote="$(git rev-parse "$upstream")"
|
||||
if [[ "$home" == "$remote" ]]; then
|
||||
return
|
||||
fi
|
||||
ui_yesno "Linux Game Manager" "Linux Game manager" "Updates are available. Would you like to update now?" || return
|
||||
# Store the current commit before pulling
|
||||
local beforePull=$(git rev-parse HEAD)
|
||||
git pull
|
||||
# Show changes between the stored commit and current HEAD
|
||||
git log "$beforePull..HEAD" --pretty=format:'%an: %s' | tac
|
||||
exit $?
|
||||
ui_yesno "Linux Game Manager" "Linux Game Manager" "Updates are available. Would you like to update now?" || return
|
||||
|
||||
# Perform git pull quietly, then show only the important changes
|
||||
local update_result
|
||||
git pull --quiet >/dev/null 2>&1
|
||||
update_result=$?
|
||||
|
||||
# Get the important information: commit messages and summary
|
||||
local changes_summary
|
||||
changes_summary=$({
|
||||
echo "UPDATE COMPLETED"
|
||||
echo
|
||||
echo "Recent changes:"
|
||||
git log '@{1}..' --pretty=format:'• %an: %s' | tac
|
||||
echo
|
||||
echo "Update summary:"
|
||||
git diff --stat '@{1}..' | tail -1
|
||||
} 2>/dev/null)
|
||||
|
||||
# Show only the meaningful update information
|
||||
ui_msgbox "Update Complete" "Linux Game Manager" "$changes_summary"
|
||||
|
||||
exit $update_result
|
||||
}
|
||||
|
||||
|
||||
@ -251,11 +361,11 @@ check_dependencies() {
|
||||
if [[ "${#dependencies[@]}" -eq 0 ]]; then
|
||||
return
|
||||
fi
|
||||
echo "missing dependencies. Please install the following:"
|
||||
echo
|
||||
local missing_deps="missing dependencies. Please install the following:\n\n"
|
||||
for i in "${dependencies[@]}" ; do
|
||||
echo "$i"
|
||||
missing_deps+="$i\n"
|
||||
done
|
||||
ui_msgbox "Linux Game Manager" "Linux Game Manager" "$missing_deps"
|
||||
exit 1
|
||||
}
|
||||
|
||||
@ -274,10 +384,11 @@ terminal_emulator() {
|
||||
return
|
||||
fi
|
||||
done
|
||||
echo "No suitable terminal emulators found, please install one of:"
|
||||
local terminal_msg="No suitable terminal emulators found, please install one of:\n\n"
|
||||
for i in "${terminals[@]}" ; do
|
||||
echo "$i"
|
||||
terminal_msg+="$i\n"
|
||||
done
|
||||
ui_msgbox "Linux Game Manager" "Linux Game Manager" "$terminal_msg"
|
||||
}
|
||||
|
||||
# Function to open urls
|
||||
@ -289,7 +400,7 @@ open_url() {
|
||||
desktop_launcher() {
|
||||
local desktopFile="${HOME}/linux-game-manager.desktop"
|
||||
if [[ -e "${desktopFile}" ]]; then
|
||||
echo "the file ${desktopFile} exists. Cannot create the launcher."
|
||||
ui_msgbox "Linux Game Manager" "Linux Game Manager" "The file ${desktopFile} exists. Cannot create the launcher."
|
||||
exit 1
|
||||
fi
|
||||
local dotDesktop
|
||||
@ -324,28 +435,20 @@ desktop_launcher() {
|
||||
# Alerts, for when user needs to read something.
|
||||
alert() {
|
||||
play -qnV0 synth 3 pluck D3 pluck A3 pluck D4 pluck F4 pluck A4 delay 0 .1 .2 .3 .4 remix - chorus 0.9 0.9 38 0.75 0.3 0.5 -t
|
||||
echo
|
||||
read -rp "Press enter to continue." continue
|
||||
ui_msgbox "Linux Game Manager" "Linux Game Manager" "Press OK to continue."
|
||||
}
|
||||
|
||||
clear_cache() {
|
||||
local answer
|
||||
if [[ ! -d "${cache}" ]]; then
|
||||
echo "No cache found at ${cache}."
|
||||
ui_msgbox "Linux Game Manager" "Linux Game Manager" "No cache found at ${cache}."
|
||||
return
|
||||
fi
|
||||
while ! [[ "${answer,,}" =~ ^yes$|^no$ ]]; do
|
||||
echo "This will delete all contents of ${cache}. Are you sure you want to continue?"
|
||||
echo "Please type yes or no."
|
||||
echo
|
||||
read -r answer
|
||||
done
|
||||
if [[ "$answer" == "no" ]]; then
|
||||
if ! ui_yesno "Linux Game Manager" "Linux Game Manager" "This will delete all contents of ${cache}. Are you sure you want to continue?"; then
|
||||
return
|
||||
fi
|
||||
# All safety checks done. Delete the cache.
|
||||
rm -rfv "${cache}"
|
||||
echo "Cache deleted."
|
||||
rm -rfv "${cache}" | ui_progressbox "Linux Game Manager" "Clearing cache..."
|
||||
ui_msgbox "Linux Game Manager" "Linux Game Manager" "Cache deleted."
|
||||
}
|
||||
|
||||
download() {
|
||||
@ -363,7 +466,7 @@ download() {
|
||||
# Skip if the item is in cache.
|
||||
[[ -e "${cache}/${dest}" ]] && continue
|
||||
{ if ! curl -L4 -C - --retry 10 --output "${cache}/${dest}" "${i}" ; then
|
||||
echo "Could not download \"$i\"..."
|
||||
ui_msgbox "Linux Game Manager" "Linux Game Manager" "Could not download \"$i\"..."
|
||||
exit 1
|
||||
fi; } | ui_progressbox "Linux Game Manager" "Downloading \"$dest\" from \"$i\""
|
||||
local downloadError=1
|
||||
@ -416,7 +519,7 @@ download_named() {
|
||||
# Skip if the item is in cache.
|
||||
test -e "${cache}/${dest}" && return
|
||||
if ! curl -L4 --output "${cache}/${dest}" "${2}" ; then
|
||||
echo "Could not download \"$dest\"..."
|
||||
ui_msgbox "Linux Game Manager" "Linux Game Manager" "Could not download \"$dest\"..."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
@ -436,7 +539,6 @@ get_installer() {
|
||||
if echo "$2" | xclip -selection clipboard 2> /dev/null ; then
|
||||
message+="\n\nThe URL has been copied to the clipboard."
|
||||
fi
|
||||
echo "Manual intervention required..."
|
||||
alert
|
||||
ui_msgbox "Linux Game Manager" "Linux Game Manager" "$message"
|
||||
# Search the Desktop and Downloads directories for the installation file
|
||||
@ -445,34 +547,30 @@ get_installer() {
|
||||
done
|
||||
# If the file is still not available abort.
|
||||
if [[ ! -f "${cache}/$1" ]]; then
|
||||
echo "couldn't find $1. Please download the file and try again."
|
||||
ui_msgbox "Linux Game Manager" "Linux Game Manager" "Couldn't find $1. Please download the file and try again."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
help() {
|
||||
echo "${0##*/}"
|
||||
echo "Released under the terms of the Common Public Attribution License Version 1.0"
|
||||
echo -e "This is a Stormux project: https://stormux.org\n"
|
||||
echo -e "Usage:\n"
|
||||
echo "With no arguments, open the game launcher."
|
||||
local help_text="${0##*/}\nReleased under the terms of the Common Public Attribution License Version 1.0\nThis is a Stormux project: https://stormux.org\n\nUsage:\n\nWith no arguments, open the game launcher.\n\n"
|
||||
|
||||
# Add command options
|
||||
for i in "${!command[@]}" ; do
|
||||
echo "-${i/:/ <parameter>}: ${command[${i}]}"
|
||||
done | sort
|
||||
echo
|
||||
echo "Some settings that are often used can be stored in a settings.conf file."
|
||||
echo "If wanted, place it at the following location:"
|
||||
echo "${configFile%/*}/settings.conf"
|
||||
echo "The syntax is variable=\"value\""
|
||||
echo
|
||||
echo "doomLanguage=\"en\" # 2 letter language code for translation."
|
||||
echo "ipfsGateway=\"https://ipfs.stormux.org\" # Gateway to be used for ipfs downloads."
|
||||
echo "noCache=\"true\" # Do not keep downloaded items in the cache."
|
||||
echo "spd_module=\<module_name>\" # set speech-dispatcher module."
|
||||
echo "spd_pitch=\<number>\" # set speech-dispatcher speech pitch."
|
||||
echo "spd_rate=\<number>\" # set speech-dispatcher speech rate."
|
||||
echo "spd_voice=\<voice_name>\" # set speech-dispatcher voice. Be sure module is correct."
|
||||
echo "spd_volume=\<number>\" # set speech-dispatcher speech volume."
|
||||
help_text+="-${i/:/ <parameter>}: ${command[${i}]}\n"
|
||||
done
|
||||
|
||||
help_text+="\nSome settings that are often used can be stored in a settings.conf file.\nIf wanted, place it at the following location:\n${configFile%/*}/settings.conf\nThe syntax is variable=\"value\"\n\n"
|
||||
help_text+="doomLanguage=\"en\" # 2 letter language code for translation.\n"
|
||||
help_text+="ipfsGateway=\"https://ipfs.stormux.org\" # Gateway to be used for ipfs downloads.\n"
|
||||
help_text+="noCache=\"true\" # Do not keep downloaded items in the cache.\n"
|
||||
help_text+="spd_module=<module_name>\" # set speech-dispatcher module.\n"
|
||||
help_text+="spd_pitch=<number>\" # set speech-dispatcher speech pitch.\n"
|
||||
help_text+="spd_rate=<number>\" # set speech-dispatcher speech rate.\n"
|
||||
help_text+="spd_voice=<voice_name>\" # set speech-dispatcher voice. Be sure module is correct.\n"
|
||||
help_text+="spd_volume=<number>\" # set speech-dispatcher speech volume."
|
||||
|
||||
ui_msgbox "Linux Game Manager Help" "Linux Game Manager" "$help_text"
|
||||
exit 0
|
||||
}
|
||||
|
||||
@ -507,7 +605,7 @@ game_installer() {
|
||||
done
|
||||
# If all games are installed, exit
|
||||
if [[ ${#menuList[@]} -eq 0 ]]; then
|
||||
echo "All games are already installed."
|
||||
ui_msgbox "Linux Game Manager" "Linux Game Manager" "All games are already installed."
|
||||
exit 0
|
||||
fi
|
||||
# Add donation option at the end
|
||||
@ -596,7 +694,7 @@ game_removal() {
|
||||
game_update() {
|
||||
mapfile -t lines < <(find .update -type f -iname '*.sh' 2> /dev/null)
|
||||
if [[ ${#lines} -eq 0 ]]; then
|
||||
echo "No games found."
|
||||
ui_msgbox "Linux Game Manager" "Linux Game Manager" "No games found."
|
||||
exit 0
|
||||
fi
|
||||
# Create the menu of updatable games
|
||||
@ -723,8 +821,8 @@ requiredPackages=(
|
||||
"unzip"
|
||||
)
|
||||
for i in "${requiredPackages[@]}" ; do
|
||||
if ! command -v $i > /dev/null 2>&1 ; then
|
||||
echo "Please install ${i/7z/p7zip} before continuing."
|
||||
if ! command -v "$i" > /dev/null 2>&1 ; then
|
||||
ui_msgbox "Linux Game Manager" "Linux Game Manager" "Please install ${i/7z/p7zip} before continuing."
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
Reference in New Issue
Block a user