Skip to content

Commit 12f6dd8

Browse files
App class: automatically set icon_path
1 parent f6fb647 commit 12f6dd8

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

internal_filesystem/lib/mpos/app/app.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import ujson
23
from ..activity_navigator import ActivityNavigator
34

@@ -30,11 +31,26 @@ def __init__(
3031

3132
self.image = None
3233
self.image_dsc = None
34+
self.icon_path = self._find_icon_path()
3335
self.main_launcher_activity = self._find_main_launcher_activity()
3436

3537
def __str__(self):
3638
return f"App({self.name}, v{self.version}, {self.category})"
3739

40+
def _check_icon_path(self, tocheck):
41+
try:
42+
#print(f"checking {tocheck}")
43+
st = os.stat(tocheck)
44+
#print(f"_find_icon_path got {st}")
45+
return tocheck
46+
except Exception as e:
47+
#print(f"No app icon found: {e}")
48+
return None
49+
50+
def _find_icon_path(self):
51+
fullpath = "apps/" + self.fullname + "/res/mipmap-mdpi/icon_64x64.png"
52+
return self._check_icon_path(fullpath) or self._check_icon_path("builtin/" + fullpath)
53+
3854
def _find_main_launcher_activity(self):
3955
for act in self.activities:
4056
if not act.get("entrypoint") or not act.get("classname"):

tests/package_manager.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import unittest
22

3-
from mpos import PackageManager
3+
from mpos import App, PackageManager
44

55
class TestCompareVersions(unittest.TestCase):
66

@@ -35,3 +35,15 @@ def test_installed_not_builtin(self):
3535

3636
def test_not_installed(self):
3737
self.assertFalse(PackageManager.is_installed_by_name("com.micropythonos.badname"))
38+
39+
class TestPackageManager_get_app_list(unittest.TestCase):
40+
41+
def test_get_app_list(self):
42+
app_list = PackageManager.get_app_list()
43+
self.assertEqual(len(app_list), 17)
44+
45+
def test_get_app(self):
46+
app_list = PackageManager.get_app_list()
47+
hello_world_app = PackageManager.get("com.micropythonos.helloworld")
48+
self.assertIsInstance(hello_world_app, App)
49+
self.assertEqual(hello_world_app.icon_path, "apps/com.micropythonos.helloworld/res/mipmap-mdpi/icon_64x64.png")

0 commit comments

Comments
 (0)