From 8a1cf8679673c7e2071a5050dcee595607e77343 Mon Sep 17 00:00:00 2001
From: Rahix <rahix@rahix.de>
Date: Fri, 18 Oct 2019 09:33:14 +0200
Subject: [PATCH] feat(menu): List special apps at the top

Add a mechanism for "favorite apps" which are shown at the top of the
app-list no matter what.

Signed-off-by: Rahix <rahix@rahix.de>
---
 preload/menu.py | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/preload/menu.py b/preload/menu.py
index c56adc3c..60794957 100644
--- a/preload/menu.py
+++ b/preload/menu.py
@@ -16,21 +16,30 @@ import utime
 
 App = collections.namedtuple("App", ["name", "path"])
 
+# Favorite apps which are shown at the very top of the app list
+FAVORITE_APPS = ["personal_state", "ecg"]
+
 
 def enumerate_entries():
     for f in os.listdir("/"):
         if f == "main.py":
             yield App("Home", f)
 
+    yield from enumerate_apps(FAVORITE_APPS)
+
     yield from sorted(enumerate_apps(), key=lambda b: b.name.lower())
 
 
-def enumerate_apps():
+def enumerate_apps(apps=None):
     """List all installed apps."""
-    for app in os.listdir("/apps"):
+    for app in apps or os.listdir("/apps"):
         if app.startswith("."):
             continue
 
+        # Skip special apps when enumerating from filesystem
+        if apps is None and app in FAVORITE_APPS:
+            continue
+
         if app.endswith(".py") or app.endswith(".elf"):
             yield App(app, "/apps/" + app)
             continue
-- 
GitLab