2020
2121progress_bar = None
2222
23- refresh_icons_period = 300
24-
2523action_label_install = "Install"
2624action_label_uninstall = "Uninstall"
2725action_label_restore = "Restore Built-in"
@@ -228,7 +226,7 @@ def download_apps(json_url):
228226 response = urequests .get (json_url , timeout = 10 )
229227 except Exception as e :
230228 print ("Download failed:" , e )
231- please_wait_label .set_text (f"Error downloading app index: { e } " )
229+ lv . async_call ( lambda l : please_wait_label .set_text (f"Error downloading app index: { e } " ), None )
232230 if response and response .status_code == 200 :
233231 print (f"Got response text: { response .text } " )
234232 apps = [mpos .apps .App (** app ) for app in json .loads (response .text )]
@@ -239,18 +237,16 @@ def download_apps(json_url):
239237 # Sort apps by app.name
240238 apps .sort (key = lambda x : x .name .lower ()) # Use .lower() for case-insensitive sorting
241239 please_wait_label .add_flag (lv .obj .FLAG .HIDDEN )
242- create_apps_list ()
240+ lv . async_call ( lambda l : create_apps_list (), None )
243241
244242def download_icons ():
245243 for app in apps :
246244 print ("Downloading icon for app " )
247245 image_dsc = download_icon (app .icon_url )
248- app .image_dsc = image_dsc
249- print ("Finished downloading icons, scheduling stop of refresh timer..." )
250- # One more fresh is needed, so this needs to be scheduled after the next icon refresh
251- refresh_icons_pause = lv .timer_create (lambda l : refresh_icons .pause (), refresh_icons_period , None )
252- refresh_icons_pause .set_repeat_count (1 )
253- refresh_icons_pause .set_auto_delete (False )
246+ app .image_dsc = image_dsc # save it for the app detail page
247+ lv .async_call (lambda l , id = app .image_dsc : app .image .set_src (id ), None )
248+ time .sleep_ms (50 ) # wait until image updated
249+ print ("Finished downloading icons..." )
254250
255251
256252def load_icon (icon_path ):
@@ -423,24 +419,15 @@ def back_to_main(event):
423419 lv .screen_load (appscreen )
424420
425421
426- def refresh_icons_cb (timer ):
427- #print("Refreshing app icons...")
428- for app in apps :
429- #print("Refreshing icon for {app.name}")
430- if app .image_dsc :
431- app .image .set_src (app .image_dsc )
432-
433422def janitor_cb (timer ):
434423 global appscreen , app_detail_screen
435424 if lv .screen_active () != appscreen and lv .screen_active () != app_detail_screen :
436425 print ("appstore.py backgrounded, cleaning up..." )
437426 janitor .delete ()
438- refresh_icons .delete ()
439427 restart_launcher () # refresh the launcher
440428 print ("appstore.py ending" )
441429
442430janitor = lv .timer_create (janitor_cb , 400 , None )
443- refresh_icons = lv .timer_create (refresh_icons_cb , refresh_icons_period , None )
444431
445432please_wait_label = lv .label (appscreen )
446433please_wait_label .set_text ("Downloading app index..." )
0 commit comments