4040COLOR_SLIDER_KNOB = DARKYELLOW
4141COLOR_SLIDER_INDICATOR = LIGHTPINK
4242
43-
43+ foreground_app_name = None
4444drawer = None
4545wifi_screen = None
4646drawer_open = False
@@ -212,7 +212,7 @@ def slider_event(e):
212212def wifi_event (e ):
213213 global drawer_open
214214 close_drawer ()
215- start_app ( "/builtin/apps/ com.example.wificonf" )
215+ start_app_by_name ( " com.example.wificonf" )
216216
217217wifi_btn .add_event_cb (wifi_event ,lv .EVENT .CLICKED ,None )
218218#
@@ -364,6 +364,17 @@ def execute_script_new_thread(scriptname, is_file, is_launcher, is_graphical):
364364 except Exception as e :
365365 print ("/main.py: execute_script_new_thread(): error starting new thread thread: " , e )
366366
367+ def start_app_by_name (app_name , is_launcher = False ):
368+ global foreground_app_name
369+ foreground_app_name = app_name
370+ custom_app_dir = f"/apps/{ app_name } "
371+ builtin_app_dir = f"/builtin/apps/{ app_name } "
372+ try :
373+ stat = uos .stat (custom_app_dir )
374+ start_app (custom_app_dir , is_launcher )
375+ except OSError :
376+ start_app (builtin_app_dir , is_launcher )
377+
367378def start_app (app_dir , is_launcher = False ):
368379 print (f"/main.py start_app({ app_dir } ,{ is_launcher } " )
369380 manifest_path = f"{ app_dir } /META-INF/MANIFEST.MF"
@@ -377,15 +388,8 @@ def start_app(app_dir, is_launcher=False):
377388 close_bar ()
378389
379390def restart_launcher ():
380- # The launcher might have been updated from the builtin one, so check that:
381- custom_launcher = "/apps/com.example.launcher"
382- builtin_launcher = "/builtin/apps/com.example.launcher"
383- try :
384- stat = uos .stat (custom_launcher )
385- start_app (custom_launcher , True )
386- except OSError :
387- start_app (builtin_launcher , True )
388-
391+ # No need to stop the other launcher first, because it exits after building the screen
392+ start_app_by_name ("com.example.launcher" , True )
389393
390394# Execute this if it exists
391395execute_script_new_thread ("/autorun.py" , True , False , False )
@@ -400,6 +404,7 @@ def restart_launcher():
400404import uos
401405custom_auto_connect = "/apps/com.example.wificonf/assets/auto_connect.py"
402406builtin_auto_connect = "/builtin/apps/com.example.wificonf/assets/auto_connect.py"
407+ # Maybe start_app_by_name() and start_app_by_name() could be merged so the try-except logic is not duplicated...
403408try :
404409 stat = uos .stat (custom_auto_connect )
405410 execute_script_new_thread (custom_auto_connect , True , False , False )
@@ -411,6 +416,7 @@ def restart_launcher():
411416 except OSError :
412417 print ("Couldn't execute {builtin_auto_connect}, continuing..." )
413418
419+
414420restart_launcher ()
415421
416422# If we got this far without crashing, then no need to rollback the update
0 commit comments