1010
1111# Screens:
1212app_detail_screen = None
13+ appscreen = lv .screen_active ()
1314
1415apps = []
1516update_button = None
1819please_wait_label = None
1920
2021progress_bar = None
21- keepdownloadingicons = False
22+
23+ refresh_icons_period = 300
2224
2325action_label_install = "Install"
2426action_label_uninstall = "Uninstall"
@@ -240,15 +242,16 @@ def download_apps(json_url):
240242 create_apps_list ()
241243
242244def download_icons ():
243- global apps
244245 for app in apps :
245246 print ("Downloading icon for app " )
246- if not keepdownloadingicons :
247- break
248247 image_dsc = download_icon (app .icon_url )
249248 app .image_dsc = image_dsc
250249 print ("Finished downloading icons, scheduling stop of refresh timer..." )
251- lv .async_call (lambda l : refresh_icons .pause (), None )
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 )
254+
252255
253256def load_icon (icon_path ):
254257 with open (icon_path , 'rb' ) as f :
@@ -297,8 +300,6 @@ def create_apps_list():
297300 desc_label .add_event_cb (lambda e , a = app : show_app_detail (a ), lv .EVENT .CLICKED , None )
298301 print ("create_apps_list app done" )
299302 try :
300- global keepdownloadingicons
301- keepdownloadingicons = True
302303 _thread .stack_size (32 * 1024 ) # seems to need 32KB for urequests
303304 _thread .start_new_thread (download_icons ,())
304305 except Exception as e :
@@ -426,28 +427,25 @@ def refresh_icons_cb(timer):
426427 #print("Refreshing app icons...")
427428 for app in apps :
428429 #print("Refreshing icon for {app.name}")
429- app .image .set_src (app .image_dsc )
430+ if app .image_dsc :
431+ app .image .set_src (app .image_dsc )
430432
431433def janitor_cb (timer ):
432434 global appscreen , app_detail_screen
433435 if lv .screen_active () != appscreen and lv .screen_active () != app_detail_screen :
434436 print ("appstore.py backgrounded, cleaning up..." )
435437 janitor .delete ()
436438 refresh_icons .delete ()
437- appscreen .clean ()
438- appscreen .delete ()
439439 restart_launcher () # refresh the launcher
440440 print ("appstore.py ending" )
441441
442- janitor = lv .timer_create (janitor_cb , 800 , None )
443- refresh_icons = lv .timer_create (refresh_icons_cb , 500 , None )
442+ janitor = lv .timer_create (janitor_cb , 400 , None )
443+ refresh_icons = lv .timer_create (refresh_icons_cb , refresh_icons_period , None )
444444
445445please_wait_label = lv .label (appscreen )
446446please_wait_label .set_text ("Downloading app index..." )
447447please_wait_label .center ()
448448
449- appscreen = lv .screen_active ()
450-
451449can_check_network = True
452450try :
453451 import network
@@ -457,6 +455,6 @@ def janitor_cb(timer):
457455if can_check_network and not network .WLAN (network .STA_IF ).isconnected ():
458456 please_wait_label .set_text ("Error: WiFi is not connected." )
459457else :
460- _thread .stack_size (32 * 1024 )
458+ _thread .stack_size (16 * 1024 )
461459 _thread .start_new_thread (download_apps , ("http://demo.lnpiggy.com:2121/apps.json" ,))
462460
0 commit comments