Skip to content
Draft
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
45 changes: 45 additions & 0 deletions api
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,51 @@ search_apps() {
fi
}

cache_categories() {
# $1 - apps dir
# $2 - include Pi-Apps?
yad --title="LinStore" \
--class="LinStore" \
--center --borders=10 \
--text "Generating app cache..." \
--no-buttons &

if [ -e "${1}/app_categories" ]; then
rm -f "${1}/app_categories"
fi

for app_dir in "${1}"/*; do
app_name=$(basename "${app_dir}")
if [ -e "${1}/$app_name/category" ]; then
echo "$app_name|$(cat "${1}/$app_name/category")" >> "${1}/app_categories"
fi
done

if [[ "$2" == "TRUE" ]]; then
if [ -e "$HOME/pi-apps/etc/categories" ]; then
while IFS= read -r line; do
app_name=$(echo "$line" | awk -F'|' '{print $1}')
category=$(grep -r "$(echo "$line" | awk -F'|' '{print $2}')" etc/mapping | head -n1 | awk -F'|' '{print $2}')
echo "$app_name|$category" >> "${1}/app_categories"
done < "$HOME/pi-apps/etc/categories"
fi
fi

sort "${1}/app_categories" > "${1}/app_categories.tmp"
mv "${1}/app_categories.tmp" "${1}/app_categories"

pkill -f "yad*"
}

get_categories() {
cat etc/categories
}

get_apps_in_category() {
local category="$1"
grep "|$category$" etc/categories | cut -d'|' -f1
}

update() {
pkill -f "yad*"
./api info "Updating LinStore..."
Expand Down
113 changes: 28 additions & 85 deletions gui
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

source api

APP_STORE_NAME="LinStore"
APP_STORE_WIDTH=320
APP_STORE_HEIGHT=600
Expand Down Expand Up @@ -74,71 +76,6 @@ list_piapps() {
fi
}

read_categories() {
while read -r category; do
categories["$category"]=""
done <etc/categories

for app_dir in "${1}"/*; do
app_name=$(basename "${app_dir}")

if [ ! -e "${1}/$app_name/category" ]; then
escaped_app_name=$(echo "$app_name" | sed 's/([\/.^$*+?|{}\[])/\\&/g')
data=$(grep -E "$escaped_app_name" etc/piapps-categories | awk -F"|" '{print $2}')
if [ -n "$data" ]; then
data2=$(grep -E "$data" etc/mapping | awk -F"|" '{print $2}')
if [ -n "$data2" ]; then
echo "$data2" > "${1}/$app_name/category"
category_file="${1}/$app_name/category"
else
continue
fi
else
continue
fi
fi

category_file="${1}/$app_name/category"
install_script="$app_dir/install"

# Check if the install script or architecture-specific install scripts exist for this app
if [ -e "$install_script" ]; then
while IFS= read -r app_in_category; do
# Make sure $app_in_category is not empty before accessing the array
if [ -n "$app_in_category" ]; then
if [ -n "${categories[$app_in_category]}" ]; then
categories["$app_in_category"]+=" $app_name"
category_apps["$app_in_category"]+="|$app_name"
else
categories["$app_in_category"]="$app_name"
category_apps["$app_in_category"]="$app_name"
fi
fi
break
done <"$category_file"
else
architecture=$(cat ~/.linstore/architecture.txt)
install_script_arch="install-$architecture"

if [ -e "$app_dir/$install_script_arch" ]; then
while IFS= read -r app_in_category; do
# Make sure $app_in_category is not empty before accessing the array
if [ -n "$app_in_category" ]; then
if [ -n "${categories[$app_in_category]}" ]; then
categories["$app_in_category"]+=" $app_name"
category_apps["$app_in_category"]+="|$app_name"
else
categories["$app_in_category"]="$app_name"
category_apps["$app_in_category"]="$app_name"
fi
fi
break
done <"$category_file"
fi
fi
done
}

get_app_description() {
app_name="$1"
description_file="apps/$app_name/description"
Expand Down Expand Up @@ -284,9 +221,12 @@ show_apps_in_category() {
formatted_apps=()
if [ "$1" == "All Apps" ]; then
title="All Apps"
for app_dir in apps/*; do
app_name=$(basename "$app_dir")
if [ -e "$app_dir/install" ] || [ -e "$app_dir/install-$(cat ~/.linstore/architecture.txt)" ]; then
while IFS= read -r line; do
app_name=$(echo "$line" | awk -F'|' '{print $1}')
app_dir="apps/$app_name"
if [ -e "$app_dir/install" ] || [ -e "$app_dir/install-$(cat ~/.linstore/architecture.txt)" ] \
|| [ -e "$HOME/pi-apps/apps/$app_name/install-$(cat ~/.linstore/architecture.txt)" ] \
|| [ -e "$HOME/pi-apps/apps/$app_name/install" ]; then
app_icon="apps/$app_name/icon-24.png"
formatted_apps+=("$app_icon")
if [ -e "$HOME/.linstore/installscripts/$app_name" ]; then
Expand All @@ -295,22 +235,26 @@ show_apps_in_category() {
formatted_apps+=("$app_name")
fi
fi
done
done < "apps/app_categories"
else
apps_in_category="${category_apps["$1"]}"
title="Apps in $1 Category"
#formatted_apps=()

IFS='|' read -r -a app_list <<<"$apps_in_category"
for app in "${app_list[@]}"; do
app_icon="apps/$app/icon-24.png"
formatted_apps+=("$app_icon")
if [ -e "$HOME/.linstore/installscripts/$app" ]; then
formatted_apps+=("<span fgcolor=\"$ACCENT\">$app</span>")
else
formatted_apps+=("$app")
while IFS= read -r line; do
[[ $(echo "$line" | awk -F'|' '{print $2}') == "$1" ]] || continue
app=$(echo "$line" | awk -F'|' '{print $1}')
if [ -e "apps/$app/install" ] || [ -e "apps/$app/install-$(cat ~/.linstore/architecture.txt)" ] \
|| [ -e "$HOME/pi-apps/apps/$app/install-$(cat ~/.linstore/architecture.txt)" ] \
|| [ -e "$HOME/pi-apps/apps/$app/install" ]; then
app_icon="apps/$app/icon-24.png"
formatted_apps+=("$app_icon")
if [ -e "$HOME/.linstore/installscripts/$app" ]; then
formatted_apps+=("<span fgcolor=\"$ACCENT\">$app</span>")
else
formatted_apps+=("$app")
fi
fi
done
done < "apps/app_categories"
fi

GTK_THEME="${theme}" GDK_BACKEND=x11 $YAD_COMMAND --text "<big><b>$title</b></big>" --geometry=${APP_STORE_WIDTH}x${APP_STORE_HEIGHT}+${categoryPos}+${categoryPosY} --center --columns="2" \
Expand All @@ -330,13 +274,8 @@ show_apps_in_category() {
}

show_app_store() {
read_categories "apps"
if [[ "$use_piapps" == "TRUE" ]]; then
read_categories "/home/${USER}/pi-apps/apps"
fi

# Sort categories alphabetically and format with newlines
sorted_categories=$(printf '%s\n' "${!categories[@]}" | sort)
sorted_categories=$(printf '%s\n' "$(get_categories)" | sort)

list_items=()
list_items=("images/categories/All Apps.png" "All Apps")
Expand Down Expand Up @@ -373,6 +312,10 @@ show_app_store() {
fi
}

if [ ! -e apps/app_categories ]; then
cache_categories "apps" "$(list_piapps)"
fi

if [[ $1 == "" ]]; then
./api logo
./api buildinfo
Expand Down
3 changes: 3 additions & 0 deletions settings
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

source api

APP_STORE_DIRECTORY="apps"
CATEGORIES_FILE="etc/categories"
THEMES_DIRECTORY="/usr/share/themes"
Expand Down Expand Up @@ -139,6 +141,7 @@ show_settings() {

import_from_piapps=$(echo "$fixed_settings" | awk -F '|' '{print $5}')
echo $import_from_piapps > "etc/pi-apps-import"
cache_categories "apps" "$(cat "etc/pi-apps-import" 2> /dev/null || echo FALSE)"

express_updates=$(echo "$fixed_settings" | awk -F '|' '{print $6}')
echo $express_updates > "etc/express-updates"
Expand Down
5 changes: 5 additions & 0 deletions update
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

source api

if [[ $(xrandr --current) =~ "connected primary" ]]; then
resolution=$(xrandr --current | grep " connected primary" | awk '{print $4}' | cut -d'+' -f1)
else
Expand Down Expand Up @@ -33,6 +35,9 @@ check_for_updates() {
mv ~/.linstore/tmp/apps ./apps
sleep 1

echo '# Update app cache'
cache_categories "apps" "$(cat "etc/pi-apps-import" 2> /dev/null || echo FALSE)"

# Clean up
# rm -rf ~/.linstore/tmp
echo "# Finished"
Expand Down