Improved response handling

This commit is contained in:
Ken Van Hoeylandt 2025-10-24 00:09:11 +02:00
parent a19c55d783
commit 2e5f6cc0e8

View File

@ -15,6 +15,8 @@ namespace tt::app::apphub {
constexpr auto* TAG = "AppHub"; constexpr auto* TAG = "AppHub";
extern const AppManifest manifest;
static std::string getVersionWithoutPostfix() { static std::string getVersionWithoutPostfix() {
std::string version(TT_VERSION); std::string version(TT_VERSION);
auto index = version.find_first_of('-'); auto index = version.find_first_of('-');
@ -47,6 +49,14 @@ class AppHubApp final : public App {
std::string cachedAppsJsonFile = std::format("{}/apps.json", getTempPath()); std::string cachedAppsJsonFile = std::format("{}/apps.json", getTempPath());
std::unique_ptr<Thread> thread; std::unique_ptr<Thread> thread;
static std::shared_ptr<AppHubApp> _Nullable findAppInstance() {
auto app_context = getCurrentAppContext();
if (app_context->getManifest().appId != manifest.appId) {
return nullptr;
}
return std::static_pointer_cast<AppHubApp>(app_context->getApp());
}
enum class State { enum class State {
Refreshing, Refreshing,
ErrorTimeSync, ErrorTimeSync,
@ -63,6 +73,14 @@ class AppHubApp final : public App {
self->refresh(); self->refresh();
} }
void onRefreshSuccess() {
TT_LOG_I(TAG, "Request OK");
}
void onRefreshError() {
TT_LOG_E(TAG, "Request error");
}
static void createAppWidget(const std::shared_ptr<AppManifest>& manifest, lv_obj_t* list) { static void createAppWidget(const std::shared_ptr<AppManifest>& manifest, lv_obj_t* list) {
lv_obj_t* btn = lv_list_add_button(list, nullptr, manifest->appName.c_str()); lv_obj_t* btn = lv_list_add_button(list, nullptr, manifest->appName.c_str());
lv_obj_add_event_cb(btn, &onAppPressed, LV_EVENT_SHORT_CLICKED, manifest.get()); lv_obj_add_event_cb(btn, &onAppPressed, LV_EVENT_SHORT_CLICKED, manifest.get());
@ -109,10 +127,16 @@ class AppHubApp final : public App {
"/system/certificates/WE1.pem", "/system/certificates/WE1.pem",
download_path, download_path,
[] { [] {
TT_LOG_I(TAG, "Request OK"); auto app = findAppInstance();
if (app != nullptr) {
app->onRefreshSuccess();
}
}, },
[] { [] {
TT_LOG_E(TAG, "Request error"); auto app = findAppInstance();
if (app != nullptr) {
app->onRefreshError();
}
} }
); );
} }