From a5666a0ba072902cb9a09a4ff44a6c281202b33f Mon Sep 17 00:00:00 2001 From: Thomas Farstrike Date: Thu, 1 May 2025 22:52:13 +0200 Subject: [PATCH] appstore: progress bar on uninstall --- .../com.example.appstore/assets/appstore.py | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/internal_filesystem/builtin/apps/com.example.appstore/assets/appstore.py b/internal_filesystem/builtin/apps/com.example.appstore/assets/appstore.py index 10e61232..6121d0c7 100644 --- a/internal_filesystem/builtin/apps/com.example.appstore/assets/appstore.py +++ b/internal_filesystem/builtin/apps/com.example.appstore/assets/appstore.py @@ -64,6 +64,28 @@ try: except ImportError: zipfile = None + +def uninstall_app(app_folder, label): + global install_button, progress_bar + install_button.remove_flag(lv.obj.FLAG.CLICKABLE) # TODO: change color so it's clear the button is not clickable + label.set_text("Please wait...") # TODO: Put "Cancel" if cancellation is possible + progress_bar.remove_flag(lv.obj.FLAG.HIDDEN) + progress_bar.set_value(33, lv.ANIM.ON) + time.sleep_ms(500) + try: + import shutil + shutil.rmtree(app_folder) + progress_bar.set_value(66, lv.ANIM.ON) + time.sleep_ms(500) + except Exception as e: + print(f"Removing app_folder {app_folder} got error: {e}") + progress_bar.set_value(100, lv.ANIM.OFF) + time.sleep(1) + progress_bar.add_flag(lv.obj.FLAG.HIDDEN) + progress_bar.set_value(0, lv.ANIM.OFF) + label.set_text(action_label_install) + install_button.add_flag(lv.obj.FLAG.CLICKABLE) + def download_and_unzip(zip_url, dest_folder, label): global install_button, progress_bar install_button.remove_flag(lv.obj.FLAG.CLICKABLE) # TODO: change color so it's clear the button is not clickable @@ -119,8 +141,9 @@ def download_and_unzip(zip_url, dest_folder, label): progress_bar.set_value(80, lv.ANIM.OFF) progress_bar.set_value(100, lv.ANIM.OFF) time.sleep(1) - label.set_text("Uninstall") progress_bar.add_flag(lv.obj.FLAG.HIDDEN) + progress_bar.set_value(0, lv.ANIM.OFF) + label.set_text(action_label_uninstall) install_button.add_flag(lv.obj.FLAG.CLICKABLE) @@ -260,10 +283,11 @@ def toggle_install(download_url, fullname): print("Could not start download_and_unzip thread: ", e) elif label.get_text() == action_label_uninstall: print("Uninstalling app....") - import shutil - if fullname: - shutil.rmtree(f"/apps/{fullname}") - label.set_text("Install") + try: + _thread.stack_size(16384) + _thread.start_new_thread(uninstall_app, (f"/apps/{fullname}", label)) + except Exception as e: + print("Could not start download_and_unzip thread: ", e) def back_to_main(event):