Added settings app (#27)

- Added Settings app to show all apps of type `AppTypeSettings`.
- Removed the `AppTypeSettings` apps from the Desktop app.
This commit is contained in:
Ken Van Hoeylandt 2024-01-31 21:00:46 +01:00 committed by GitHub
parent d171b9a231
commit 7f133e65c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 44 additions and 2 deletions

View File

@ -11,9 +11,13 @@ typedef struct _lv_obj_t lv_obj_t;
typedef void* App;
typedef enum {
/** A desktop app sits at the root of the app stack managed by the Loader service */
AppTypeDesktop,
/** Standard apps, provided by the system. */
AppTypeSystem,
/** The apps that are launched/shown by the Settings app. The Settings app itself is of type AppTypeSystem. */
AppTypeSettings,
/** User-provided apps. */
AppTypeUser
} AppType;

View File

@ -25,8 +25,6 @@ static void desktop_show(TT_UNUSED App app, TT_UNUSED lv_obj_t* parent) {
lv_list_add_text(list, "System");
tt_app_manifest_registry_for_each_of_type(AppTypeSystem, list, create_app_widget);
lv_list_add_text(list, "Settings");
tt_app_manifest_registry_for_each_of_type(AppTypeSettings, list, create_app_widget);
lv_list_add_text(list, "User");
tt_app_manifest_registry_for_each_of_type(AppTypeUser, list, create_app_widget);
}

View File

@ -0,0 +1,38 @@
#include "app_manifest_registry.h"
#include "check.h"
#include "lvgl.h"
#include "services/loader/loader.h"
static void on_app_pressed(lv_event_t* e) {
lv_event_code_t code = lv_event_get_code(e);
if (code == LV_EVENT_CLICKED) {
const AppManifest* manifest = lv_event_get_user_data(e);
loader_start_app(manifest->id, false, NULL);
}
}
static void create_app_widget(const AppManifest* manifest, void* _Nullable parent) {
tt_check(parent);
lv_obj_t* list = (lv_obj_t*)parent;
lv_obj_t* btn = lv_list_add_btn(list, LV_SYMBOL_FILE, manifest->name);
lv_obj_add_event_cb(btn, &on_app_pressed, LV_EVENT_CLICKED, (void*)manifest);
}
static void on_show(TT_UNUSED App app, TT_UNUSED lv_obj_t* parent) {
lv_obj_t* list = lv_list_create(parent);
lv_obj_set_size(list, LV_PCT(100), LV_PCT(100));
lv_obj_center(list);
tt_app_manifest_registry_for_each_of_type(AppTypeSettings, list, create_app_widget);
}
const AppManifest settings_app = {
.id = "settings",
.name = "Settings",
.icon = NULL,
.type = AppTypeSystem,
.on_start = NULL,
.on_stop = NULL,
.on_show = &on_show,
.on_hide = NULL
};

View File

@ -26,11 +26,13 @@ static const ServiceManifest* const system_services[] = {
extern const AppManifest desktop_app;
extern const AppManifest display_app;
extern const AppManifest settings_app;
extern const AppManifest system_info_app;
static const AppManifest* const system_apps[] = {
&desktop_app,
&display_app,
&settings_app,
&system_info_app
};