Skip to content

Commit ad5565c

Browse files
App framework: simplify MANIFEST.JSON
Make launcher, entrypoint and classname optional by defaulting to "assets/main.py" with class "Main".
1 parent b984431 commit ad5565c

File tree

2 files changed

+18
-30
lines changed

2 files changed

+18
-30
lines changed

internal_filesystem/apps/com.micropythonos.doom_launcher/META-INF/MANIFEST.JSON

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,10 @@
33
"publisher": "MicroPythonOS",
44
"short_description": "Legendary 3D shooter",
55
"long_description": "Plays Doom 1, 2 and modded .wad files from internal storage or SD card and plays them. Place them in the folder /roms/doom/ . Uses ducalex's retro-go port of PrBoom. Supports zipped wad files too.",
6-
"icon_url": "https://apps.micropythonos.com/apps/com.micropythonos.doom/icons/com.micropythonos.doom_0.0.1_64x64.png",
7-
"download_url": "https://apps.micropythonos.com/apps/com.micropythonos.doom/mpks/com.micropythonos.doom_0.0.1.mpk",
8-
"fullname": "com.micropythonos.doom",
6+
"icon_url": "https://apps.micropythonos.com/apps/com.micropythonos.doom/icons/com.micropythonos.doom_launcher_0.0.1_64x64.png",
7+
"download_url": "https://apps.micropythonos.com/apps/com.micropythonos.doom/mpks/com.micropythonos.doom_launcher_0.0.1.mpk",
8+
"fullname": "com.micropythonos.doom_launcher",
99
"version": "0.0.1",
1010
"category": "games",
11-
"activities": [
12-
{
13-
"entrypoint": "assets/main.py",
14-
"classname": "Main",
15-
"intent_filters": [
16-
{
17-
"action": "main",
18-
"category": "launcher"
19-
}
20-
]
21-
}
22-
]
2311
}
2412

internal_filesystem/lib/mpos/apps.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def good_stack_size():
1818

1919
# Run the script in the current thread:
2020
# Returns True if successful
21-
def execute_script(script_source, is_file, cwd=None, classname=None):
21+
def execute_script(script_source, is_file, classname, cwd=None):
2222
import utime # for timing read and compile
2323
thread_id = _thread.get_ident()
2424
compile_name = 'script' if not is_file else script_source
@@ -50,23 +50,20 @@ def execute_script(script_source, is_file, cwd=None, classname=None):
5050
end_time = utime.ticks_diff(utime.ticks_ms(), start_time)
5151
print(f"apps.py execute_script: exec took {end_time}ms")
5252
# Introspect globals
53-
#classes = {k: v for k, v in script_globals.items() if isinstance(v, type)}
54-
#functions = {k: v for k, v in script_globals.items() if callable(v) and not isinstance(v, type)}
55-
#variables = {k: v for k, v in script_globals.items() if not callable(v)}
56-
#print("Classes:", classes.keys())
57-
#print("Functions:", functions.keys())
58-
#print("Variables:", variables.keys())
59-
if not classname:
60-
print("Running without a classname isn't supported right now.")
61-
return False
53+
classes = {k: v for k, v in script_globals.items() if isinstance(v, type)}
54+
functions = {k: v for k, v in script_globals.items() if callable(v) and not isinstance(v, type)}
55+
variables = {k: v for k, v in script_globals.items() if not callable(v)}
56+
print("Classes:", classes.keys()) # This lists a whole bunch of classes, including lib/mpos/ stuff
57+
print("Functions:", functions.keys())
58+
print("Variables:", variables.keys())
6259
main_activity = script_globals.get(classname)
6360
if main_activity:
6461
start_time = utime.ticks_ms()
6562
Activity.startActivity(None, Intent(activity_class=main_activity))
6663
end_time = utime.ticks_diff(utime.ticks_ms(), start_time)
6764
print(f"execute_script: Activity.startActivity took {end_time}ms")
6865
else:
69-
print(f"Warning: could not find app's main_activity {main_activity}")
66+
print(f"Warning: could not find app's main_activity {classname}")
7067
return False
7168
except Exception as e:
7269
print(f"Thread {thread_id}: exception during execution:")
@@ -125,11 +122,14 @@ def start_app(fullname):
125122
if not app.installed_path:
126123
print(f"Warning: start_app can't start {fullname} because no it doesn't have an installed_path")
127124
return
125+
entrypoint = "assets/main.py"
126+
classname = "Main"
128127
if not app.main_launcher_activity:
129-
print(f"WARNING: start_app can't start {fullname} because it doesn't have a main_launcher_activity")
130-
return
131-
start_script_fullpath = f"{app.installed_path}/{app.main_launcher_activity.get('entrypoint')}"
132-
result = execute_script(start_script_fullpath, True, app.installed_path + "/assets/", app.main_launcher_activity.get("classname"))
128+
print(f"WARNING: app {fullname} doesn't have a main_launcher_activity, defaulting to class {classname} in {entrypoint}")
129+
else:
130+
entrypoint = app.main_launcher_activity.get('entrypoint')
131+
classname = app.main_launcher_activity.get("classname")
132+
result = execute_script(app.installed_path + "/" + entrypoint, True, classname, app.installed_path + "/assets/")
133133
# Launchers have the bar, other apps don't have it
134134
if app.is_valid_launcher():
135135
mpos.ui.topmenu.open_bar()

0 commit comments

Comments
 (0)