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 ():
1717stacksize = 24 * 1024
@@ -21,7 +21,7 @@ def good_stack_size():
2121return 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 ):
2525import utime # for timing read and compile
2626thread_id = _thread .get_ident ()
2727compile_name = 'script' if not is_file else script_source
@@ -63,7 +63,13 @@ def execute_script(script_source, is_file, cwd=None, classname=None):
6363main_activity = script_globals .get (classname )
6464if main_activity :
6565start_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" )
6773end_time = utime .ticks_diff (utime .ticks_ms (),start_time )
6874print (f"execute_script: Activity.startActivity took{ end_time } ms" )
6975else :
@@ -123,7 +129,7 @@ def start_app(fullname):
123129print (f"WARNING: start_app can't start{ fullname } because it doesn't have a main_launcher_activity" )
124130return
125131start_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
128134if app .is_valid_launcher ():
129135mpos .ui .topmenu .open_bar ()
@@ -137,7 +143,7 @@ def restart_launcher():
137143print ("restart_launcher" )
138144mpos .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 ():
141147if app .is_valid_launcher ():
142148print (f"Found launcher, starting{ app .fullname } " )
143149start_app (app .fullname )