-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui
executable file
·316 lines (275 loc) · 11.2 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
#!/bin/bash
APP_STORE_NAME="LinStore"
APP_STORE_WIDTH=320
APP_STORE_HEIGHT=600
pwd
if ! command -v yad &>/dev/null; then
error "YAD needs to be installed to run LinStore."
fi
if [ -f "gui" ] || [ -f "createapp" ] || [ -f "settings" ]; then
cd .
else
cd ~/.linstore
fi
resolution=$(xrandr | grep " connected primary" | awk '{print $4}' | cut -d'+' -f1)
horizontal=$(echo $resolution | cut -d'x' -f1)
vertical=$(echo $resolution | cut -d'x' -f2)
let "categoryPos=$horizontal/2-360"
let "categoryPosY=$vertical/2-340"
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
}
read_categories() {
while read -r category; do
categories["$category"]=""
done <etc/categories
for app_dir in apps/*; do
app_name=$(basename "$app_dir")
if [ ! -e "apps/$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" > "apps/$app_name/category"
category_file="apps/$app_name/category"
else
continue
fi
else
continue
fi
fi
category_file="apps/$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)
app_details_page() {
kill $(pgrep -f "title=App Details")
sleep 0.1
pos=$(wmctrl -lG | grep "Category" | awk '{print $3,$4}')
x2=$((horizontal / 2 - 40))
y2=$((vertical / 2 - 340))
if [ -e "$HOME/.linstore/installscripts/${1//|/}" ]; then
installed="true"
else
installed="false"
fi
TITLE="App Details"
wmctrl -l | grep "$TITLE" | awk '{print $1}' | while read -r window_id; do
wmctrl -ic "$window_id"
done
local selected_app_name="${1//|/}"
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")
local install_command=$(./api install "$app_directory" "$selected_app_name")
local uninstall_command=$(./api uninstall "$app_directory" "$selected_app_name")
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'"
else
displayName="<b>${selected_app_name}</b> (<i>not installed</i>)"
buttonText="Install"
buttonImage="images/button/install.png"
buttonCommand="$install_command"
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
(
yad --class LinStore --title="App Details" --geometry=450x${APP_STORE_HEIGHT}+${x2}+${y2} --form \
--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" --skip-taskbar
)
rm -f /tmp/description.tmp
}
show_categories() {
list_items=()
for category in "${!categories[@]}"; do
category_icon="images/$category.png"
list_items+=("$category_icon")
list_items+=("$category")
done
selected_category_raw=$(GTK_THEME="${theme}" yad --text "Welcome to LinStore\nThe app store that's simple to use." --width="$APP_STORE_WIDTH" --height="$APP_STORE_HEIGHT" --columns="2" \
"${list_items[@]}" \
--list --image="images/logo-64.png" --window-icon="images/logo/logo-64.png" --image-on-top --title "$APP_STORE_NAME" --column "Icon:IMG" --column "Category" --button "Show Apps:3" --button "Settings:4" --item-padding="10")
selected_category="${selected_category_raw//|/}"
echo "$selected_category"
}
show_apps_in_category() {
while true; do
if [ "$1" == "All Apps" ]; then
# Show all apps in the "All Apps" category
all_apps_list=()
for app_dir in apps/*; do
app_name=$(basename "$app_dir")
app_icon="apps/$app_name/icon-24.png"
all_apps_list+=("$app_icon")
all_apps_list+=("$app_name")
done
GTK_THEME="${theme}" yad --text "<big><b>$1</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 "All Apps Category" --column "Icon:IMG" --column "Apps" \
--button="Back"!images/button/back.png!:4 --separator="\n" "${all_apps_list[@]}" --no-headers \
--dclick-action='bash -c "./gui showdetails \"%s\""'
else
apps_in_category="${category_apps["$1"]}"
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")
formatted_apps+=("$app")
done
GTK_THEME="${theme}" yad --text "<big><b>Apps in $1 Category</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 "$1 Category" --column "Icon:IMG" --column "Apps" \
--button="Back"!images/button/back.png!:4 --separator="\n" "${formatted_apps[@]}" --no-headers \
--select-action='bash -c "./gui showdetails \"%s\""'
fi
button_clicked=$?
if [ $button_clicked -eq 4 ]; then
show_app_store
break
fi
show_app_store
break
done
}
show_app_store() {
read_categories
# 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}" yad --text "$random_announcement" --geometry=${APP_STORE_WIDTH}x${APP_STORE_HEIGHT}+${categoryPos}+${categoryPosY} --center --columns="3" \
"${list_items[@]}" \
--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=$?
echo $exval
selected_category="${selected_category_raw//|/}"
if [ "$exval" == "44" ]; then
./api search && show_app_store
elif [ -n "$selected_category" ]; then
show_apps_in_category "$selected_category"
elif [ "$exval" -eq "252" ]; then
pkill -f "yad*"
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
else
detect_and_write_architecture
show_app_store
fi