From 54ee88358bdf465db2558544f7ac4ee1c3d3f0c3 Mon Sep 17 00:00:00 2001 From: b0xcat Date: Fri, 31 May 2024 19:05:21 +0200 Subject: [PATCH 1/5] Uninstall WIP --- modules/firmware_apps/app_store.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/modules/firmware_apps/app_store.py b/modules/firmware_apps/app_store.py index 1cc7bad..28a448e 100644 --- a/modules/firmware_apps/app_store.py +++ b/modules/firmware_apps/app_store.py @@ -145,6 +145,7 @@ def exit_available_menu(): item_font_size=ten_pt, ) + def prepare_main_menu(self): def on_cancel(): self.minimise() @@ -182,7 +183,9 @@ def on_cancel(): self.cleanup_ui_widgets() self.update_state("main_menu") - def on_select(_, __): + def on_select(value, idx): + print(f"SELECTED: {value}, {idx}") + self.uninstall_app(value) # TODO maybe implement uninstalling apps pass @@ -197,6 +200,21 @@ def on_select(_, __): item_font_size=ten_pt, ) + def uninstall_app(self, app): + user_apps = list_user_apps() + selected_app = list(filter(lambda x: x['name'] == app, user_apps)) + if len(selected_app) == 0: + raise RuntimeError(f"app not found: {app}") + if len(selected_app) > 1: + raise RuntimeError(f"duplicate app found: {app}") + else: + selected_app = selected_app[0] + selected_app_module = selected_app['path'] + selected_app_fs_path = "/" + "/".join(selected_app_module.split(".")[0:-1]) + print(f"Selected app fs path: {selected_app_fs_path}") + + + def error_screen(self, ctx, message): ctx.save() ctx.text_align = ctx.CENTER @@ -218,7 +236,7 @@ def update(self, delta): self.get_index() elif self.state == "wifi_init": try: - wifi.connect() + wifi.connect(ssid="Henk", password="espespesp") except Exception: pass self.update_state("wifi_connecting") From 3e6251094accc565df1b91321cc2f62745c57a0f Mon Sep 17 00:00:00 2001 From: b0xcat Date: Fri, 31 May 2024 19:42:49 +0200 Subject: [PATCH 2/5] Allow uninstalling apps --- modules/firmware_apps/app_store.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/firmware_apps/app_store.py b/modules/firmware_apps/app_store.py index 28a448e..125a1f9 100644 --- a/modules/firmware_apps/app_store.py +++ b/modules/firmware_apps/app_store.py @@ -9,6 +9,8 @@ import app import wifi +import shutil +import machine from app_components import Menu, clear_background, fourteen_pt, sixteen_pt, ten_pt from events.input import BUTTON_TYPES, ButtonDownEvent from requests import get @@ -184,10 +186,9 @@ def on_cancel(): self.update_state("main_menu") def on_select(value, idx): - print(f"SELECTED: {value}, {idx}") self.uninstall_app(value) - # TODO maybe implement uninstalling apps - pass + self.cleanup_ui_widgets() + self.update_state("main_menu") installed_apps = list_user_apps() @@ -212,6 +213,9 @@ def uninstall_app(self, app): selected_app_module = selected_app['path'] selected_app_fs_path = "/" + "/".join(selected_app_module.split(".")[0:-1]) print(f"Selected app fs path: {selected_app_fs_path}") + shutil.rmtree(selected_app_fs_path) + eventbus.emit(InstallNotificationEvent()) + machine.reset() From 47b40057265051f4b02575e2bb0ffd958ae980d9 Mon Sep 17 00:00:00 2001 From: b0xcat Date: Fri, 31 May 2024 19:43:00 +0200 Subject: [PATCH 3/5] Print error msg when app fails to start --- modules/system/launcher/app.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/system/launcher/app.py b/modules/system/launcher/app.py index b03743f..4810c8e 100644 --- a/modules/system/launcher/app.py +++ b/modules/system/launcher/app.py @@ -154,7 +154,8 @@ def launch(self, item): try: module = __import__(module_name, None, None, (fn,)) app = getattr(module, fn)() - except Exception: + except Exception as e: + print(f"Error creating app: {e}") eventbus.emit( ShowNotificationEvent(message=f"{item["name"]} has crashed") ) From 0d74d88297ac5437a2b67e5bacd0343dc1eaae39 Mon Sep 17 00:00:00 2001 From: b0xcat Date: Fri, 31 May 2024 19:43:13 +0200 Subject: [PATCH 4/5] Add shutil to frozen lib files --- tildagon/manifest.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tildagon/manifest.py b/tildagon/manifest.py index 02c77b4..e940c9d 100644 --- a/tildagon/manifest.py +++ b/tildagon/manifest.py @@ -37,6 +37,7 @@ def freeze_images(path, generated_dir): module("eeprom_i2c.py", base_path="$(MPY_DIR)/../modules/lib") freeze("$(MPY_DIR)/../modules/lib", "typing.py") freeze("$(MPY_DIR)/../modules/lib", "typing_extensions.py") +freeze("$(MPY_DIR)/../modules/lib", "shutil.py") #freeze("$(MPY_DIR)/../micropython-lib/python-ecosys/urequests", "urequests.py") #freeze("$(MPY_DIR)/../micropython-lib/micropython/upysh", "upysh.py") #freeze("$(MPY_DIR)/../micropython-lib/python-stdlib/functools", "functools.py") From dec04441b82d46ffa0144c425710c7c30202050c Mon Sep 17 00:00:00 2001 From: b0xcat Date: Fri, 31 May 2024 19:45:54 +0200 Subject: [PATCH 5/5] Please don't connect to my hotspot lol --- modules/firmware_apps/app_store.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/firmware_apps/app_store.py b/modules/firmware_apps/app_store.py index 125a1f9..6272f85 100644 --- a/modules/firmware_apps/app_store.py +++ b/modules/firmware_apps/app_store.py @@ -240,7 +240,7 @@ def update(self, delta): self.get_index() elif self.state == "wifi_init": try: - wifi.connect(ssid="Henk", password="espespesp") + wifi.connect() except Exception: pass self.update_state("wifi_connecting")