Skip to content

Commit a5666a0

Browse files
appstore: progress bar on uninstall
1 parent c70fe71 commit a5666a0

File tree

1 file changed

+29
-5
lines changed
  • internal_filesystem/builtin/apps/com.example.appstore/assets

1 file changed

+29
-5
lines changed

internal_filesystem/builtin/apps/com.example.appstore/assets/appstore.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,28 @@ def load_icon(url):
6464
except ImportError:
6565
zipfile = None
6666

67+
68+
def uninstall_app(app_folder, label):
69+
global install_button, progress_bar
70+
install_button.remove_flag(lv.obj.FLAG.CLICKABLE) # TODO: change color so it's clear the button is not clickable
71+
label.set_text("Please wait...") # TODO: Put "Cancel" if cancellation is possible
72+
progress_bar.remove_flag(lv.obj.FLAG.HIDDEN)
73+
progress_bar.set_value(33, lv.ANIM.ON)
74+
time.sleep_ms(500)
75+
try:
76+
import shutil
77+
shutil.rmtree(app_folder)
78+
progress_bar.set_value(66, lv.ANIM.ON)
79+
time.sleep_ms(500)
80+
except Exception as e:
81+
print(f"Removing app_folder {app_folder} got error: {e}")
82+
progress_bar.set_value(100, lv.ANIM.OFF)
83+
time.sleep(1)
84+
progress_bar.add_flag(lv.obj.FLAG.HIDDEN)
85+
progress_bar.set_value(0, lv.ANIM.OFF)
86+
label.set_text(action_label_install)
87+
install_button.add_flag(lv.obj.FLAG.CLICKABLE)
88+
6789
def download_and_unzip(zip_url, dest_folder, label):
6890
global install_button, progress_bar
6991
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):
119141
progress_bar.set_value(80, lv.ANIM.OFF)
120142
progress_bar.set_value(100, lv.ANIM.OFF)
121143
time.sleep(1)
122-
label.set_text("Uninstall")
123144
progress_bar.add_flag(lv.obj.FLAG.HIDDEN)
145+
progress_bar.set_value(0, lv.ANIM.OFF)
146+
label.set_text(action_label_uninstall)
124147
install_button.add_flag(lv.obj.FLAG.CLICKABLE)
125148

126149

@@ -260,10 +283,11 @@ def toggle_install(download_url, fullname):
260283
print("Could not start download_and_unzip thread: ", e)
261284
elif label.get_text() == action_label_uninstall:
262285
print("Uninstalling app....")
263-
import shutil
264-
if fullname:
265-
shutil.rmtree(f"/apps/{fullname}")
266-
label.set_text("Install")
286+
try:
287+
_thread.stack_size(16384)
288+
_thread.start_new_thread(uninstall_app, (f"/apps/{fullname}", label))
289+
except Exception as e:
290+
print("Could not start download_and_unzip thread: ", e)
267291

268292

269293
def back_to_main(event):

0 commit comments

Comments
 (0)