App class: automatically set icon_path

This commit is contained in:
Thomas Farstrike
2025-11-02 15:53:44 +01:00
parent f6fb647172
commit 12f6dd826a
2 changed files with 29 additions and 1 deletions
+16
View File
@@ -1,3 +1,4 @@
import os
import ujson
from ..activity_navigator import ActivityNavigator
@@ -30,11 +31,26 @@ class App:
self.image = None
self.image_dsc = None
self.icon_path = self._find_icon_path()
self.main_launcher_activity = self._find_main_launcher_activity()
def __str__(self):
return f"App({self.name}, v{self.version}, {self.category})"
def _check_icon_path(self, tocheck):
try:
#print(f"checking {tocheck}")
st = os.stat(tocheck)
#print(f"_find_icon_path got {st}")
return tocheck
except Exception as e:
#print(f"No app icon found: {e}")
return None
def _find_icon_path(self):
fullpath = "apps/" + self.fullname + "/res/mipmap-mdpi/icon_64x64.png"
return self._check_icon_path(fullpath) or self._check_icon_path("builtin/" + fullpath)
def _find_main_launcher_activity(self):
for act in self.activities:
if not act.get("entrypoint") or not act.get("classname"):
+13 -1
View File
@@ -1,6 +1,6 @@
import unittest
from mpos import PackageManager
from mpos import App, PackageManager
class TestCompareVersions(unittest.TestCase):
@@ -35,3 +35,15 @@ class TestPackageManager_is_installed_by_name(unittest.TestCase):
def test_not_installed(self):
self.assertFalse(PackageManager.is_installed_by_name("com.micropythonos.badname"))
class TestPackageManager_get_app_list(unittest.TestCase):
def test_get_app_list(self):
app_list = PackageManager.get_app_list()
self.assertEqual(len(app_list), 17)
def test_get_app(self):
app_list = PackageManager.get_app_list()
hello_world_app = PackageManager.get("com.micropythonos.helloworld")
self.assertIsInstance(hello_world_app, App)
self.assertEqual(hello_world_app.icon_path, "apps/com.micropythonos.helloworld/res/mipmap-mdpi/icon_64x64.png")