|
| 1 | +importujson |
| 2 | +from ..content.intentimportIntent# optional, if App uses Intent |
| 3 | + |
| 4 | + |
| 5 | +classApp: |
| 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=activitiesor [] |
| 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 | +returnf"App({self.name}, v{self.version},{self.category})" |
| 38 | + |
| 39 | +def_find_main_launcher_activity(self): |
| 40 | +foractinself.activities: |
| 41 | +ifnotact.get("entrypoint")ornotact.get("classname"): |
| 42 | +continue |
| 43 | +forfinact.get("intent_filters", []): |
| 44 | +iff.get("action")=="main"andf.get("category")=="launcher": |
| 45 | +returnact |
| 46 | +returnNone |
| 47 | + |
| 48 | +defis_valid_launcher(self): |
| 49 | +returnself.category=="launcher"andself.main_launcher_activity |
| 50 | + |
| 51 | +@classmethod |
| 52 | +deffrom_manifest(cls,appdir): |
| 53 | +manifest_path=f"{appdir}/META-INF/MANIFEST.JSON" |
| 54 | +default=cls(installed_path=appdir) |
| 55 | +try: |
| 56 | +withopen(manifest_path,"r")asf: |
| 57 | +data=ujson.load(f) |
| 58 | +exceptOSError: |
| 59 | +returndefault |
| 60 | + |
| 61 | +returncls( |
| 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 | + ) |