-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui
More file actions
executable file
·395 lines (350 loc) · 13.7 KB
/
gui
File metadata and controls
executable file
·395 lines (350 loc) · 13.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
#!/bin/bash
APP_STORE_NAME="LinStore"
APP_STORE_WIDTH=320
APP_STORE_HEIGHT=600
# generic stuff just in case an alternative yad instance exists, for some reason
YAD_COMMAND="yad"
YAD_FLAGS=""
ACCENT="green"
#pwd
if ! command -v "$YAD_COMMAND" &>/dev/null; then
echo "YAD needs to be installed to run LinStore."
exit 1
fi
if [ -f "gui" ] || [ -f "createapp" ] || [ -f "settings" ]; then
cd .
else
cd ~/.linstore
fi
if [[ $(xrandr --current) =~ "connected primary" ]]; then
#echo "Dual monitor setup, placing on primary monitor"
resolution=$(xrandr --current | grep " connected primary" | awk '{print $4}' | cut -d'+' -f1)
else
#echo "Single monitor setup, no primary monitor"
resolution=$(xrandr --current | grep " connected" | awk '{print $3}' | cut -d'+' -f1)
fi
horizontal=$(echo $resolution | cut -d'x' -f1)
vertical=$(echo $resolution | cut -d'x' -f2)
let "categoryPos=$horizontal/2-385"
let "categoryPosY=$vertical/2-320"
declare -A categories
declare -A category_apps
detect_and_write_architecture() {
mkdir -p ~/.linstore
case "$(uname -m)" in
x86_64)
echo "x64" >~/.linstore/architecture.txt
;;
i686)
echo "x86" >~/.linstore/architecture.txt
;;
armv7l)
echo "32" >~/.linstore/architecture.txt
;;
aarch64)
echo "64" >~/.linstore/architecture.txt
;;
*)
echo "Unknown architecture" >~/.linstore/architecture.txt
;;
esac
}
if [ -e "etc/accent" ]; then
ACCENT="$(cat etc/accent)"
if [[ "$ACCENT" == "" ]]; then
ACCENT="green"
fi
fi
list_piapps() {
piapps_file="etc/pi-apps-import"
if [ -e "$piapps_file" ]; then
cat "$piapps_file"
else
echo ""
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"
if [ -e "$description_file" ]; then
cat "$description_file"
else
echo "No description available."
fi
}
get_app_creator() {
app_name="$1"
creator_file="apps/$app_name/creator"
if [ -e "$creator_file" ]; then
cat "$creator_file"
else
echo "No description available."
fi
}
get_app_website() {
app_name="$1"
website_file="apps/$app_name/website"
if [ -e "$website_file" ]; then
cat "$website_file"
else
echo "No description available."
fi
}
theme_get() {
website_file="etc/theme"
if [ -e "$website_file" ]; then
cat "$website_file"
else
echo ""
fi
}
theme=$(theme_get)
###################################
# Graphical environments go below #
multi_install() {
all_apps_list=()
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
app_icon="apps/$app_name/icon-24.png"
all_apps_list+=("FALSE")
all_apps_list+=("$app_icon")
all_apps_list+=("$app_name")
fi
done
APPS=$(GTK_THEME="${theme}" GDK_BACKEND=x11 $YAD_COMMAND --text "<big><b>Multi Installer</b></big>\nInstall multiple apps at once" --geometry=600x${APP_STORE_HEIGHT} --center --columns="3" \
--list --checklist --image="images/logo/logo-64.png" --window-icon="images/logo/logo-64.png" --image-on-top --title "LinStore" --column="Select":chk --column "Icon:IMG" --column "Apps" \
--button="Install"!images/button/install.png!:0 "${all_apps_list[@]}" --no-headers)
response=$?
./api info "Response: $response"
if [ $response -eq 0 ]; then
if [[ "$APPS" != "" ]]; then
list=""
while IFS= read -r line; do
list+="$(echo -e "$line" | awk -F "|" '{print $3}')"
list+=$'\n'
done <<< "$APPS"
./manage multi-install "$list"
fi
fi
}
app_details_page() {
kill $(pgrep -f "title=App Details") > /dev/null 2>&1
sleep 0.1
pos=$(wmctrl -lG | grep "LinStore" | awk '{print $3,$4}')
x2=$((horizontal / 2 - 65))
#y2=$((vertical / 2 - 300))
TITLE="App Details"
wmctrl -l | grep "$TITLE" | awk '{print $1}' | while read -r window_id; do
wmctrl -ic "$window_id" > /dev/null 2>&1
done
local selected_app_name="${1//|/}"
selected_app_name=$(echo "$selected_app_name" | sed 's/<[^>]*>//g')
local app_directory="apps/$selected_app_name"
local app_icon="$app_directory/icon-48.png"
local description=$(get_app_description "$selected_app_name")
local creator=$(get_app_creator "$selected_app_name")
local website=$(get_app_website "$selected_app_name")
if [ -e "$HOME/.linstore/installscripts/$selected_app_name" ]; then
installed="true"
else
installed="false"
fi
local install_command=$(./api install "$app_directory" "$selected_app_name")
local uninstall_command=$(./api uninstall "$app_directory" "$selected_app_name")
local open_command=$(./api open "$app_directory")
buttons=()
if [[ "$installed" == "true" ]]; then
displayName="<b>${selected_app_name}</b> (<i>installed</i>)"
buttonText="Uninstall"
buttonImage="images/button/uninstall.png"
# Create a temporary script for the commands
temp_script=$(mktemp)
echo "$uninstall_command && rm -rf \"$HOME/.linstore/installscripts/$selected_app_name\"" >"$temp_script"
chmod +x "$temp_script"
buttonCommand="bash -c 'bash $temp_script; rm $temp_script'"
if [[ "$open_command" != "" ]]; then
buttons+=("--button=<b>Open</b>!system-run:$open_command")
fi
else
displayName="<b>${selected_app_name}</b> (<i>not installed</i>)"
buttonText="<b>Install</b>"
buttonImage="images/button/install.png"
buttonCommand="$install_command"
fi
if [[ "$open" != "" ]]; then
buttons+=("--button=Open!system-run:$open")
fi
if [[ -f "$app_directory/donate" ]]; then
donate="Help out the developer by <a href='$(cat $app_directory/donate)'>donating</a>!\n"
else
donate=""
fi
(
GDK_BACKEND=x11 $YAD_COMMAND --class LinStore --title="App Details" --geometry=450x${APP_STORE_HEIGHT}+${x2}+${categoryPosY} --form --class="LinStore" \
--text "<big>${displayName}</big>\nBy <b>${creator}</b> (<a href='${website}'>App Website</a>)\n${donate}" \
--field="<b>Description</b>:TXT" --no-edit "$description" --image="$app_icon" --window-icon="images/logo/logo-64.png" --image-on-top \
--button="$buttonText!$buttonImage:$buttonCommand" "${buttons[@]}" --skip-taskbar --noclose &
)
rm -f /tmp/description.tmp
}
show_apps_in_category() {
while true; do
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
app_icon="apps/$app_name/icon-24.png"
formatted_apps+=("$app_icon")
if [ -e "$HOME/.linstore/installscripts/$app_name" ]; then
formatted_apps+=("<span fgcolor=\"$ACCENT\">$app_name</span>")
else
formatted_apps+=("$app_name")
fi
fi
done
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")
fi
done
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" \
--list --image="images/logo/logo-64.png" --window-icon="images/logo/logo-64.png" --image-on-top --title "LinStore" --column "Icon:IMG" --column "Apps" --class="LinStore" \
--button="Back"!images/button/back.png!:4 --separator="\n" --markup "${formatted_apps[@]}" --no-headers \
--css="span{fgcolor:green;}" --select-action='bash -c "./gui showdetails \"%s\"" &'#> /dev/null 2>&1
button_clicked=$?
if [ $button_clicked -eq 4 ]; then
show_app_store
break
fi
show_app_store
break
done
}
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)
list_items=()
list_items=("images/categories/All Apps.png" "All Apps")
while IFS= read -r category; do
category_icon="images/categories/$category.png" # Path to category icons
list_items+=("$category_icon")
list_items+=("$category")
done <<<"$sorted_categories"
# Fetching a random line from the announcements file
random_announcement=$(shuf -n 1 etc/announcements)
# Search function
selected_category_raw=$(GTK_THEME="${theme}" GDK_BACKEND=x11 $YAD_COMMAND --text "$random_announcement" \
--geometry=${APP_STORE_WIDTH}x${APP_STORE_HEIGHT}+${categoryPos}+${categoryPosY} --center --columns="3" \
"${list_items[@]}" --class="LinStore" \
--list --image="images/logo/logo-64.png" --window-icon="images/logo/logo-64.png" --image-on-top --title "$APP_STORE_NAME" --column "Icon:IMG" \
--column "Category" --button "!images/button/search.png"!"Search":"bash -c './api search' &" \
--button "!images/button/update.png"!"Updates":"bash -c './update' &" --button "!images/button/settings.png"!"Settings":"bash -c './settings' &" \
--no-headers --item-height="$welcome_height" --timeout=0 --no-close)
exval=$?
./api info "Exit value: ${exval}"
selected_category="${selected_category_raw//|/}"
if [ "$exval" == "44" ]; then
./api search && show_app_store
elif [ "$exval" -eq "143" ]; then
pkill -f "yad*" > /dev/null 2>&1
elif [ "$exval" -eq "252" ]; then
pkill -f "yad*" > /dev/null 2>&1
elif [ -n "$selected_category" ]; then
show_apps_in_category "$selected_category" &
fi
}
if [[ $1 == "" ]]; then
./api logo
./api buildinfo
echo ""
use_piapps=$(list_piapps)
./api warning "Is LinStore able to use Pi-Apps' library? ${use_piapps}"
fi
if [[ $1 == "showdetails" ]]; then
if [ -e /tmp/tmpname ]; then
app_details_page "$(cat /tmp/tmpname && rm -r /tmp/tmpname)"
else
app_details_page "$(echo $2 | awk -F"'" '{print $4}')"
fi
elif [[ $1 == "multi-install" ]]; then
multi_install
else
detect_and_write_architecture
show_app_store
fi