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

Add retry button, subterminal, summary window to manage daemon #2708

Merged
merged 14 commits into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from 11 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
77 changes: 30 additions & 47 deletions api
Original file line number Diff line number Diff line change
Expand Up @@ -1081,51 +1081,24 @@ terminal_manage() { # wrapper for the original terminal_manage function to termi
terminal_manage_multi "$action $app"
}

terminal_manage_multi() { #function to install/uninstall/update/refresh multiple apps (or filelists) - uses a terminal and refreshes the app list
queue="$1" #one or multiple actions and app names (or filelists of the format 'filelist:path/to/file:path/to/another/file')
Botspot marked this conversation as resolved.
Show resolved Hide resolved
terminal_manage_multi() { #function to install/uninstall/update/refresh multiple apps - refreshes the app list if applicable
local queue="$1" #one or multiple actions and app names

#To prevent multiple simultaneous manage instances, use the 'daemon' mode. This will create a queue of actions that are executed concurrently.
#The first daemon instance is the 'master' process. Subsequent processes will add the action to the queue and then exit.
#The first daemon instance is the 'master' process, which opens a terminal. Subsequent processes will add the action to the queue and then exit.
#All output is generated by the 'master' daemon process. Subsequent processes shouldn't open a terminal, because the master one is already open.
if [ -f "${DIRECTORY}/data/manage-daemon/pid" ] && process_exists $(cat "${DIRECTORY}/data/manage-daemon/pid") ;then
#The 'master' daemon is already running. Avoid launching a second terminal.
#daemon already running, send queue to it and exit
"${DIRECTORY}/manage" daemon "$queue"

else
#in a terminal, first get the api functions, display the pi-apps logo, run the manage script, and refresh the app list if the $pipe variable is set
"${DIRECTORY}/etc/terminal-run" '
DIRECTORY="'"$DIRECTORY"'"
export geometry2="'"$geometry2"'"
source "${DIRECTORY}/api"
generate_logo

refresh_list() { #Refresh the current list of apps in the event of a change
if [ ! -z "'"$pipe"'" ] && [ -p "'"$pipe"'" ];then
echo -e "\f" > "'"$pipe"'"
"${DIRECTORY}/preload" "$(cat "${DIRECTORY}/data/settings/App List Style")" "'"$prefix"'" > "'"$pipe"'" 2>/dev/null
fi
}

"${DIRECTORY}/manage" daemon "'"$queue"'"

#refresh app list
refresh_list

for i in {30..1} ;do
echo -en "You can close this window now. Auto-closing in $i seconds.\e[0K\r"
sleep 1
done
' "Terminal Output"

# Check if terminal-run failed to launch. GUI users don't see any terminal output if it fails (since there is no terminal open) so we need to prompt them with a GUI window
if [ "$?" != 0 ]; then
echo -e "Unable to open a terminal.\nDebug output below.\n$(DEBUG=1 "${DIRECTORY}/etc/terminal-run" 2>&1)" | yad --center --window-icon="${DIRECTORY}/icons/logo.png" \
--width=700 --height=300 --text-info --title="Error occured when calling terminal-run" \
--image="${DIRECTORY}/icons/error.png" --image-on-top --fontname=12 \
--button='OK'
if echo "$queue" | grep -q "^update filelist:" ;then #list of files separated by :
updatable_apps='' updatable_files="$(echo "$queue" | grep "^update filelist:" | sed 's/^update filelist://g' | tr ':' '\n')" no_status=true update_now_cli
fi
#this function is running the daemon, so once it exits refresh the pi-apps list
"${DIRECTORY}/manage" daemon "$queue"

#refresh app list
if [ ! -z "$pipe" ] && [ -p "$pipe" ];then
echo -e '\f' > "$pipe"
"${DIRECTORY}/preload" "$(cat "${DIRECTORY}/data/settings/App List Style")" "$prefix" > "$pipe" 2>/dev/null
fi
fi
}
Expand Down Expand Up @@ -1598,6 +1571,9 @@ will_reinstall() { #return 0 if $1 app will be reinstalled during an update, oth
if [ "$(app_status "$app")" != 'installed' ];then
return 1
fi
#it seems that the above code was added for speed alone https://github.com/Botspot/pi-apps/commit/d8bfc3f5fc9b42060bfbd68a11b24f66246d61bc
#commenting it out allows retrying failed app update where uninstall succeeds but install fails
#edit: uncommented it again because all uninstalled app refreshes were now being installed

#detect which installation script exists - both for local install and for update directory
local local_scriptname="$(script_name_cpu "$app")"
Expand Down Expand Up @@ -2919,16 +2895,19 @@ send_error_report() { #non-interactively send a Pi-Apps error log file to the Bo

}

diagnose_apps() { #Given a list of apps that failed to install/uninstall, loop through each error log, diagnose it, and provide a "Send report" button if applicable.
local failed_apps="$1"
diagnose_apps() { #Given a list of action;app that failed to install/uninstall, loop through each error log, diagnose it, and provide a "Send report" button if applicable.
local failure_list="$1"
local IFS=$'\n'

local num_lines="$(grep . <<<"$failed_apps" | wc -l)"
local i=1 #counter to track which failed_app in the list is current
local app
local num_lines="$(grep . <<<"$failure_list" | wc -l)"
local i=1 #counter to track which line in the list is current
local line
local button

for app in $failed_apps ;do
for line in $failure_list ;do
local action="$(echo "$line" | awk -F';' '{print $1}')"
local app="$(echo "$line" | awk -F';' '{print $2}')"

theofficialgman marked this conversation as resolved.
Show resolved Hide resolved
local logfile="$(get_logfile "$app")"
#given the app's logfile, categorize the error and set the error_type variable
local diagnosis="$(log_diagnose "$logfile" "allowwrite")"
Expand Down Expand Up @@ -2958,7 +2937,7 @@ diagnose_apps() { #Given a list of apps that failed to install/uninstall, loop t
text+=$'\n'"Error report cannot be sent because your system is unsupported."
else
#if all of the above checks evaluate to FALSE, then display the "Send report" button.
local send_button=(--button='Send report'!"${DIRECTORY}/icons/send-error-report.png":2)
local send_button=(--button='Send report'!"${DIRECTORY}/icons/send-error-report.png"!"Send this log file to Pi-Apps developers for review":2)
fi

#display support links, depending on if this was a package-app or a script-app
Expand All @@ -2981,7 +2960,7 @@ diagnose_apps() { #Given a list of apps that failed to install/uninstall, loop t
error_caption="$(echo "$unsupported_message" | sed "s/\x1b\[[0-9;]*[a-zA-Z]//g")"$'\n'$'\n'"$error_caption"
fi

#this dialog may be one in a series of failed_app dialogs. Name the window-close button accordingly.
#this dialog may be one in a series of diagnosis dialogs. Name the window-close button accordingly.
if [ $i -lt $num_lines ];then
local close_button=(--button="Next error!${DIRECTORY}/icons/forward.png":1)
else
Expand All @@ -2993,12 +2972,16 @@ diagnose_apps() { #Given a list of apps that failed to install/uninstall, loop t
--text="$text" --wrap --fontname=12 \
--button='View log'!"${DIRECTORY}/icons/log-file.png"!"Review the output from when <b>$app</b> tried to $action.":"bash -c 'view_file "\""$logfile"\""'" \
"${send_button[@]}" \
"${close_button[@]}"
--button="Retry!${DIRECTORY}/icons/refresh.png"!"Try $(echo "${action}ing" | sed 's/updateing/updating/g') $app again.":3 \
"${close_button[@]}" >/dev/null
button="${PIPESTATUS[1]}"

if [ $button == 2 ];then
#send error log
send_error_report "$logfile"
elif [ $button == 3 ];then
#retry button clicked, return new queue line(s) back to manage daemon
echo "$line"
fi

i=$((i+1))
Expand Down
Binary file added icons/botspot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/theofficialgman.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading