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:
committed by
GitHub
parent
2bbd44a8b5
commit
c3bcf93698
@@ -1,4 +1,5 @@
|
||||
#include "app/files/FilesPrivate.h"
|
||||
#include "app/files/View.h"
|
||||
#include "app/files/State.h"
|
||||
|
||||
#include "app/AppContext.h"
|
||||
#include "Assets.h"
|
||||
@@ -12,31 +13,31 @@ namespace tt::app::files {
|
||||
|
||||
extern const AppManifest manifest;
|
||||
|
||||
/** Returns the app data if the app is active. Note that this could clash if the same app is started twice and a background thread is slow. */
|
||||
class FilesApp : public App {
|
||||
std::unique_ptr<View> view;
|
||||
std::shared_ptr<State> state;
|
||||
|
||||
static void onShow(AppContext& app, lv_obj_t* parent) {
|
||||
auto files = std::static_pointer_cast<Files>(app.getData());
|
||||
files->onShow(parent);
|
||||
}
|
||||
public:
|
||||
FilesApp() {
|
||||
state = std::make_shared<State>();
|
||||
view = std::make_unique<View>(state);
|
||||
}
|
||||
|
||||
static void onStart(AppContext& app) {
|
||||
auto files = std::make_shared<Files>();
|
||||
app.setData(files);
|
||||
}
|
||||
void onShow(AppContext& appContext, lv_obj_t* parent) override {
|
||||
view->init(parent);
|
||||
}
|
||||
|
||||
static void onResult(AppContext& app, Result result, const Bundle& bundle) {
|
||||
auto files = std::static_pointer_cast<Files>(app.getData());
|
||||
files->onResult(result, bundle);
|
||||
}
|
||||
void onResult(AppContext& appContext, Result result, std::unique_ptr<Bundle> bundle) override {
|
||||
view->onResult(result, std::move(bundle));
|
||||
}
|
||||
};
|
||||
|
||||
extern const AppManifest manifest = {
|
||||
.id = "Files",
|
||||
.name = "Files",
|
||||
.icon = TT_ASSETS_APP_ICON_FILES,
|
||||
.type = TypeHidden,
|
||||
.onStart = onStart,
|
||||
.onShow = onShow,
|
||||
.onResult = onResult
|
||||
.type = Type::Hidden,
|
||||
.createApp = create<FilesApp>
|
||||
};
|
||||
|
||||
void start() {
|
||||
|
||||
Reference in New Issue
Block a user