1111import mpos .info
1212import mpos .ui
1313from mpos import Activity , Intent
14- from mpos .package_manager import PackageManager
14+ from mpos .content . pm import PackageManager
1515
1616def good_stack_size ():
1717 stacksize = 24 * 1024
@@ -21,7 +21,7 @@ def good_stack_size():
2121 return stacksize
2222
2323# Run the script in the current thread:
24- def execute_script (script_source , is_file , cwd = None , classname = None ):
24+ def execute_script (script_source , is_file , cwd = None , classname = None , app = None ):
2525 import utime # for timing read and compile
2626 thread_id = _thread .get_ident ()
2727 compile_name = 'script' if not is_file else script_source
@@ -63,7 +63,13 @@ def execute_script(script_source, is_file, cwd=None, classname=None):
6363 main_activity = script_globals .get (classname )
6464 if main_activity :
6565 start_time = utime .ticks_ms ()
66- Activity .startActivity (None , Intent (activity_class = main_activity ))
66+ from mpos .app .activity import Activity as BaseActivity
67+ if app :
68+ dummy = BaseActivity ()
69+ dummy .app = app
70+ returned_activity = dummy .startActivity (Intent (activity_class = main_activity ))
71+ else :
72+ print ("Warning: app not found in PackageManager" )
6773 end_time = utime .ticks_diff (utime .ticks_ms (), start_time )
6874 print (f"execute_script: Activity.startActivity took { end_time } ms" )
6975 else :
@@ -123,7 +129,7 @@ def start_app(fullname):
123129 print (f"WARNING: start_app can't start { fullname } because it doesn't have a main_launcher_activity" )
124130 return
125131 start_script_fullpath = f"{ app .installed_path } /{ app .main_launcher_activity .get ('entrypoint' )} "
126- execute_script (start_script_fullpath , True , app .installed_path + "/assets/" , app .main_launcher_activity .get ("classname" ))
132+ execute_script (start_script_fullpath , True , app .installed_path + "/assets/" , app .main_launcher_activity .get ("classname" ), app )
127133 # Launchers have the bar, other apps don't have it
128134 if app .is_valid_launcher ():
129135 mpos .ui .topmenu .open_bar ()
@@ -137,7 +143,7 @@ def restart_launcher():
137143 print ("restart_launcher" )
138144 mpos .ui .empty_screen_stack ()
139145 # No need to stop the other launcher first, because it exits after building the screen
140- for app in mpos . package_manager . PackageManager .get_app_list ():
146+ for app in PackageManager .get_app_list ():
141147 if app .is_valid_launcher ():
142148 print (f"Found launcher, starting { app .fullname } " )
143149 start_app (app .fullname )
0 commit comments