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
@@ -7,39 +7,47 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** Important: These values must map to tt::app::Result values exactly */
|
||||
typedef enum {
|
||||
AppResultOk,
|
||||
AppResultCancelled,
|
||||
AppResultError
|
||||
AppResultOk = 0,
|
||||
AppResultCancelled = 1,
|
||||
AppResultError = 2
|
||||
} Result;
|
||||
|
||||
typedef void* AppContextHandle;
|
||||
|
||||
typedef void (*AppOnStart)(AppContextHandle app);
|
||||
typedef void (*AppOnStop)(AppContextHandle app);
|
||||
typedef void (*AppOnShow)(AppContextHandle app, lv_obj_t* parent);
|
||||
typedef void (*AppOnHide)(AppContextHandle app);
|
||||
typedef void (*AppOnResult)(AppContextHandle app, Result result, BundleHandle resultData);
|
||||
/** Important: These function types must map to t::app types exactly */
|
||||
typedef void* (*AppCreateData)();
|
||||
typedef void (*AppDestroyData)(void* data);
|
||||
typedef void (*AppOnStart)(AppContextHandle app, void* _Nullable data);
|
||||
typedef void (*AppOnStop)(AppContextHandle app, void* _Nullable data);
|
||||
typedef void (*AppOnShow)(AppContextHandle app, void* _Nullable data, lv_obj_t* parent);
|
||||
typedef void (*AppOnHide)(AppContextHandle app, void* _Nullable data);
|
||||
typedef void (*AppOnResult)(AppContextHandle app, void* _Nullable data, Result result, BundleHandle resultData);
|
||||
|
||||
/**
|
||||
* This is used to register the manifest of an external app.
|
||||
* @param[in] name the application's human-readable name
|
||||
* @param[in] icon the optional application icon (you can use LV_SYMBOL_* too)
|
||||
* @param[in] onStart called when the app is launched (started)
|
||||
* @param[in] onStop called when the app is exited (stopped)
|
||||
* @param[in] onShow called when the app is about to be shown to the user (app becomes visible)
|
||||
* @param[in] onHide called when the app is about to be invisible to the user (e.g. other app was launched by this app, and this app goes to the background)
|
||||
* @param[in] onResult called when the app receives a result after launching another app
|
||||
*/
|
||||
void tt_set_app_manifest(
|
||||
const char* name,
|
||||
const char* _Nullable icon,
|
||||
AppOnStart onStart,
|
||||
AppOnStop _Nullable onStop,
|
||||
AppOnShow _Nullable onShow,
|
||||
AppOnHide _Nullable onHide,
|
||||
AppOnResult _Nullable onResult
|
||||
);
|
||||
typedef struct {
|
||||
/** The application's human-readable name */
|
||||
const char* name;
|
||||
/** The application icon (you can use LV_SYMBOL_* too) */
|
||||
const char* _Nullable icon;
|
||||
/** The application can allocate data to re-use later (e.g. struct with state) */
|
||||
AppCreateData _Nullable createData;
|
||||
/** If createData is specified, this one must be specified too */
|
||||
AppDestroyData _Nullable destroyData;
|
||||
/** Called when the app is launched (started) */
|
||||
AppOnStart _Nullable onStart;
|
||||
/** Called when the app is exited (stopped) */
|
||||
AppOnStop _Nullable onStop;
|
||||
/** Called when the app is about to be shown to the user (app becomes visible) */
|
||||
AppOnShow _Nullable onShow;
|
||||
/** Called when the app is about to be invisible to the user (e.g. other app was launched by this app, and this app goes to the background) */
|
||||
AppOnHide _Nullable onHide;
|
||||
/** Called when the app receives a result after launching another app */
|
||||
AppOnResult _Nullable onResult;
|
||||
} ExternalAppManifest;
|
||||
|
||||
/** This is used to register the manifest of an external app. */
|
||||
void tt_app_register(const ExternalAppManifest* manifest);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user