Skip to content

Commit

Permalink
initial upload of new-gui changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Botspot committed Mar 9, 2022
1 parent ae74458 commit 7a19fd1
Show file tree
Hide file tree
Showing 21 changed files with 856 additions and 897 deletions.
81 changes: 70 additions & 11 deletions api
Original file line number Diff line number Diff line change
Expand Up @@ -784,11 +784,11 @@ app_categories() { #lists all apps in a virtual filesystem based on categories f

#show special "Packages" category
if [ "$show_apps_setting" != standard ];then
list_apps package | list_intersect "$(list_apps visible)" | sed 's+^+Packages/+g'
list_apps package | list_subtract "$(list_apps hidden)" | sed 's+^+Packages/+g'
fi

#show special "All Apps" category
list_apps cpu_installable | list_intersect "$(list_apps visible)" | sed 's+^+All Apps/+g' | "${filter[@]}"
list_apps cpu_installable | list_subtract "$(list_apps hidden)" | sed 's+^+All Apps/+g' | "${filter[@]}"
}

bitly_link() { #Runs whenever an app is installed/uninstalled to tally the number of users for each app
Expand Down Expand Up @@ -939,18 +939,18 @@ app_search() { #search all apps for $1, with filenames in $2 (space-separated an
#search description and website
local results="$(find "${DIRECTORY}/apps" \( -name $find_syntax \) -exec grep -Fi "$query" {} + | awk -F: '{print $1}' | sed "s+${DIRECTORY}/apps/++g" | sed 's+/.*++g')"
#hide incompatible and hidden/disabled apps
results="$(echo "$results" | list_intersect "$(list_apps visible)" | list_intersect "$(list_apps cpu_installable)" | sort)"
results="$(echo "$results" | list_subtract "$(list_apps hidden)" | list_intersect "$(list_apps cpu_installable)" | sort)"

#search app names
results="$(list_apps cpu_installable | list_intersect "$(list_apps visible)" | grep -i "$query" | sort)
results="$(list_apps cpu_installable | list_subtract "$(list_apps hidden)" | grep -i "$query" | sort)
$results"

#remove duplicate entries
echo "$results" | awk '!seen[$0]++'

}

app_search_gui() {
app_search_gui() { #graphical interface to search for apps
local output=''
output="$(yad "${yadflags[@]}" --title=Search --width=310 \
--text="Search for apps."$'\n'"Not case-sensitive." \
Expand All @@ -974,7 +974,11 @@ app_search_gui() {

results="$(app_search "$query" "$search_files")"

if [ ! -z "$results" ];then
if [ "$(echo "$results" | wc -l)" == 1 ];then
#if only one result, don't ask user to select it
echo "$results"

elif [ ! -z "$results" ];then

IFS=$'\n'
LIST=''
Expand All @@ -990,11 +994,6 @@ $(echo "$(cat "${DIRECTORY}/apps/${app}/description" || echo "Description unavai
--list --no-headers --column=:IMG --column=name --column=tooltip:HD \
--print-column=2 --tooltip-column=3)" || exit 0

#if only one app is listed, user should not have to select it.
if [ "$(echo "$results" | wc -l)" == 1 ] && [ -z "$app" ];then
app="$results"
fi

echo "$app"
else
yad "${yadflags[@]}" --title=Results --width=310 \
Expand Down Expand Up @@ -1838,6 +1837,58 @@ get_codename() { #get debian/ubuntu codename
lsb_release -sc
}

multi_install_gui() { #graphical interface to install multiple apps from a list.

#get list of apps - hide hidden apps and hide installed apps
local apps="$(list_apps cpu_installable | list_subtract "$(list_apps hidden)" | list_subtract "$(list_apps installed)")"

local IFS=$'\n'
local app

apps="$(for app in $apps ;do
echo "FALSE
${DIRECTORY}/apps/$app/icon-24.png
$app
$(head -n1 "${DIRECTORY}/apps/$app/description")"
done | sed 's/&/&/g' | yad "${yadflags[@]}" --list --checklist \
--width=300 --height=500 \
--hide-column=4 --print-column=3 --tooltip-column=4 --no-headers \
--text="Install everything you want!"$'\n'"Note: apps that are already installed are not shown." \
--column=:chk --column=:img --column=name --column=:tip \
--button=Cancel!"${DIRECTORY}/icons/exit.png":1 --button='Install selected'!"${DIRECTORY}/icons/install.png":0)"

if [ $? == 0 ] && [ ! -z "$apps" ];then
#remove empty lines from yad's output
apps="$(grep . <<<"$apps")"
echo "Will install these apps:"$'\n'"$apps"

#set the terminal title text
title="Installing $(wc -l <<<"$apps") apps"

#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"'"
source "${DIRECTORY}/api"
generate_logo
"${DIRECTORY}/manage" multi-install "'"$apps"'"
exitcode=$?
if [ $exitcode == 0 ];then
echo
#display countdown
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
else
echo -e "\nClose this window to exit."
read enter #technically you could press Enter to exit.
fi' "$title"

fi
}

#command interceptors - functions that enhance a command
enable_module() { #Permanent equivalent to modprobe, this will load the module on every future startup
local module="$1"
Expand Down Expand Up @@ -2063,6 +2114,14 @@ if [ "$guimode" == yad-dark ];then
export GTK_THEME=Adwaita-dark
elif [ "$guimode" == yad-light ];then
export GTK_THEME=PiXflat
elif [ "$guimode" == yad-default ];then
export GTK_THEME=''
elif [ "$guimode" == xlunch-light-3d ];then
export GTK_THEME=''
elif [ "$guimode" == xlunch-dark-3d ];then
export GTK_THEME=Adwaita-dark
elif [ "$guimode" == xlunch-dark ];then
export GTK_THEME=Adwaita-dark
fi

#this array stores flags that are used in all yad windows - saves on the typing and makes it easy to change an attribute on all dialogs from one place.
Expand Down
2 changes: 1 addition & 1 deletion etc/logviewer
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ for file in $logfiles;do
LIST="$LIST
$date
${DIRECTORY}/apps/${app}/icon-24.png
$(echo $action | sed "s+^uninstall$+${DIRECTORY}/icons/uninstall-short.png+g" | sed "s+^install$+${DIRECTORY}/icons/install-short.png+g")
$(echo $action | sed "s+^uninstall$+${DIRECTORY}/icons/uninstall.png+g" | sed "s+^install$+${DIRECTORY}/icons/install.png+g")
$(echo $result | sed "s+^success$+${DIRECTORY}/icons/${action}ed.png+g" | sed "s+^fail$+${DIRECTORY}/icons/corrupted.png+g" | sed "s+^incomplete$+${DIRECTORY}/icons/corrupted.png+g")
$(echo $action | sed 's/^uninstall$/Uninstalling/g' | sed 's/^install$/Installing/g') $app $(echo $result | sed 's/success/succeeded./g' | sed 's/fail/failed./g' | sed 's/incomplete/was interrupted./g')
$file"
Expand Down
56 changes: 42 additions & 14 deletions etc/preload-daemon
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,65 @@ function error {
exit 1
}

#Only one instance of this script should run at a time. Exit now if another process other than this one is running
proc="$(pgrep preload-daemon)"
num_proc="$(echo "$proc" | wc -l)"
if [ "$2" != 'once' ] && [ "$num_proc" -gt 1 ];then
echo "Preload-daemon is already running." 1>&2
exit 0
else
echo "Running preload-daemon..." 1>&2
fi

#for refresh_all_pkgapp_status function, and to prevent preload script from sourcing api
source "${DIRECTORY}/api" || error "failed to source ${DIRECTORY}/api"

#for mktimestamps function
source "${DIRECTORY}/preload" source

#variable 1 is yad or xlunch
#variable 2 is 'once', if you only want this to run once and exit.

if [ "$(pgrep preload-daemon | wc -l)" -gt 2 ] && [ "$2" != 'once' ];then
#echo "Another instance of preload-daemon is already running. Exiting now."
exit 0
fi

#generate list of folders to preload, including special folders
folders="$(read_category_files | awk -F '|' '{print $2}' | sort | uniq | grep .)
Installed
Packages
All Apps"
#echo "$folders"

[[ "$1" != yad* ]] && [[ "$1" != xlunch* ]] && [ ! -z "$1" ] && error "Unrecognized list format $1"
IFS=$'\n'

#runs every 30 secs for 10 mins
for i in {1..20};do
IFS=$'\n'
"${DIRECTORY}/preload" "$1" &>/dev/null
for folder in $folders ; do
echo "Preloading $folder..."
"${DIRECTORY}/preload" "$1" "$folder" &>/dev/null
done

#hide package-apps that are unavailable in the repositories, and change their status accordingly
refresh_all_pkgapp_status
#only run this if the /var/lib/dpkg/status has been changed since last time
if [ "$(stat -c %Y /var/lib/dpkg/status 2>/dev/null)" != "$(cat "${DIRECTORY}/data/preload/timestamps-dpkg-status" 2>/dev/null)" ];then
echo "Refreshing pkgapp_status..." 1>&2
stat -c %Y /var/lib/dpkg/status 2>/dev/null > "${DIRECTORY}/data/preload/timestamps-dpkg-status"
refresh_all_pkgapp_status &
fi

#get modified timestamps for files/directories in the pi-apps folder
timestamps="$(mktimestamps)"

#determine the app list style (it may change)
guimode="$(cat "${DIRECTORY}/settings/App List Style")"

#only re-preload everything if something in the pi-apps folder was changed
if [ "$timestamps" != "$pretimestamps" ];then

"${DIRECTORY}/preload" "$guimode" &>/dev/null
for folder in $folders ; do
echo "Preloading $folder..." 1>&2
"${DIRECTORY}/preload" "$guimode" "$folder" &>/dev/null
done
echo done 1>&2
else
echo "Preloading skipped; nothing was changed" 1>&2
fi

[ "$2" == 'once' ] && exit 0
[ "$2" == 'once' ] && exit 0 #if the $2 flag to this script is 'once', then it will only preload everything once.
sleep 30
pretimestamps="$timestamps"
done
Loading

0 comments on commit 7a19fd1

Please sign in to comment.