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

Desktop User Interface and mouse support, #70

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion bin/armbian-configng
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ json_data=$(< "$json_file")

#
# 'whiptail' is a simple dialog box utility that works well with Bash. It doesn't have all the features of some other dialog box utilities, but it does everything we need for this script.
[[ -x "$(command -v whiptail)" ]] && DIALOG="whiptail"
[[ -x "$(command -v whiptail)" ]] && DIALOG="whiptail" && GUI="whiptail"


#
Expand Down Expand Up @@ -123,6 +123,9 @@ case "$1" in
"$option" "$args"
exit 0
;;
"--gui")
[[ -x "$(command -v zenity)" ]] && GUI="zenity"
;;
"main=help" | "main=Help")
see_cli_legacy
echo ""
Expand Down
136 changes: 72 additions & 64 deletions lib/armbian-configng/config.ng.functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -465,11 +465,12 @@ parse_menu_items() {
if [[ -n $condition && $condition != "null" ]]; then
# If the function returns a truthy value, add the menu item to the menu
if eval $condition; then
options+=("$id" " - $description")
#options+=("$id" " - $description")
options+=("$id" " - $description")
fi
else
# If the condition field is empty or null, add the menu item to the menu
options+=("$id" " - $description ")
options+=("$id" " - $description ")
fi
done < <(echo "$json_data" | jq -r '.menu[] | '${parent_id:+".. | objects | select(.id==\"$parent_id\") | .sub[]? |"}' select(.disabled|not) | "\(.id)\n\(.description)\n\(.condition)"' || exit 1 )
}
Expand All @@ -495,8 +496,32 @@ generate_top_menu() {

parse_menu_items menu_options

local OPTION=$($DIALOG --title "$TITLE" --menu "$BACKTITLE" 0 80 9 "${menu_options[@]}" \
--ok-button Select --cancel-button Exit 3>&1 1>&2 2>&3)
if [[ $GUI == "zenity" ]]; then
local zenity_options=()
for ((i=0; i<${#menu_options[@]}; i+=2)); do
local id="${menu_options[i]}"
local description="${menu_options[i+1]}"
zenity_options+=("$id" "$description")
done

# Display menu with zenity
local OPTION=$(zenity --list --title="Select an Option" \
--column="ID" --column="Description" \
"${zenity_options[@]}" \
--height=300 --width=400 --ok-label="Select" --cancel-label="Exit")

else

local OPTION=$(whiptail --title "$TITLE" \
--backtitle "$BACKTITLE" \
--menu "Select an option:" 0 80 9 \
"${menu_options[@]}" \
--ok-button Select \
--cancel-button Exit \
3>&1 1>&2 2>&3)

fi

local exitstatus=$?

if [ $exitstatus = 0 ]; then
Expand Down Expand Up @@ -528,8 +553,25 @@ function generate_menu() {
local submenu_options=()
parse_menu_items submenu_options

local OPTION=$($DIALOG --title "$TITLE" --menu "$BACKTITLE" 0 80 9 "${submenu_options[@]}" \
--ok-button Select --cancel-button Back 3>&1 1>&2 2>&3)
if [[ $GUI == "zenity" ]]; then
local zenity_options=()
for ((i=0; i<${#menu_options[@]}; i+=2)); do
local id="${submenu_options[i]}"
local description="${submenu_options[i+1]}"
zenity_options+=("$id" "$description")
done

# Display menu with zenity
local OPTION=$(zenity --list --title="Select an Option" \
--column="ID" --column="Description" \
"${zenity_options[@]}" \
--height=300 --width=400 --ok-label="Select" --cancel-label="Exit")

else

local OPTION=$(whiptail --title "$TITLE" --menu "$BACKTITLE" 0 80 9 "${submenu_options[@]}" \
--ok-button Select --cancel-button Back 3>&1 1>&2 2>&3)
fi

local exitstatus=$?

Expand Down Expand Up @@ -613,11 +655,10 @@ function show_message() {
input=$(cat)

# Display the "OK" message box with the input data
if [[ $DIALOG != "bash" ]]; then
$DIALOG --title "$TITLE" --msgbox "$input" 0 0
if [[ $GUI == "zenity" ]]; then
zenity --info --title="$TITLE" --text="$input." --ok-label="OK"
else
echo -e "$input"
read -p -r "Press [Enter] to continue..."
$DIALOG --title "$TITLE" --msgbox "$input" 0 0
fi
}

Expand Down Expand Up @@ -713,23 +754,33 @@ module_options+=(
function get_user_continue() {
local message="$1"
local next_action="$2"

if $($DIALOG --yesno "$message" 10 80 3>&1 1>&2 2>&3); then
$next_action
if [[ "$GUI" == "zenity" ]]; then
if zenity --question --title="Confirm Action" --text="$message" --width=300 --height=200; then
eval $next_action
else
$next_action "No"
eval $next_action "No"
fi
elif [[ "$GUI" == "whiptail" ]]; then
if whiptail --yesno "$message" 10 80 3>&1 1>&2 2>&3; then
eval $next_action
else
eval $next_action "No"
fi
else
echo "Error: Unsupported GUI tool specified."
exit 1
fi
}


menu_options+=(
["get_user_continue,author"]="Joey Turner"
["get_user_continue,ref_link"]=""
["get_user_continue,feature"]="process_input"
["get_user_continue,desc"]="used to process the user's choice paired with get_user_continue"
["get_user_continue,example"]="get_user_continue 'Do you wish to continue?' process_input"
["get_user_continue,status"]="Active"
["get_user_continue,doc_link"]=""
["process_input,author"]="Joey Turner"
["process_input,ref_link"]=""
["process_input,feature"]="process_input"
["process_input,desc"]="used to process the user's choice paired with get_user_continue"
["process_input,example"]="get_user_continue 'Do you wish to continue?' process_input"
["process_input,status"]="Active"
["process_input,doc_link"]=""
)
#
# Function to process the user's choice paired with get_user_continue
Expand All @@ -741,49 +792,6 @@ function process_input() {
fi
}


module_options+=(
["get_user_continue_secure,author"]="Joey Turner"
["get_user_continue_secure,ref_link"]=""
["get_user_continue_secure,feature"]="get_user_continue_secure"
["get_user_continue_secure,desc"]="Secure version of get_user_continue"
["get_user_continue_secure,example"]="get_user_continue_secure 'Do you wish to continue?' process_input"
["get_user_continue_secure,doc_link"]=""
["get_user_continue_secure,status"]="Active"
)
#
# Secure version of get_user_continue
#
function get_user_continue_secure() {
local message="$1"
local next_action="$2"

# Define a list of allowed functions
local allowed_functions=("process_input" "other_function")
# Check if the next_action is in the list of allowed functions
found=0
for func in "${allowed_functions[@]}"; do
if [[ "$func" == "$next_action" ]]; then
found=1
break
fi
done

if [[ "$found" -eq 1 ]]; then
if $($DIALOG --yesno "$message" 10 80 3>&1 1>&2 2>&3); then
$next_action
else
$next_action "No"
fi
else
echo "Error: Invalid function"

exit 1
fi
}



module_options+=(
["see_ping,author"]="Joey Turner"
["see_ping,ref_link"]=""
Expand Down
Loading