@@ -18,6 +18,7 @@ class AppStore(Activity):
1818 apps = []
1919 app_index_url = "https://apps.micropythonos.com/app_index.json"
2020 can_check_network = True
21+ keep_running = False
2122
2223 # Widgets:
2324 main_screen = None
@@ -35,8 +36,9 @@ def onCreate(self):
3536 self .setContentView (self .main_screen )
3637
3738 def onResume (self , screen ):
39+ self .keep_running = True
3840 if len (self .apps ):
39- return
41+ return # already downloaded them
4042 try :
4143 import network
4244 except Exception as e :
@@ -47,12 +49,16 @@ def onResume(self, screen):
4749 _thread .stack_size (mpos .apps .good_stack_size ())
4850 _thread .start_new_thread (self .download_app_index , (self .app_index_url ,))
4951
52+ def onStop (self , screen ):
53+ self .keep_running = False
54+
5055 def download_app_index (self , json_url ):
5156 try :
5257 response = requests .get (json_url , timeout = 10 )
5358 except Exception as e :
5459 print ("Download failed:" , e )
55- lv .async_call (lambda l , error = e : self .please_wait_label .set_text (f"Downloading app index from:\n { json_url } \n got error: { error } " ), None )
60+ if self .keep_running :
61+ lv .async_call (lambda l , error = e : self .please_wait_label .set_text (f"App index download \n { json_url } \n got error: { error } " ), None )
5662 return
5763 if response and response .status_code == 200 :
5864 #print(f"Got response text: {response.text}")
@@ -69,8 +75,9 @@ def download_app_index(self, json_url):
6975 # Sort apps by app.name
7076 self .apps .sort (key = lambda x : x .name .lower ()) # Use .lower() for case-insensitive sorting
7177 time .sleep_ms (200 )
72- lv .async_call (lambda l : self .please_wait_label .add_flag (lv .obj .FLAG .HIDDEN ), None )
73- lv .async_call (lambda l : self .create_apps_list (), None )
78+ if self .keep_running :
79+ lv .async_call (lambda l : self .please_wait_label .add_flag (lv .obj .FLAG .HIDDEN ), None )
80+ lv .async_call (lambda l : self .create_apps_list (), None )
7481 except Exception as e :
7582 print (f"ERROR: could not parse reponse.text JSON: { e } " )
7683 finally :
@@ -133,6 +140,8 @@ def download_icons(self):
133140 print (f"Downloading icon for { app .name } " )
134141 image_dsc = self .download_icon (app .icon_url )
135142 app .image_dsc = image_dsc # save it for the app detail page
143+ if not self .keep_running :
144+ break
136145 lv .async_call (lambda l : app .image .set_src (image_dsc ), None )
137146 time .sleep_ms (200 ) # not waiting here will result in some async_calls() not being executed
138147 print ("Finished downloading icons..." )
0 commit comments