You've already forked MicroPythonOS
mirror of
https://github.com/m5stack/MicroPythonOS.git
synced 2026-05-20 11:51:27 -07:00
App class: automatically set icon_path
This commit is contained in:
@@ -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"):
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user