Refactor app launching (#174)

- Refactor the way apps work: Instead of a C interface, they are now C++ classes. The main reasoning is that attaching data to an app was cumbersome. Having different implementations for different kinds of apps was cumbersome too. (3 or 4 layers of manifest nesting for the TactilityC project)
- External apps are still written in C, but they get a createData/destroyData in their manifest, so:
- External apps now have their own manifest.
- All functions in the original AppManifest are removed and replaced by a single `createApp` function
- External apps now automatically register (each app individually!) when they run the first time. As a side-effect they become visible in the `AppList` app!
- Adapted all apps for the new interface.
- Adapted all internal logic for these changes (Gui, ViewPort, Loader, AppContext, AppInstance, etc.)
- Rewrote parts of Loader to use std::shared_ptr to make the code much safer.
- Added a refcount check for the `AppInstance` and `App` at the end of their lifecycle. Show warning if refcount is too high.
This commit is contained in:
Ken Van Hoeylandt
2025-01-21 17:48:32 +01:00
committed by GitHub
parent 2bbd44a8b5
commit c3bcf93698
73 changed files with 2561 additions and 2581 deletions
+8 -11
View File
@@ -19,9 +19,8 @@ Gui* gui = nullptr;
void onLoaderMessage(const void* message, TT_UNUSED void* context) {
auto* event = static_cast<const loader::LoaderEvent*>(message);
if (event->type == loader::LoaderEventTypeApplicationShowing) {
app::AppContext& app = event->app_showing.app;
const app::AppManifest& app_manifest = app.getManifest();
showApp(app, app_manifest.onShow, app_manifest.onHide);
auto app_instance = service::loader::getCurrentAppContext();
showApp(app_instance);
} else if (event->type == loader::LoaderEventTypeApplicationHiding) {
hideApp();
}
@@ -94,27 +93,25 @@ void requestDraw() {
thread_flags_set(thread_id, GUI_THREAD_FLAG_DRAW);
}
void showApp(app::AppContext& app, ViewPortShowCallback on_show, ViewPortHideCallback on_hide) {
void showApp(std::shared_ptr<app::AppContext> app) {
lock();
tt_check(gui->appViewPort == nullptr);
gui->appViewPort = view_port_alloc(app, on_show, on_hide);
tt_check(gui->appToRender == nullptr);
gui->appToRender = std::move(app);
unlock();
requestDraw();
}
void hideApp() {
lock();
ViewPort* view_port = gui->appViewPort;
tt_check(view_port != nullptr);
tt_check(gui->appToRender != nullptr);
// We must lock the LVGL port, because the viewport hide callbacks
// might call LVGL APIs (e.g. to remove the keyboard from the screen root)
tt_check(lvgl::lock(configTICK_RATE_HZ));
view_port_hide(view_port);
gui->appToRender->getApp()->onHide(*gui->appToRender);
lvgl::unlock();
view_port_free(view_port);
gui->appViewPort = nullptr;
gui->appToRender = nullptr;
unlock();
}