From 00900372cc940cfd2a153f7087636899cd54def3 Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak <dos@dosowisko.net> Date: Fri, 20 Oct 2023 16:14:13 +0200 Subject: [PATCH] py,st3m: BundleMetadata: Rename "menu" to "category" Old versions of py,st3m can't handle the new categories and outright reject any bundles that use them. Allow the old "menu" key to be used as a fallback for old firmwares. --- docs/badge/programming.rst | 2 +- python_payload/st3m/application.py | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/docs/badge/programming.rst b/docs/badge/programming.rst index 63ee80a6dd..57b99928f7 100644 --- a/docs/badge/programming.rst +++ b/docs/badge/programming.rst @@ -654,7 +654,7 @@ Together with the Python code this file forms a so called bundle [app] name = "My Demo" - menu = "Apps" + category = "Apps" [entry] class = "MyDemo" diff --git a/python_payload/st3m/application.py b/python_payload/st3m/application.py index ae5fad58ef..38c1550b2f 100644 --- a/python_payload/st3m/application.py +++ b/python_payload/st3m/application.py @@ -99,7 +99,7 @@ class BundleMetadata: name = "Name of the application" # One of "Apps", "Badge", "Music", "Games", "Media". Picks which menu # the bundle's class will be loadable from. - menu = "Apps" + category = "Apps" [entry] # Required for app to actually load. Defines the name of the class that @@ -144,13 +144,12 @@ class BundleMetadata: if "name" not in app or type(app["name"]) != str: raise BundleMetadataBroken("missing app.name key") self.name = app["name"] - if "menu" not in app or type(app["menu"]) != str: - raise BundleMetadataBroken("missing app.menu key") - self.menu = app["menu"] - if self.menu not in ["Apps", "Music", "Badge", "Games", "Media", "Hidden"]: - raise BundleMetadataBroken( - "app.menu must be either Apps, Music, Badge, Games or Media" - ) + if "category" not in app or type(app["category"]) != str: + if "menu" not in app or type(app["menu"]) != str: + raise BundleMetadataBroken("missing app.category key") + self.menu = app["menu"] + else: + self.menu = app["category"] version = 0 if t.get("metadata") is not None: @@ -216,11 +215,15 @@ class BundleMetadata: raise BundleMetadataBroken("no valid entry method specified") + def menu_kinds(self) -> List[str]: + """ + Returns a list of menu kinds this bundle places its entries in. + """ + return [self.menu] + def menu_entries(self, kind: str) -> List["MenuItemAppLaunch"]: """ Returns MenuItemAppLauch entries for this bundle for a given menu kind. - - Kind is one of 'Apps', 'Badge', 'Music', 'Games', 'Media'. """ if self.menu != kind: return [] -- GitLab