Skip to content

Commit 3828a5f

Browse files
Apps: cache main_launcher_activity
1 parent 056db40 commit 3828a5f

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

internal_filesystem/lib/mpos/apps.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def execute_script_new_thread(scriptname, is_file):
9393
if "camtest" in scriptname:
9494
print("Starting camtest with extra stack size!")
9595
stack=32*1024
96-
elif "appstore"in scriptname:
96+
elif "appstore" in scriptname:
9797
print("Starting appstore with extra stack size!")
9898
stack=24*1024 # this doesn't do anything because it's all started in the same thread
9999
else:
@@ -111,17 +111,16 @@ def start_app(fullname):
111111
start_time = utime.ticks_ms()
112112
app = PackageManager.get(fullname)
113113
if not app:
114-
print(f"Warning: start_app could not find app {fullname}, aborting...")
114+
print(f"Warning: start_app can't find app {fullname}")
115115
return
116116
if not app.installed_path:
117-
print(f"Warning: start_app could not find installed_path for {fullname}, aborting...")
117+
print(f"Warning: start_app can't start {fullname} because no it doesn't have an installed_path")
118118
return
119-
main_launcher_activity = PackageManager.find_main_launcher_activity(app)
120-
if not main_launcher_activity:
121-
print(f"WARNING: can't start {fullname} because no main_launcher_activity was found.")
119+
if not app.main_launcher_activity:
120+
print(f"WARNING: start_app can't start {fullname} because it doesn't have a main_launcher_activity")
122121
return
123-
start_script_fullpath = f"{app.installed_path}/{main_launcher_activity.get('entrypoint')}"
124-
execute_script(start_script_fullpath, True, app.installed_path + "/assets/", main_launcher_activity.get("classname"))
122+
start_script_fullpath = f"{app.installed_path}/{app.main_launcher_activity.get('entrypoint')}"
123+
execute_script(start_script_fullpath, True, app.installed_path + "/assets/", app.main_launcher_activity.get("classname"))
125124
# Launchers have the bar, other apps don't have it
126125
if PackageManager.is_launcher(fullname):
127126
mpos.ui.topmenu.open_bar()
@@ -137,7 +136,7 @@ def restart_launcher():
137136
# No need to stop the other launcher first, because it exits after building the screen
138137
for app in mpos.package_manager.PackageManager.get_app_list():
139138
#print(f"checking {app}")
140-
if app.category == "launcher" and PackageManager.find_main_launcher_activity(app):
139+
if app.category == "launcher" and app.main_launcher_activity: # if it's a launcher and it has a main_launcher_activity
141140
print(f"Found launcher, starting {app.fullname}")
142141
start_app(app.fullname)
143142

@@ -157,6 +156,7 @@ def __init__(self, name, publisher, short_description, long_description, icon_ur
157156
self.image_dsc = None
158157
self.activities = activities
159158
self.installed_path = installed_path
159+
self.main_launcher_activity = self._find_main_launcher_activity()
160160

161161
def __str__(self):
162162
return (f"App(name='{self.name}', "
@@ -167,6 +167,22 @@ def __str__(self):
167167
f"activities='{self.activities}', "
168168
f"installed_path={self.installed_path})")
169169

170+
def _find_main_launcher_activity(self):
171+
result = None
172+
for activity in self.activities:
173+
if not activity.get("entrypoint") or not activity.get("classname"):
174+
print(f"Warning: activity {activity} has no entrypoint and classname, skipping...")
175+
continue
176+
print("checking activity's intent_filters...")
177+
for intent_filter in activity.get("intent_filters"):
178+
print("checking intent_filter...")
179+
if intent_filter.get("action") == "main" and intent_filter.get("category") == "launcher":
180+
print("found main_launcher!")
181+
result = activity
182+
break
183+
return result
184+
185+
170186
def parse_manifest(appdir):
171187
print(f"parse_manifest({appdir})")
172188
manifest_path = f"{appdir}/META-INF/MANIFEST.JSON"

internal_filesystem/lib/mpos/package_manager.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -220,22 +220,6 @@ def is_installed_by_name(app_fullname):
220220
print(f"Checking if app {app_fullname} is installed...")
221221
return PackageManager.is_installed_by_path(f"apps/{app_fullname}") or PackageManager.is_installed_by_path(f"builtin/apps/{app_fullname}")
222222

223-
@staticmethod
224-
def find_main_launcher_activity(app):
225-
result = None
226-
for activity in app.activities:
227-
if not activity.get("entrypoint") or not activity.get("classname"):
228-
print(f"Warning: activity {activity} has no entrypoint and classname, skipping...")
229-
continue
230-
print("checking activity's intent_filters...")
231-
for intent_filter in activity.get("intent_filters"):
232-
print("checking intent_filter...")
233-
if intent_filter.get("action") == "main" and intent_filter.get("category") == "launcher":
234-
print("found main_launcher!")
235-
result = activity
236-
break
237-
return result
238-
239223
@staticmethod
240224
def is_launcher(app_name):
241225
print(f"checking is_launcher for {app_name}")

0 commit comments

Comments
 (0)