Skip to content

Commit 18a8d86

Browse files
appstore: download icons in separate thread
1 parent 221ab9b commit 18a8d86

File tree

1 file changed

+31
-6
lines changed
  • internal_filesystem/builtin/apps/com.example.appstore/assets

1 file changed

+31
-6
lines changed

internal_filesystem/builtin/apps/com.example.appstore/assets/appstore.py

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ def __init__(self, name, publisher, short_description, long_description, icon_ur
2323
self.short_description = short_description
2424
self.long_description = long_description
2525
self.icon_url = icon_url
26-
self.image_dsc = None
2726
self.download_url = download_url
2827
self.fullname = fullname
2928
self.version = version
30-
29+
self.image = None
30+
self.image_dsc = None
3131

3232
def is_installed_by_path(dir_path):
3333
try:
@@ -43,7 +43,7 @@ def is_installed_by_name(app_fullname):
4343
print(f"Checking if app {app_fullname} is installed...")
4444
return is_installed_by_path(f"/apps/{app_fullname}") or is_installed_by_path(f"/builtin/apps/{app_fullname}")
4545

46-
def load_icon(url):
46+
def download_icon(url):
4747
print(f"downloading icon from {url}")
4848
response = urequests.get(url, timeout=5)
4949
if response.status_code == 200:
@@ -163,8 +163,27 @@ def download_apps(json_url):
163163
please_wait_label.set_text(f"Error downloading app index: {e}")
164164

165165

166+
def download_icons():
167+
global apps
168+
for app in apps:
169+
image_dsc = download_icon(app.icon_url)
170+
app.image_dsc = image_dsc
171+
app.image.set_src(image_dsc)
172+
print(f"Changed image_dsc for {app.icon_url}")
173+
print("finished downloading all icons")
174+
175+
def load_icon(icon_path):
176+
with open(icon_path, 'rb') as f:
177+
image_data = f.read()
178+
image_dsc = lv.image_dsc_t({
179+
'data_size': len(image_data),
180+
'data': image_data
181+
})
182+
return image_dsc
183+
166184
def create_apps_list():
167185
global apps
186+
default_icon_dsc = load_icon("/builtin/res/mipmap-mdpi/default_icon_64x64.png")
168187
print("create_apps_list")
169188
apps_list = lv.list(mainscreen)
170189
apps_list.set_style_pad_all(0, 0)
@@ -182,11 +201,12 @@ def create_apps_list():
182201
cont.set_size(lv.pct(100), lv.SIZE_CONTENT)
183202
cont.set_scrollbar_mode(lv.SCROLLBAR_MODE.OFF)
184203
cont.add_event_cb(lambda e, a=app: show_app_detail(a), lv.EVENT.CLICKED, None)
185-
image_dsc = load_icon(app.icon_url)
186-
app.image_dsc = image_dsc
187204
icon_spacer = lv.image(cont)
188-
icon_spacer.set_src(image_dsc)
205+
#image_dsc = default_icon_dsc
206+
#app.image_dsc = image_dsc
207+
#icon_spacer.set_src(image_dsc)
189208
icon_spacer.set_size(64, 64)
209+
app.image = icon_spacer
190210
icon_spacer.add_event_cb(lambda e, a=app: show_app_detail(a), lv.EVENT.CLICKED, None)
191211
label_cont = lv.obj(cont)
192212
label_cont.set_flex_flow(lv.FLEX_FLOW.COLUMN)
@@ -202,6 +222,11 @@ def create_apps_list():
202222
desc_label.add_event_cb(lambda e, a=app: show_app_detail(a), lv.EVENT.CLICKED, None)
203223
print("create_apps_list app one done")
204224
print("create_apps_list app done")
225+
try:
226+
_thread.stack_size(16384)
227+
_thread.start_new_thread(download_icons,())
228+
except Exception as e:
229+
print("Could not start thread to download icons: ", e)
205230

206231

207232
def show_app_detail(app):

0 commit comments

Comments
 (0)