|
| 1 | +import ujson |
| 2 | +from ..content.intent import Intent # optional, if App uses Intent |
| 3 | + |
| 4 | + |
| 5 | +class App: |
| 6 | + def __init__( |
| 7 | + self, |
| 8 | + name="Unknown", |
| 9 | + publisher="Unknown", |
| 10 | + short_description="", |
| 11 | + long_description="", |
| 12 | + icon_url="", |
| 13 | + download_url="", |
| 14 | + fullname="Unknown", |
| 15 | + version="0.0.0", |
| 16 | + category="", |
| 17 | + activities=None, |
| 18 | + installed_path=None, |
| 19 | + ): |
| 20 | + self.name = name |
| 21 | + self.publisher = publisher |
| 22 | + self.short_description = short_description |
| 23 | + self.long_description = long_description |
| 24 | + self.icon_url = icon_url |
| 25 | + self.download_url = download_url |
| 26 | + self.fullname = fullname |
| 27 | + self.version = version |
| 28 | + self.category = category |
| 29 | + self.activities = activities or [] |
| 30 | + self.installed_path = installed_path |
| 31 | + |
| 32 | + self.image = None |
| 33 | + self.image_dsc = None |
| 34 | + self.main_launcher_activity = self._find_main_launcher_activity() |
| 35 | + |
| 36 | + def __str__(self): |
| 37 | + return f"App({self.name}, v{self.version}, {self.category})" |
| 38 | + |
| 39 | + def _find_main_launcher_activity(self): |
| 40 | + for act in self.activities: |
| 41 | + if not act.get("entrypoint") or not act.get("classname"): |
| 42 | + continue |
| 43 | + for f in act.get("intent_filters", []): |
| 44 | + if f.get("action") == "main" and f.get("category") == "launcher": |
| 45 | + return act |
| 46 | + return None |
| 47 | + |
| 48 | + def is_valid_launcher(self): |
| 49 | + return self.category == "launcher" and self.main_launcher_activity |
| 50 | + |
| 51 | + @classmethod |
| 52 | + def from_manifest(cls, appdir): |
| 53 | + manifest_path = f"{appdir}/META-INF/MANIFEST.JSON" |
| 54 | + default = cls(installed_path=appdir) |
| 55 | + try: |
| 56 | + with open(manifest_path, "r") as f: |
| 57 | + data = ujson.load(f) |
| 58 | + except OSError: |
| 59 | + return default |
| 60 | + |
| 61 | + return cls( |
| 62 | + name=data.get("name", default.name), |
| 63 | + publisher=data.get("publisher", default.publisher), |
| 64 | + short_description=data.get("short_description", default.short_description), |
| 65 | + long_description=data.get("long_description", default.long_description), |
| 66 | + icon_url=data.get("icon_url", default.icon_url), |
| 67 | + download_url=data.get("download_url", default.download_url), |
| 68 | + fullname=data.get("fullname", default.fullname), |
| 69 | + version=data.get("version", default.version), |
| 70 | + category=data.get("category", default.category), |
| 71 | + activities=data.get("activities", default.activities), |
| 72 | + installed_path=appdir, |
| 73 | + ) |
0 commit comments