forked from Botspot/pi-apps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui
executable file
·411 lines (362 loc) · 14.7 KB
/
gui
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
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
#!/bin/bash
DIRECTORY="$(readlink -f "$(dirname "$0")")"
function error {
echo -e "\e[91m$1\e[39m"
exit 1
}
[ -z "$(yad --help)" ] && error "YAD needs to be installed to run pi-apps."
echo '|‾‾‾‾\(‾) /‾\
| |‾) |‾| / ⧋ \ |‾'\''‾‾\|‾'\''‾‾\/‾‾‾|
| ‾_/| | |‾‾‾| / ‾‾‾ \| |‾) | |‾) \ ‾‾\
|_|‾ |_| ‾‾‾ /_/‾‾‾\_\ .‾_/| .‾_/|‾‾ /
|_|‾ |_|‾ ‾‾‾
'
#check for updates in background
"${DIRECTORY}/updater" &>/dev/null &
#Variable 1 is used to view the details of the specified app
if [ ! -z "$1" ];then
output="$1"
fi
#hide wine on twisteros
(if [ -f /usr/local/bin/twistver ] && ! grep -q "Mac OS Theme|Eyecandy" "${DIRECTORY}/data/categories/structure" ;then
"${DIRECTORY}/install"
fi) &
rm -rf "${DIRECTORY}/apps/FreeCAD (precompiled)"
"${DIRECTORY}/etc/categoryedit" 'FreeCAD' Editors >/dev/null
#show Etcher on TwisterOS
"${DIRECTORY}/etc/categoryedit" 'balenaEtcher' Tools >/dev/null
install() {
app="$1"
#terminal title text
linecount="$(echo "$app" | wc -l)"
if [ $linecount -eq 1 ];then
title="Installing $app"
elif [ $linecount -le 4 ];then
title="Installing $(echo "$app" | tr '\n' '|' | sed -i 's/|/, /g')"
else
title="Installing several apps"
fi
"${DIRECTORY}/etc/terminal-run" '
if "'"${DIRECTORY}/manage"'" multi-install "'"$app"'" ; then
echo -e "\nClosing in 30 seconds."
sleep 30
else
echo -e "\nClose this window to exit."
read enter #technically you could press Enter to exit.
fi
' "$title"
sleep 1
while ps -C manage &>/dev/null;do sleep 0.1; done
}
uninstall() {
app="$1"
#terminal title text
linecount="$(echo "$app" | wc -l)"
if [ $linecount -eq 1 ];then
title="Uninstalling $app"
elif [ $linecount -le 4 ];then
title="Uninstalling $(echo "$app" | tr '\n' '|' | sed -i 's/|/, /g')"
else
title="Uninstalling several apps"
fi
"${DIRECTORY}/etc/terminal-run" '
if "'"${DIRECTORY}/manage"'" multi-uninstall "'"$app"'" ; then
echo -e "\nClosing in 30 seconds."
sleep 30
else
echo -e "\nClose this window to exit."
read enter #technically you could press Enter to exit.
fi
' "$title"
sleep 1
while ps -C manage &>/dev/null;do sleep 0.1; done
}
motd="$(echo -e "$(wget -qO- https://raw.githubusercontent.com/dwhr-pi/pi-apps-announcements/main/message | shuf -n 1)")"
#app list mode. Allowed values: 'yad', 'xlunch'
guimode="$(cat "${DIRECTORY}/data/settings/App List Style")"
[ -z "$guimode" ] && guimode=yad
#mode=yad
prefix=''
while true;do
LIST="$("${DIRECTORY}/preload" $guimode "$prefix")"
#LIST="$(cat "${DIRECTORY}/data/preload/LIST")"
#echo "$LIST"
#if output is not empty then assume button pressed was Details
button=0
while [ -z "$output" ];do
if [ "$guimode" == yad ];then
if [ -z "$prefix" ];then
buttons=("--button=!${DIRECTORY}/icons/install.png!Install:4" \
"--button=!${DIRECTORY}/icons/uninstall.png!Uninstall:2" \
"--button=!${DIRECTORY}/icons/info.png!View more about the selected software:0" )
else
buttons=("--button=!${DIRECTORY}/icons/back.png!Back:3" \
"--button=!${DIRECTORY}/icons/install.png!Install:4" \
"--button=!${DIRECTORY}/icons/uninstall.png!Uninstall:2" \
"--button=!${DIRECTORY}/icons/info.png!Details:0" )
fi
output="$(echo -e "$LIST" | yad --center --title='Pi-Apps'"$([ ! -z "$prefix" ] && echo ": $(echo "$prefix" | tr '/' '>')")" --width=810 --height=550 --no-headers \
--text="$([ -z "$prefix" ] && echo "$motd" || echo "Viewing $(echo "$prefix" | tr '/' '>') category")" --image="${DIRECTORY}/icons/logo-64.png" --image-on-top \
--list --multiple --separator='\n' --window-icon="${DIRECTORY}/icons/logo.png" \
--column=:IMG --column=:IMG --column=Name --column=Sysname:HD --column=tip:HD \
--print-column=4 --tooltip-column=5 \
"${buttons[@]}" \
)"
button=$? #get exit code to determine which button was pressed
echo "Button: ${button}"
if [ $button -eq 252 ];then #if window manager x was pressed
exit 0
fi
if [ "$button" == 3 ];then
#back button
break
fi
if [ -z "$output" ];then
echo "output variable empty!"
yad --center --title='Pi-Apps' --width=310 \
--window-icon="${DIRECTORY}/icons/logo.png" \
--text="Mind reading is not supported.
(You didn"\'"t select an App)" \
--button=OK:0
fi
elif [ "$guimode" == xlunch ];then
if [ ! -d "${DIRECTORY}/xlunch" ] || [ ! -f /usr/bin/xlunch ];then
#get current number of terminal-run processes
rm -f /tmp/xlunchfailed /tmp/xlunchfinished /tmp/terminalexit
echo '' > /tmp/terminalexit
"${DIRECTORY}/etc/terminal-run" "
function error {
echo -e "\""\e[91m$1\e[39m"\""
echo 'Close this terminal to exit.'
echo '' > /tmp/xlunchfailed
sleep infinity
}
trap 'echo "\"""\"" > /tmp/terminalexit' EXIT
rm -f /tmp/terminalexit
sudo rm -rf /usr/bin/xlunch "\""$DIRECTORY/xlunch"\"" 2>/dev/null
sudo apt install -y libimlib2-dev libx11-dev || error 'APT failed to install libimlib2-dev and libx11-dev packages!'
cd "\""$DIRECTORY"\""
git clone https://github.com/Tomas-M/xlunch || error 'Failed to clone xlunch repository!'
cd "\""$DIRECTORY/xlunch"\""
echo 'Running make...'
make -j8 || error 'make command failed!'
echo 'Running sudo make install...'
sudo make install || error 'sudo make install failed!'
sudo rm -f /usr/share/applications/genentries.desktop
cd $HOME
if [ ! -f /usr/bin/xlunch ];then
error 'xlunch should be installed now, but /usr/bin/xlunch does not exist!'
fi
echo '' > /tmp/xlunchfinished
" 'Compiling xlunch...'
#if terminal doesn't start in 3 seconds, then /tmp/terminalexit will exist.
sleep 3
#check for an exit status code from the running terminal
while true; do
if [ -f /tmp/xlunchfinished ];then
break
echo "xlunch finished installing."
elif [ -f /tmp/xlunchfailed ] || [ -f /tmp/terminalexit ];then
#revert back to yad
echo 'yad' > "{DIRECTORY}/data/settings/App List Style"
error "xlunch failed to compile!\nOr the terminal exited."
else
sleep 1
fi
done
fi
#xlunch compiled
screen_width="$(xdpyinfo | grep 'dimensions:' | tr 'x' '\n' | tr ' ' '\n' | sed -n 7p)"
screen_height="$(xdpyinfo | grep 'dimensions:' | tr 'x' '\n' | tr ' ' '\n' | sed -n 8p)"
height=700
width=800
xposition=$(((screen_width/2)-(width/2)))
yposition=$(((screen_height/2)-(height/2)))
if false;then
scrotosition=$(((screen_width/2)-(width/2))) -a "$((xposition+1)),$((yposition+33)),${width},${height}" blur.png #blur_init.png
convert -blur 10x5 ~/blur.png ~/blur.png
fi
if [ ! -z "$prefix" ];then
echo "Adding back button to xlunch..."
LIST="Back;${DIRECTORY}/icons/back-64.png;./
$LIST"
LIST="$(echo "$LIST" | grep .)"
fi
echo "$LIST"
if [ -z "$prefix" ];then
searchbox="Search: "
else
searchbox="Viewing $(echo "$prefix" | tr '/' '>'). Search: "
fi
output="$(echo -e "$LIST" | xlunch -WoCS -s 64 --bc 000000A0 --tc ffffffff --pc 6060ffff --hc 60606010 \
-p "$searchbox" -a -c 2 --title "Pi-Apps: Raspberry Pi app store" \
--icon "${DIRECTORY}/icons/logo.png" --scrollbarcolor ffffff40 --scrollindicatorcolor 0000ff80\
--width $width --height $height --xposition $xposition --yposition $yposition \
--button "${DIRECTORY}/icons/logo-128.png;;$((($width/2)-(128/2))),0;pi-apps-homepage1"
#-g ~/blur.png
)"
button=0
if [ -z "$output" ];then
error "xlunch did not report any selected apps!"
fi
#homepage button
if [ "$output" == 'pi-apps-homepage1' ];then
chromium-browser https://github.com/dwhr-pi/pi-apps &
output=''
fi
else
error "Unrecognized app list style '$guimode'!"
fi
output="$(echo "$output" | sed '/^$/d')"
echo "Output: ${output}EOO"
done
#output variable populated
case $button in
1)
echo "User exited."
exit 0
;;
3)
echo "Back"
prefix="$(dirname "$prefix" | tr -d '.')"
;;
0)
echo "Details"
if echo "$output" | grep -q '/' ;then
#folder
if [ "$output" == './' ];then
echo "Back"
prefix="$(dirname "$prefix" | tr -d '.')"
else
prefix="$prefix/$output"
prefix="${prefix::-1}"
prefix="$(echo "$prefix" | sed 's+^/++')"
fi
echo "Prefix is $prefix"
output=''
else
#app
output="$(echo "$output" | head -n1)"
if [ ! -z "$(cat "${DIRECTORY}/data/installed-packages/${output}")" ];then
installedpackages="
This app installed these packages: $(cat "${DIRECTORY}/data/installed-packages/${output}" | sort | uniq | tr '\n' ' ')"
else
installedpackages=''
fi
description="$(cat "${DIRECTORY}/apps/${output}/description" || echo 'Description unavailable')"
text="$(echo "$(cat "${DIRECTORY}/apps/${output}/description" || echo "Description unavailable")" | head -n1)
Current status: $(cat "${DIRECTORY}/data/status/${output}" || echo 'Uninstalled')
Website: $(cat "${DIRECTORY}/apps/${output}/website" || echo 'unavailable')
$(echo "$description" | grep -v "$(echo "$description" | head -n1)")
$installedpackages"
#if already installed then no need to provide install button. And vice versa.
whichbutton="$(
if [ "$(cat "${DIRECTORY}/data/settings/Show Edit button")" == 'Yes' ];then
echo "--button=Edit!${DIRECTORY}/icons/edit.png:10"
fi
if [ -f "${DIRECTORY}/apps/${output}/credits" ];then
echo "--button=Credits!${DIRECTORY}/icons/credits.png:12"
fi
if [ ! -f "${DIRECTORY}/data/status/${output}" ];then
#Taking a chance here. If status file is nonexistent, assume uninstalled.
echo "--button=!${DIRECTORY}/icons/install.png:4"
elif [ "$(cat "${DIRECTORY}/data/status/${output}")" == 'installed' ];then
echo "--button=!${DIRECTORY}/icons/uninstall.png:2"
elif [ "$(cat "${DIRECTORY}/data/status/${output}")" == 'uninstalled' ];then
echo "--button=!${DIRECTORY}/icons/install.png:4"
else
#if status is corrupted or unknown, then show both buttons
echo "--button=!${DIRECTORY}/icons/uninstall.png:2 --button=!${DIRECTORY}/icons/install.png:4"
fi
)"
echo "$text" | yad --text-info --fontname=12 --wrap --show-uri \
--image="${DIRECTORY}/apps/${output}/icon-64.png" --image-on-top \
--title="Details of ${output}" --window-icon="${DIRECTORY}/icons/logo.png" --center --width=700 --height=300 \
--button=Back!"${DIRECTORY}/icons/back.png":0 \
--button=''!"${DIRECTORY}/icons/up.png"!'View previous App':6 \
--button=''!"${DIRECTORY}/icons/down.png"!'View next App':8 \
$whichbutton
button=$? #get exit code to determine which button was pressed
echo "Button: ${button}"
if [ $button == 0 ];then
echo 'Back' #do nothing, as user requested to go back
#clear app var
output=''
elif [ $button == 4 ];then
app="$output"
install "$app"
elif [ $button == 2 ];then
app="$output"
uninstall "$app"
elif [ $button == 6 ] || [ $button == 8 ];then
#previous or next app clicked
lsoutput="$(echo "$LIST" | grep -v '/' | grep -v '(' | grep -v *'\n App folder' | awk -F ';' '{print $NF}' | uniq)"
echo "$lsoutput"
if [ $button == 6 ];then
echo 'previous app'
#convert $output into number, then subtract 1 from it
number="$(echo "$lsoutput" | grep -nx "$output" | cut -f1 -d: )"
lastline="$(echo "$lsoutput" | wc -l)"
if [ $(($number - 1)) -lt '1' ];then
newnumber=$lastline
else
newnumber=$(($number - 1))
fi
output="$(echo "$lsoutput" | sed -n "${newnumber}p")"
echo "Line number was ${number}, but now is ${newnumber}. Name is ${output}."
elif [ $button == 8 ];then
echo 'next app'
#convert $output into number, then add 1 to it
number="$(echo "$lsoutput" | grep -nx "$output" | cut -f1 -d: )"
echo "Line number was ${number}, but now is ${newnumber}. Name is ${output}."
lastline="$(echo "$lsoutput" | wc -l)"
if [ $(($number + 1)) -gt $lastline ];then
newnumber=1
else
newnumber=$(($number + 1))
fi
output="$(echo "$lsoutput" | sed -n "${newnumber}p")"
echo "Line number was ${number}, but now is ${newnumber}. Name is ${output}."
fi
elif [ $button == 10 ];then
echo "edit $output"
"${DIRECTORY}/createapp" "$output"
elif [ $button == 12 ];then
echo "credits of $output"
cat "${DIRECTORY}/apps/${output}/credits" | yad --text-info --fontname=12 --wrap \
--image="${DIRECTORY}/apps/${output}/icon-64.png" --image-on-top \
--title="Credits of ${output}" --window-icon="${DIRECTORY}/icons/logo.png" --center --width=700 --height=300 \
--button=Close!"${DIRECTORY}/icons/exit.png":0
else
echo 'unknown button. Exiting now.'
exit 0
fi
fi
;;
2)
#uninstal
if ! echo "$output" | grep -q '/' ;then
uninstall "$output"
#clear output var to prompt main window to open next
else
motd="Sorry, you can"\'"t uninstall folders."
prefix=''
fi
output=''
;;
4)
#install
if ! echo "$output" | grep -q '/' ;then
install "$output"
#clear output var to prompt main window to open next
else
motd="Sorry, you can"\'"t install folders."
prefix=''
fi
output=''
;;
*)
error "Unknown button: $button"
;;
esac
done