Skip to content

Commit

Permalink
Add app store category menu
Browse files Browse the repository at this point in the history
  • Loading branch information
jake-walker committed Oct 21, 2024
1 parent aa8f510 commit 1a75d0e
Showing 1 changed file with 54 additions and 4 deletions.
58 changes: 54 additions & 4 deletions modules/firmware_apps/app_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class AppStoreApp(app.App):
def __init__(self):
super().__init__()
self.menu = None
self.available_categories_menu = None
self.available_menu = None
self.installed_menu = None
self.update_menu = None
Expand All @@ -56,13 +57,16 @@ def __init__(self):
self.app_store_index = []
self.apps_with_updates = []
self.apps_available_dict = {}
self.app_categories = []
self.category_filter = None
self.to_install_app = None
self.tarball = None
self.wait_one_cycle = False

def cleanup_ui_widgets(self):
widgets = [
self.menu,
self.available_categories_menu,
self.available_menu,
self.installed_menu,
self.update_menu,
Expand All @@ -74,6 +78,7 @@ def cleanup_ui_widgets(self):
widget._cleanup()

self.menu = None
self.available_categories_menu = None
self.available_menu = None
self.installed_menu = None
self.update_menu = None
Expand Down Expand Up @@ -114,6 +119,14 @@ def handle_index(self):
self.update_state("no_index")
return

# build list of categories from index
self.app_categories = []

for item in self.app_store_index:
app_category = item["manifest"]["app"].get("category")
if app_category not in self.app_categories:
self.app_categories.append(app_category)

self.update_state("main_menu")

def install_app(self, app):
Expand Down Expand Up @@ -143,19 +156,45 @@ def handle_code_input(self, code):
# TODO notify user of invalid code
self.update_state("main_menu")

def prepare_available_categories_menu(self):
def on_select(_, i):
self.category_filter = self.app_categories[i]
self.update_state("available_menu")
self.cleanup_ui_widgets()

def exit_available_categories_menu():
self.cleanup_ui_widgets()
self.update_state("main_menu")

self.available_categories_menu = Menu(
self,
menu_items=self.app_categories,
select_handler=on_select,
back_handler=exit_available_categories_menu,
focused_item_font_size=fourteen_pt,
item_font_size=ten_pt,
)

def prepare_available_menu(self):
def filtered_index():
return [
app
for app in self.app_store_index
if app["manifest"]["app"].get("category") == self.category_filter
]

def on_select(_, i):
self.to_install_app = self.app_store_index[i]
self.to_install_app = filtered_index()[i]
self.update_state("installing_app")
self.cleanup_ui_widgets()

def exit_available_menu():
self.cleanup_ui_widgets()
self.update_state("main_menu")
self.update_state("available_categories_menu")

self.available_menu = Menu(
self,
menu_items=[app["manifest"]["app"]["name"] for app in self.app_store_index],
menu_items=[app["manifest"]["app"]["name"] for app in filtered_index()],
select_handler=on_select,
back_handler=exit_available_menu,
focused_item_font_size=fourteen_pt,
Expand All @@ -175,7 +214,7 @@ def on_select(value, idx):
)
self.update_state("code_install_input")
elif value == AVAILABLE:
self.update_state("available_menu")
self.update_state("available_categories_menu")
elif value == INSTALLED:
self.update_state("installed_menu")
elif value == UPDATE:
Expand Down Expand Up @@ -311,6 +350,11 @@ def update(self, delta):
self.handle_index()
elif self.state == "main_menu" and not self.menu:
self.prepare_main_menu()
elif (
self.state == "available_categories_menu"
and not self.available_categories_menu
):
self.prepare_available_categories_menu()
elif self.state == "available_menu" and not self.available_menu:
self.prepare_available_menu()
elif self.state == "installed_menu" and not self.installed_menu:
Expand All @@ -320,6 +364,8 @@ def update(self, delta):

if self.menu:
self.menu.update(delta)
if self.available_categories_menu:
self.available_categories_menu.update(delta)
if self.available_menu:
self.available_menu.update(delta)
if self.installed_menu:
Expand All @@ -336,6 +382,10 @@ def draw(self, ctx):
self.menu.draw(ctx)
elif self.state == "main_menu" and not self.menu:
self.error_screen(ctx, "Loading...")
elif (
self.state == "available_categories_menu" and self.available_categories_menu
):
self.available_categories_menu.draw(ctx)
elif self.state == "available_menu" and self.available_menu:
self.available_menu.draw(ctx)
elif self.state == "installed_menu" and self.installed_menu:
Expand Down

0 comments on commit 1a75d0e

Please sign in to comment.