mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-02-18 19:03:16 +00:00
Refactored manifest onStart/onStop to onCreate/onDestroy (#195)
When writing documentation, I realized how `onStart`/`onStop` isn't clearly communicating what it does (it could imply show/hide), so I renamed it to `onCreate` and `onDestroy`.
This commit is contained in:
parent
6c67845645
commit
7856827ecf
@ -38,8 +38,8 @@ public:
|
|||||||
App() = default;
|
App() = default;
|
||||||
virtual ~App() = default;
|
virtual ~App() = default;
|
||||||
|
|
||||||
virtual void onStart(AppContext& appContext) {}
|
virtual void onCreate(AppContext& appContext) {}
|
||||||
virtual void onStop(AppContext& appContext) {}
|
virtual void onDestroy(AppContext& appContext) {}
|
||||||
virtual void onShow(AppContext& appContext, lv_obj_t* parent) {}
|
virtual void onShow(AppContext& appContext, lv_obj_t* parent) {}
|
||||||
virtual void onHide(AppContext& appContext) {}
|
virtual void onHide(AppContext& appContext) {}
|
||||||
virtual void onResult(AppContext& appContext, Result result, std::unique_ptr<Bundle> _Nullable resultData) {}
|
virtual void onResult(AppContext& appContext, Result result, std::unique_ptr<Bundle> _Nullable resultData) {}
|
||||||
|
|||||||
@ -22,8 +22,8 @@ struct ElfManifest {
|
|||||||
std::string icon;
|
std::string icon;
|
||||||
CreateData _Nullable createData = nullptr;
|
CreateData _Nullable createData = nullptr;
|
||||||
DestroyData _Nullable destroyData = nullptr;
|
DestroyData _Nullable destroyData = nullptr;
|
||||||
OnStart _Nullable onStart = nullptr;
|
OnCreate _Nullable onCreate = nullptr;
|
||||||
OnStop _Nullable onStop = nullptr;
|
OnDestroy _Nullable onDestroy = nullptr;
|
||||||
OnShow _Nullable onShow = nullptr;
|
OnShow _Nullable onShow = nullptr;
|
||||||
OnHide _Nullable onHide = nullptr;
|
OnHide _Nullable onHide = nullptr;
|
||||||
OnResult _Nullable onResult = nullptr;
|
OnResult _Nullable onResult = nullptr;
|
||||||
@ -91,7 +91,7 @@ public:
|
|||||||
|
|
||||||
explicit ElfApp(std::string filePath) : filePath(std::move(filePath)) {}
|
explicit ElfApp(std::string filePath) : filePath(std::move(filePath)) {}
|
||||||
|
|
||||||
void onStart(AppContext& appContext) override {
|
void onCreate(AppContext& appContext) override {
|
||||||
auto initial_count = elfManifestSetCount;
|
auto initial_count = elfManifestSetCount;
|
||||||
if (startElf()) {
|
if (startElf()) {
|
||||||
if (elfManifestSetCount > initial_count) {
|
if (elfManifestSetCount > initial_count) {
|
||||||
@ -101,8 +101,8 @@ public:
|
|||||||
data = manifest->createData();
|
data = manifest->createData();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (manifest->onStart != nullptr) {
|
if (manifest->onCreate != nullptr) {
|
||||||
manifest->onStart(&appContext, data);
|
manifest->onCreate(&appContext, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -110,11 +110,11 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void onStop(AppContext& appContext) override {
|
void onDestroy(AppContext& appContext) override {
|
||||||
TT_LOG_I(TAG, "Cleaning up app");
|
TT_LOG_I(TAG, "Cleaning up app");
|
||||||
if (manifest != nullptr) {
|
if (manifest != nullptr) {
|
||||||
if (manifest->onStop != nullptr) {
|
if (manifest->onDestroy != nullptr) {
|
||||||
manifest->onStop(&appContext, data);
|
manifest->onDestroy(&appContext, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (manifest->destroyData != nullptr && data != nullptr) {
|
if (manifest->destroyData != nullptr && data != nullptr) {
|
||||||
@ -150,8 +150,8 @@ void setElfAppManifest(
|
|||||||
const char* _Nullable icon,
|
const char* _Nullable icon,
|
||||||
CreateData _Nullable createData,
|
CreateData _Nullable createData,
|
||||||
DestroyData _Nullable destroyData,
|
DestroyData _Nullable destroyData,
|
||||||
OnStart _Nullable onStart,
|
OnCreate _Nullable onCreate,
|
||||||
OnStop _Nullable onStop,
|
OnDestroy _Nullable onDestroy,
|
||||||
OnShow _Nullable onShow,
|
OnShow _Nullable onShow,
|
||||||
OnHide _Nullable onHide,
|
OnHide _Nullable onHide,
|
||||||
OnResult _Nullable onResult
|
OnResult _Nullable onResult
|
||||||
@ -161,8 +161,8 @@ void setElfAppManifest(
|
|||||||
.icon = icon ? icon : "",
|
.icon = icon ? icon : "",
|
||||||
.createData = createData,
|
.createData = createData,
|
||||||
.destroyData = destroyData,
|
.destroyData = destroyData,
|
||||||
.onStart = onStart,
|
.onCreate = onCreate,
|
||||||
.onStop = onStop,
|
.onDestroy = onDestroy,
|
||||||
.onShow = onShow,
|
.onShow = onShow,
|
||||||
.onHide = onHide,
|
.onHide = onHide,
|
||||||
.onResult = onResult
|
.onResult = onResult
|
||||||
|
|||||||
@ -8,8 +8,8 @@ namespace tt::app {
|
|||||||
|
|
||||||
typedef void* (*CreateData)();
|
typedef void* (*CreateData)();
|
||||||
typedef void (*DestroyData)(void* data);
|
typedef void (*DestroyData)(void* data);
|
||||||
typedef void (*OnStart)(void* appContext, void* _Nullable data);
|
typedef void (*OnCreate)(void* appContext, void* _Nullable data);
|
||||||
typedef void (*OnStop)(void* appContext, void* _Nullable data);
|
typedef void (*OnDestroy)(void* appContext, void* _Nullable data);
|
||||||
typedef void (*OnShow)(void* appContext, void* _Nullable data, lv_obj_t* parent);
|
typedef void (*OnShow)(void* appContext, void* _Nullable data, lv_obj_t* parent);
|
||||||
typedef void (*OnHide)(void* appContext, void* _Nullable data);
|
typedef void (*OnHide)(void* appContext, void* _Nullable data);
|
||||||
typedef void (*OnResult)(void* appContext, void* _Nullable data, Result result, Bundle* resultData);
|
typedef void (*OnResult)(void* appContext, void* _Nullable data, Result result, Bundle* resultData);
|
||||||
@ -19,8 +19,8 @@ void setElfAppManifest(
|
|||||||
const char* _Nullable icon,
|
const char* _Nullable icon,
|
||||||
CreateData _Nullable createData,
|
CreateData _Nullable createData,
|
||||||
DestroyData _Nullable destroyData,
|
DestroyData _Nullable destroyData,
|
||||||
OnStart _Nullable onStart,
|
OnCreate _Nullable onCreate,
|
||||||
OnStop _Nullable onStop,
|
OnDestroy _Nullable onDestroy,
|
||||||
OnShow _Nullable onShow,
|
OnShow _Nullable onShow,
|
||||||
OnHide _Nullable onHide,
|
OnHide _Nullable onHide,
|
||||||
OnResult _Nullable onResult
|
OnResult _Nullable onResult
|
||||||
|
|||||||
@ -97,7 +97,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void onStop(AppContext& app) override {
|
void onDestroy(AppContext& app) override {
|
||||||
thread.join();
|
thread.join();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -47,7 +47,7 @@ static lv_obj_t* createAppButton(lv_obj_t* parent, const char* title, const char
|
|||||||
|
|
||||||
class LauncherApp : public App {
|
class LauncherApp : public App {
|
||||||
|
|
||||||
void onStart(TT_UNUSED AppContext& app) override {
|
void onCreate(TT_UNUSED AppContext& app) override {
|
||||||
auto* config = tt::getConfiguration();
|
auto* config = tt::getConfiguration();
|
||||||
if (!config->autoStartAppId.empty()) {
|
if (!config->autoStartAppId.empty()) {
|
||||||
TT_LOG_I(TAG, "auto-starting %s", config->autoStartAppId.c_str());
|
TT_LOG_I(TAG, "auto-starting %s", config->autoStartAppId.c_str());
|
||||||
|
|||||||
@ -231,7 +231,7 @@ public:
|
|||||||
listWidget = list;
|
listWidget = list;
|
||||||
}
|
}
|
||||||
|
|
||||||
void onStart(AppContext& app) override {
|
void onCreate(AppContext& app) override {
|
||||||
updateTimer = std::make_unique<Timer>(Timer::Type::Once, updateTimerCallback, nullptr);
|
updateTimer = std::make_unique<Timer>(Timer::Type::Once, updateTimerCallback, nullptr);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -118,7 +118,7 @@ static void transitionAppToState(std::shared_ptr<app::AppInstance> app, app::Sta
|
|||||||
case Initial:
|
case Initial:
|
||||||
break;
|
break;
|
||||||
case Started:
|
case Started:
|
||||||
app->getApp()->onStart(*app);
|
app->getApp()->onCreate(*app);
|
||||||
break;
|
break;
|
||||||
case Showing: {
|
case Showing: {
|
||||||
LoaderEvent event_showing = { .type = LoaderEventTypeApplicationShowing };
|
LoaderEvent event_showing = { .type = LoaderEventTypeApplicationShowing };
|
||||||
@ -132,7 +132,7 @@ static void transitionAppToState(std::shared_ptr<app::AppInstance> app, app::Sta
|
|||||||
}
|
}
|
||||||
case Stopped:
|
case Stopped:
|
||||||
// TODO: Verify manifest
|
// TODO: Verify manifest
|
||||||
app->getApp()->onStop(*app);
|
app->getApp()->onDestroy(*app);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -17,14 +17,14 @@ void tt_app_register(
|
|||||||
manifest->icon,
|
manifest->icon,
|
||||||
(tt::app::CreateData)manifest->createData,
|
(tt::app::CreateData)manifest->createData,
|
||||||
(tt::app::DestroyData)manifest->destroyData,
|
(tt::app::DestroyData)manifest->destroyData,
|
||||||
(tt::app::OnStart)manifest->onStart,
|
(tt::app::OnCreate)manifest->onCreate,
|
||||||
(tt::app::OnStop)manifest->onStop,
|
(tt::app::OnDestroy)manifest->onDestroy,
|
||||||
(tt::app::OnShow)manifest->onShow,
|
(tt::app::OnShow)manifest->onShow,
|
||||||
(tt::app::OnHide)manifest->onHide,
|
(tt::app::OnHide)manifest->onHide,
|
||||||
(tt::app::OnResult)manifest->onResult
|
(tt::app::OnResult)manifest->onResult
|
||||||
);
|
);
|
||||||
#else
|
#else
|
||||||
tt_crash("TactilityC is intended for PC/Simulator");
|
tt_crash("TactilityC is not intended for PC/Simulator");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -19,8 +19,8 @@ typedef void* AppHandle;
|
|||||||
/** Important: These function types must map to t::app types exactly */
|
/** Important: These function types must map to t::app types exactly */
|
||||||
typedef void* (*AppCreateData)();
|
typedef void* (*AppCreateData)();
|
||||||
typedef void (*AppDestroyData)(void* data);
|
typedef void (*AppDestroyData)(void* data);
|
||||||
typedef void (*AppOnStart)(AppHandle app, void* _Nullable data);
|
typedef void (*AppOnCreate)(AppHandle app, void* _Nullable data);
|
||||||
typedef void (*AppOnStop)(AppHandle app, void* _Nullable data);
|
typedef void (*AppOnDestroy)(AppHandle app, void* _Nullable data);
|
||||||
typedef void (*AppOnShow)(AppHandle app, void* _Nullable data, lv_obj_t* parent);
|
typedef void (*AppOnShow)(AppHandle app, void* _Nullable data, lv_obj_t* parent);
|
||||||
typedef void (*AppOnHide)(AppHandle app, void* _Nullable data);
|
typedef void (*AppOnHide)(AppHandle app, void* _Nullable data);
|
||||||
typedef void (*AppOnResult)(AppHandle app, void* _Nullable data, Result result, BundleHandle resultData);
|
typedef void (*AppOnResult)(AppHandle app, void* _Nullable data, Result result, BundleHandle resultData);
|
||||||
@ -35,9 +35,9 @@ typedef struct {
|
|||||||
/** If createData is specified, this one must be specified too */
|
/** If createData is specified, this one must be specified too */
|
||||||
AppDestroyData _Nullable destroyData;
|
AppDestroyData _Nullable destroyData;
|
||||||
/** Called when the app is launched (started) */
|
/** Called when the app is launched (started) */
|
||||||
AppOnStart _Nullable onStart;
|
AppOnCreate _Nullable onCreate;
|
||||||
/** Called when the app is exited (stopped) */
|
/** Called when the app is exited (stopped) */
|
||||||
AppOnStop _Nullable onStop;
|
AppOnDestroy _Nullable onDestroy;
|
||||||
/** Called when the app is about to be shown to the user (app becomes visible) */
|
/** Called when the app is about to be shown to the user (app becomes visible) */
|
||||||
AppOnShow _Nullable onShow;
|
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) */
|
/** 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) */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user