Skip to content

Commit c2ae169

Browse files
Rename PackageManager to AppManager
1 parent 31dcfba commit c2ae169

29 files changed

+123
-124
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import json
33
import lvgl as lv
44

5-
from mpos import Activity, DownloadManager, PackageManager, TaskManager
5+
from mpos import Activity, DownloadManager, AppManager, TaskManager
66

77
class AppDetail(Activity):
88

@@ -142,7 +142,7 @@ def add_action_buttons(self, buttoncont, app):
142142
self.install_label = lv.label(self.install_button)
143143
self.install_label.center()
144144
self.set_install_label(self.app.fullname)
145-
if app.version and PackageManager.is_update_available(self.app.fullname, app.version):
145+
if app.version and AppManager.is_update_available(self.app.fullname, app.version):
146146
self.install_button.set_size(lv.pct(47), 40) # make space for update button
147147
print("Update available, adding update button.")
148148
self.update_button = lv.button(buttoncont)
@@ -171,10 +171,10 @@ def set_install_label(self, app_fullname):
171171
# - update is separate button, only shown if already installed and new version
172172
is_installed = True
173173
update_available = False
174-
builtin_app = PackageManager.is_builtin_app(app_fullname)
175-
overridden_builtin_app = PackageManager.is_overridden_builtin_app(app_fullname)
174+
builtin_app = AppManager.is_builtin_app(app_fullname)
175+
overridden_builtin_app = AppManager.is_overridden_builtin_app(app_fullname)
176176
if not overridden_builtin_app:
177-
is_installed = PackageManager.is_installed_by_name(app_fullname)
177+
is_installed = AppManager.is_installed_by_name(app_fullname)
178178
if is_installed:
179179
if builtin_app:
180180
if overridden_builtin_app:
@@ -214,12 +214,12 @@ async def uninstall_app(self, app_fullname):
214214
self._show_progress_bar()
215215
await self._update_progress(21)
216216
await self._update_progress(42)
217-
PackageManager.uninstall_app(app_fullname)
217+
AppManager.uninstall_app(app_fullname)
218218
await self._update_progress(100, wait=False)
219219
self._hide_progress_bar()
220220
self.set_install_label(app_fullname)
221221
self.install_button.remove_state(lv.STATE.DISABLED)
222-
if PackageManager.is_builtin_app(app_fullname):
222+
if AppManager.is_builtin_app(app_fullname):
223223
self.update_button.remove_flag(lv.obj.FLAG.HIDDEN)
224224
self.install_button.set_size(lv.pct(47), 40) # if a builtin app was removed, then it was overridden, and a new version is available, so make space for update button
225225

@@ -256,7 +256,7 @@ async def download_and_install(self, app_obj, dest_folder):
256256
else:
257257
print("Downloaded .mpk file, size:", os.stat(temp_zip_path)[6], "bytes")
258258
# Install it:
259-
PackageManager.install_mpk(temp_zip_path, dest_folder) # 60 until 80 percent is the unzip but no progress there...
259+
AppManager.install_mpk(temp_zip_path, dest_folder) # 60 until 80 percent is the unzip but no progress there...
260260
await self._update_progress(80, wait=False)
261261
except Exception as e:
262262
print(f"Download failed with exception: {e}")

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# All icons took: 1250ms
1010
# Most of this time is actually spent reading and parsing manifests.
1111
import lvgl as lv
12-
from mpos import AppearanceManager, PackageManager, Activity, DisplayMetrics
12+
from mpos import AppearanceManager, AppManager, Activity, DisplayMetrics
1313
import time
1414
import uhashlib
1515
import ubinascii
@@ -54,7 +54,7 @@ def onResume(self, screen):
5454
# ------------------------------------------------------------------
5555
# 1. Build a *compact* representation of the current app list
5656
current_apps = []
57-
for app in PackageManager.get_app_list():
57+
for app in AppManager.get_app_list():
5858
if app.category == "launcher":
5959
continue
6060
icon_hash = Launcher._hash_file(app.icon_path) # cheap SHA-1 of the icon file
@@ -90,7 +90,7 @@ def onResume(self, screen):
9090
iconcont_width = icon_size + label_height
9191
iconcont_height = icon_size + label_height
9292

93-
for app in PackageManager.get_app_list():
93+
for app in AppManager.get_app_list():
9494
if app.category == "launcher":
9595
continue
9696

@@ -128,7 +128,7 @@ def onResume(self, screen):
128128

129129
# ----- events --------------------------------------------------
130130
app_cont.add_event_cb(
131-
lambda e, fullname=app.fullname: PackageManager.start_app(fullname),
131+
lambda e, fullname=app.fullname: AppManager.start_app(fullname),
132132
lv.EVENT.CLICKED, None)
133133
app_cont.add_event_cb(
134134
lambda e, cont=app_cont: self.focus_app_cont(cont),

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import ujson
33
import time
44

5-
from mpos import Activity, PackageManager, ConnectivityManager, TaskManager, DownloadManager, DisplayMetrics, DeviceInfo, BuildInfo
5+
from mpos import Activity, AppManager, ConnectivityManager, TaskManager, DownloadManager, DisplayMetrics, DeviceInfo, BuildInfo
66

77
class OSUpdate(Activity):
88

@@ -770,7 +770,7 @@ def is_update_available(self, remote_version, current_version):
770770
Returns:
771771
bool: True if remote version is newer
772772
"""
773-
return PackageManager.compare_versions(remote_version, current_version)
773+
return AppManager.compare_versions(remote_version, current_version)
774774

775775

776776
# Non-class functions:

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import lvgl as lv
22

3-
from mpos import Intent, PackageManager, SettingActivity, SettingsActivity, TimeZone
3+
from mpos import Intent, AppManager, SettingActivity, SettingsActivity, TimeZone
44

55
from calibrate_imu import CalibrateIMUActivity
66
from check_imu_calibration import CheckIMUCalibrationActivity
@@ -44,7 +44,7 @@ def getIntent(self):
4444
{"title": "Theme Color", "key": "theme_primary_color", "placeholder": "HTML hex color, like: EC048C", "ui": "dropdown", "ui_options": theme_colors, "changed_callback": self.theme_changed},
4545
{"title": "Timezone", "key": "timezone", "ui": "dropdown", "ui_options": [(tz, tz) for tz in TimeZone.get_timezones()], "changed_callback": lambda *args: mpos.time.refresh_timezone_preference()},
4646
# Advanced settings, alphabetically:
47-
{"title": "Auto Start App", "key": "auto_start_app", "ui": "radiobuttons", "ui_options": [(app.name, app.fullname) for app in PackageManager.get_app_list()]},
47+
{"title": "Auto Start App", "key": "auto_start_app", "ui": "radiobuttons", "ui_options": [(app.name, app.fullname) for app in AppManager.get_app_list()]},
4848
{"title": "Check IMU Calibration", "key": "check_imu_calibration", "ui": "activity", "activity_class": CheckIMUCalibrationActivity},
4949
{"title": "Calibrate IMU", "key": "calibrate_imu", "ui": "activity", "activity_class": CalibrateIMUActivity},
5050
# Expert settings, alphabetically
@@ -92,7 +92,7 @@ def format_internal_data_partition(self, new_value):
9292
# This will throw an exception if there is already a "/builtin" folder present
9393
print("settings.py: WARNING: could not import/run freezefs_mount_builtin: ", e)
9494
print("Done mounting, refreshing apps")
95-
PackageManager.refresh_apps()
95+
AppManager.refresh_apps()
9696

9797
def theme_changed(self, new_value):
9898
from mpos import AppearanceManager

internal_filesystem/lib/mpos/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from .content.intent import Intent
55
from .activity_navigator import ActivityNavigator
66

7-
from .content.package_manager import PackageManager
7+
from .content.app_manager import AppManager
88
from .config import SharedPreferences
99
from .net.connectivity_manager import ConnectivityManager
1010
from .net.wifi_service import WifiService
@@ -65,7 +65,7 @@
6565
"Activity",
6666
"SharedPreferences",
6767
"ConnectivityManager", "DownloadManager", "WifiService", "AudioFlinger", "Intent",
68-
"ActivityNavigator", "PackageManager", "TaskManager", "CameraManager",
68+
"ActivityNavigator", "AppManager", "TaskManager", "CameraManager",
6969
# Device and build info
7070
"DeviceInfo", "BuildInfo",
7171
# Common activities

internal_filesystem/lib/mpos/activity_navigator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import utime
33

44
from .content.intent import Intent
5-
from .content.package_manager import PackageManager
5+
from .content.app_manager import AppManager
66

77
import mpos.ui
88

@@ -13,7 +13,7 @@ def startActivity(intent):
1313
if not isinstance(intent, Intent):
1414
raise ValueError("Must provide an Intent")
1515
if intent.action: # Implicit intent: resolve handlers
16-
handlers = PackageManager.resolve_activity(intent)
16+
handlers = AppManager.resolve_activity(intent)
1717
if not handlers:
1818
print("No handler for action:", intent.action)
1919
return
@@ -31,7 +31,7 @@ def startActivityForResult(intent, result_callback):
3131
if not isinstance(intent, Intent):
3232
raise ValueError("Must provide an Intent")
3333
if intent.action: # Implicit intent: resolve handlers
34-
handlers = PackageManager.resolve_activity(intent)
34+
handlers = AppManager.resolve_activity(intent)
3535
if not handlers:
3636
print("No handler for action:", intent.action)
3737
return

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Chooser doesn't handle an action — it shows handlers
33
# → No registration needed
44

5-
from ...content.package_manager import PackageManager
5+
from ...content.app_manager import AppManager
66

77
class ChooserActivity(Activity):
88
def __init__(self):
@@ -27,7 +27,7 @@ def onCreate(self):
2727
self.setContentView(screen)
2828

2929
def _select_handler(self, handler_name, original_intent):
30-
for handler in PackageManager.APP_REGISTRY.get(original_intent.action, []):
30+
for handler in AppManager.APP_REGISTRY.get(original_intent.action, []):
3131
if handler.__name__ == handler_name:
3232
original_intent.activity_class = handler
3333
navigator.startActivity(original_intent)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from ..activity import Activity
2-
from ...content.package_manager import PackageManager
2+
from ...content.app_manager import AppManager
33

44
class ShareActivity(Activity):
55
def __init__(self):
@@ -35,4 +35,4 @@ def onStop(self, screen):
3535
else:
3636
print("Stopped for other screen")
3737

38-
PackageManager.register_activity("share", ShareActivity)
38+
AppManager.register_activity("share", ShareActivity)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from ..activity import Activity
2-
from ...content.package_manager import PackageManager
2+
from ...content.app_manager import AppManager
33

44
class ViewActivity(Activity):
55
def __init__(self):
@@ -28,4 +28,4 @@ def onStop(self, screen):
2828
print("Stopped for other screen")
2929

3030
# Register this activity for "view" intents
31-
PackageManager.register_activity("view", ViewActivity)
31+
AppManager.register_activity("view", ViewActivity)

internal_filesystem/lib/mpos/content/package_manager.py renamed to internal_filesystem/lib/mpos/content/app_manager.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
2929
'''
3030

31-
class PackageManager:
31+
class AppManager:
3232

3333
_registry = {} # action → [ActivityClass, ...]
3434

@@ -52,9 +52,9 @@ def query_intent_activities(cls, intent):
5252

5353
"""Registry of all discovered apps.
5454
55-
* PackageManager.get_app_list() -> list of App objects (sorted by name)
56-
* PackageManager[fullname] -> App (raises KeyError if missing)
57-
* PackageManager.get(fullname) -> App or None
55+
* AppManager.get_app_list() -> list of App objects (sorted by name)
56+
* AppManager[fullname] -> App (raises KeyError if missing)
57+
* AppManager.get(fullname) -> App or None
5858
"""
5959

6060
_app_list = [] # sorted by app.name
@@ -93,7 +93,7 @@ def clear(cls):
9393

9494
@classmethod
9595
def refresh_apps(cls):
96-
print("PackageManager finding apps...")
96+
print("AppManager finding apps...")
9797

9898
cls.clear() # <-- this guarantees both containers are empty
9999
seen = set() # avoid processing the same fullname twice
@@ -117,7 +117,7 @@ def refresh_apps(cls):
117117
if not (st[0] & 0x4000):
118118
continue
119119
except Exception as e:
120-
print("PackageManager: stat of {} got exception: {}".format(full_path, e))
120+
print("AppManager: stat of {} got exception: {}".format(full_path, e))
121121
continue
122122

123123
fullname = name
@@ -132,7 +132,7 @@ def refresh_apps(cls):
132132
from ..app.app import App
133133
app = App.from_manifest(full_path)
134134
except Exception as e:
135-
print("PackageManager: parsing {} failed: {}".format(full_path, e))
135+
print("AppManager: parsing {} failed: {}".format(full_path, e))
136136
continue
137137

138138
# ---- store in both containers ---------------------------
@@ -141,7 +141,7 @@ def refresh_apps(cls):
141141
print("added app {}".format(app))
142142

143143
except Exception as e:
144-
print("PackageManager: handling {} got exception: {}".format(base, e))
144+
print("AppManager: handling {} got exception: {}".format(base, e))
145145

146146
# ---- sort the list by display name (case-insensitive) ------------
147147
cls._app_list.sort(key=lambda a: a.name.lower())
@@ -153,7 +153,7 @@ def uninstall_app(app_fullname):
153153
shutil.rmtree(f"apps/{app_fullname}") # never in builtin/apps because those can't be uninstalled
154154
except Exception as e:
155155
print(f"Removing app_folder {app_folder} got error: {e}")
156-
PackageManager.refresh_apps()
156+
AppManager.refresh_apps()
157157

158158
@staticmethod
159159
def install_mpk(temp_zip_path, dest_folder):
@@ -169,7 +169,7 @@ def install_mpk(temp_zip_path, dest_folder):
169169
except Exception as e:
170170
print(f"Unzip and cleanup failed: {e}")
171171
# Would be good to show error message here if it fails...
172-
PackageManager.refresh_apps()
172+
AppManager.refresh_apps()
173173

174174
@staticmethod
175175
def compare_versions(ver1: str, ver2: str) -> bool:
@@ -200,20 +200,20 @@ def compare_versions(ver1: str, ver2: str) -> bool:
200200

201201
@staticmethod
202202
def is_builtin_app(app_fullname):
203-
return PackageManager.is_installed_by_path(f"builtin/apps/{app_fullname}")
203+
return AppManager.is_installed_by_path(f"builtin/apps/{app_fullname}")
204204

205205
@staticmethod
206206
def is_overridden_builtin_app(app_fullname):
207-
return PackageManager.is_installed_by_path(f"apps/{app_fullname}") and PackageManager.is_installed_by_path(f"builtin/apps/{app_fullname}")
207+
return AppManager.is_installed_by_path(f"apps/{app_fullname}") and AppManager.is_installed_by_path(f"builtin/apps/{app_fullname}")
208208

209209
@staticmethod
210210
def is_update_available(app_fullname, new_version):
211211
appdir = f"apps/{app_fullname}"
212212
builtinappdir = f"builtin/apps/{app_fullname}"
213-
installed_app=PackageManager.get(app_fullname)
213+
installed_app=AppManager.get(app_fullname)
214214
if not installed_app:
215215
return False
216-
return PackageManager.compare_versions(new_version, installed_app.version)
216+
return AppManager.compare_versions(new_version, installed_app.version)
217217

218218
@staticmethod
219219
def is_installed_by_path(dir_path):
@@ -231,7 +231,7 @@ def is_installed_by_path(dir_path):
231231
@staticmethod
232232
def is_installed_by_name(app_fullname):
233233
print(f"Checking if app {app_fullname} is installed...")
234-
return PackageManager.is_installed_by_path(f"apps/{app_fullname}") or PackageManager.is_installed_by_path(f"builtin/apps/{app_fullname}")
234+
return AppManager.is_installed_by_path(f"apps/{app_fullname}") or AppManager.is_installed_by_path(f"builtin/apps/{app_fullname}")
235235

236236
@staticmethod
237237
def execute_script(script_source, is_file, classname, cwd=None):
@@ -311,7 +311,7 @@ def start_app(fullname):
311311
mpos.ui.set_foreground_app(fullname)
312312
import utime
313313
start_time = utime.ticks_ms()
314-
app = PackageManager.get(fullname)
314+
app = AppManager.get(fullname)
315315
if not app:
316316
print(f"Warning: start_app can't find app {fullname}")
317317
return
@@ -325,7 +325,7 @@ def start_app(fullname):
325325
else:
326326
entrypoint = app.main_launcher_activity.get('entrypoint')
327327
classname = app.main_launcher_activity.get("classname")
328-
result = PackageManager.execute_script(app.installed_path + "/" + entrypoint, True, classname, app.installed_path + "/assets/")
328+
result = AppManager.execute_script(app.installed_path + "/" + entrypoint, True, classname, app.installed_path + "/assets/")
329329
# Launchers have the bar, other apps don't have it
330330
if app.is_valid_launcher():
331331
mpos.ui.topmenu.open_bar()
@@ -343,5 +343,4 @@ def restart_launcher():
343343
# Stop all apps
344344
mpos.ui.remove_and_stop_all_activities()
345345
# No need to stop the other launcher first, because it exits after building the screen
346-
return PackageManager.start_app(PackageManager.get_launcher().fullname)
347-
346+
return AppManager.start_app(AppManager.get_launcher().fullname)

0 commit comments

Comments
 (0)