Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to install multiple apps #167

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions modules/firmware_apps/app_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def __init__(self):
self.app_store_index = []
self.to_install_app = None
self.tarball = None
self.wait_one_cycle = False

def cleanup_ui_widgets(self):
widgets = [
Expand All @@ -69,7 +70,12 @@ def cleanup_ui_widgets(self):
for widget in widgets:
if widget:
widget._cleanup()
widget = None

self.menu = None
self.available_menu = None
self.installed_menu = None
self.update_menu = None
self.codeinstall = None

def get_index(self):
if not wifi.status():
Expand All @@ -86,8 +92,13 @@ def background_update(self, delta):
return
self.update_state("index_received")
if self.to_install_app:
self.install_app(self.to_install_app)
self.to_install_app = None
# We wait one cycle after background_update is called to ensure the
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels a bit hacky but because update and draw may not be called while an app is installing I'm really not sure how else to fix it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, it is, but it makes sense. async_helpers.unblock is designed to help with this kind of thing, lemme try a spike.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MatthewWilkes why don't we merge this and then you can prettify it subsequently? It would be nice to have this functionality in

# installation screen is drawn
if self.wait_one_cycle:
self.install_app(self.to_install_app)
self.to_install_app = None
self.wait_one_cycle = False
self.wait_one_cycle = True

def handle_index(self):
if not self.response:
Expand Down Expand Up @@ -134,8 +145,7 @@ def prepare_available_menu(self):
def on_select(_, i):
self.to_install_app = self.app_store_index[i]
self.update_state("installing_app")
if self.available_menu:
self.available_menu._cleanup()
self.cleanup_ui_widgets()

def exit_available_menu():
self.cleanup_ui_widgets()
Expand All @@ -152,11 +162,12 @@ def exit_available_menu():

def prepare_main_menu(self):
def on_cancel():
self.cleanup_ui_widgets()
self.minimise()

def on_select(value, idx):
self.cleanup_ui_widgets()
if value == CODE_INSTALL:
self.cleanup_ui_widgets()
self.codeinstall = CodeInstall(
install_handler=lambda id: self.handle_code_input(id), app=self
)
Expand Down
6 changes: 6 additions & 0 deletions modules/system/eventbus.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,16 @@ def remove(self, event_type, event_handler, app):
if app in self.handlers:
if event_type in self.handlers[app]:
if event_handler in self.handlers[app][event_type]:
print(
f"Removed event handler for {event_type.__name__}: {app.__class__.__name__} - {event_handler.__name__}"
)
self.handlers[app][event_type].remove(event_handler)
if app in self.async_handlers:
if event_type in self.async_handlers[app]:
if event_handler in self.async_handlers[app][event_type]:
print(
f"Removed event handler for {event_type.__name__}: {app.__class__.__name__} - {event_handler.__name__}"
)
self.async_handlers[app][event_type].remove(event_handler)

def deregister(self, app):
Expand Down
Loading