Skip to content

Commit 163511f

Browse files
Dependency hell
1 parent c2c5089 commit 163511f

File tree

12 files changed

+67
-51
lines changed

12 files changed

+67
-51
lines changed

internal_filesystem/builtin/apps/com.micropythonos.appstore/assets/appstore.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from mpos.apps import Activity, Intent
1010
from mpos.app import App
1111
import mpos.ui
12-
from mpos.package_manager import PackageManager
12+
from mpos.content.pm import PackageManager
1313

1414

1515
class AppStore(Activity):

internal_filesystem/builtin/apps/com.micropythonos.launcher/assets/launcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import mpos.apps
1616
import mpos.ui
17-
from mpos.package_manager import PackageManager
17+
from mpos.content.pm import PackageManager
1818
from mpos import Activity
1919

2020
class Launcher(Activity):

internal_filesystem/lib/mpos/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from .app.activity import Activity
44
from .content.intent import Intent
55
from .navigator import ActivityNavigator
6-
from .package_manager import PackageManager
6+
from .content.pm import PackageManager
77

88
# Optional: re-export activities
99
from .app.activities.chooser import ChooserActivity

internal_filesystem/lib/mpos/app/activities/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Import all activity modules → triggers self-registration
12
from .chooser import ChooserActivity
23
from .view import ViewActivity
34
from .share import ShareActivity

internal_filesystem/lib/mpos/app/activities/chooser.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from ..activity import Activity
2+
# Chooser doesn't handle an action — it shows handlers
3+
# → No registration needed
24

3-
import mpos.package_manager
5+
from ...content.pm import PackageManager
46

57
class ChooserActivity(Activity):
68
def __init__(self):
@@ -25,7 +27,7 @@ def onCreate(self):
2527
self.setContentView(screen)
2628

2729
def _select_handler(self, handler_name, original_intent):
28-
for handler in mpos.package_manager.PackageManager.APP_REGISTRY.get(original_intent.action, []):
30+
for handler in PackageManager.APP_REGISTRY.get(original_intent.action, []):
2931
if handler.__name__ == handler_name:
3032
original_intent.activity_class = handler
3133
navigator.startActivity(original_intent)
@@ -37,3 +39,5 @@ def onStop(self, screen):
3739
print("Stopped for Chooser")
3840
else:
3941
print("Stopped for other screen")
42+
43+

internal_filesystem/lib/mpos/app/activities/share.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from ..activity import Activity
2+
from ...content.pm import PackageManager
23

34
class ShareActivity(Activity):
45
def __init__(self):
@@ -33,3 +34,5 @@ def onStop(self, screen):
3334
print("Stopped for Share")
3435
else:
3536
print("Stopped for other screen")
37+
38+
PackageManager.register_activity("share", ShareActivity)

internal_filesystem/lib/mpos/app/activities/view.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from ..activity import Activity
2+
from ...content.pm import PackageManager
23

34
class ViewActivity(Activity):
45
def __init__(self):
@@ -25,3 +26,6 @@ def onStop(self, screen):
2526
print("Stopped for View")
2627
else:
2728
print("Stopped for other screen")
29+
30+
# Register this activity for "view" intents
31+
PackageManager.register_activity("view", ViewActivity)

internal_filesystem/lib/mpos/app/activity.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from mpos.navigator import ActivityNavigator
1+
#from mpos.navigator import ActivityNavigator
22

33
import mpos.ui
44

@@ -26,7 +26,10 @@ def setContentView(self, screen):
2626
mpos.ui.setContentView(self, screen)
2727

2828
def startActivity(self, intent):
29-
ActivityNavigator.startActivity(intent)
29+
if not hasattr(self, 'app') or not self.app:
30+
print("ERROR: Activity has no .app – cannot startActivity")
31+
return
32+
self.app.start_activity(intent)
3033

3134
def startActivityForResult(self, intent, result_callback):
3235
ActivityNavigator.startActivityForResult(intent, result_callback)

internal_filesystem/lib/mpos/app/app.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import ujson
22
#from ..content.intent import Intent # optional, if App uses Intent
3-
3+
from ..navigator import ActivityNavigator
44

55
class App:
66
def __init__(
@@ -71,3 +71,7 @@ def from_manifest(cls, appdir):
7171
activities=data.get("activities", default.activities),
7272
installed_path=appdir,
7373
)
74+
75+
def start_activity(self, intent):
76+
"""Android-like: App.startActivity(Intent)"""
77+
return ActivityNavigator.startActivity(intent)

internal_filesystem/lib/mpos/apps.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import mpos.info
1212
import mpos.ui
1313
from mpos import Activity, Intent
14-
from mpos.package_manager import PackageManager
14+
from mpos.content.pm import PackageManager
1515

1616
def 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

Comments
 (0)