| 23 | extern const AppManifest manifest; |
| 24 | |
| 25 | class AppHubApp final : public App { |
| 26 | |
| 27 | lv_obj_t* contentWrapper = nullptr; |
| 28 | lv_obj_t* refreshButton = nullptr; |
| 29 | std::string cachedAppsJsonFile = std::format("{}/app_hub.json", getTempPath()); |
| 30 | std::unique_ptr<Thread> thread; |
| 31 | std::vector<AppHubEntry> entries; |
| 32 | Mutex mutex; |
| 33 | |
| 34 | static std::shared_ptr<AppHubApp> findAppInstance() { |
| 35 | auto app_context = getCurrentAppContext(); |
| 36 | if (app_context->getManifest().appId != manifest.appId) { |
| 37 | return nullptr; |
| 38 | } |
| 39 | return std::static_pointer_cast<AppHubApp>(app_context->getApp()); |
| 40 | } |
| 41 | |
| 42 | static void onAppPressed(lv_event_t* e) { |
| 43 | const auto* self = static_cast<AppHubApp*>(lv_event_get_user_data(e)); |
| 44 | auto* widget = lv_event_get_target_obj(e); |
| 45 | const auto* user_data = lv_obj_get_user_data(widget); |
| 46 | const intptr_t index = reinterpret_cast<intptr_t>(user_data); |
| 47 | self->mutex.lock(); |
| 48 | if (index < self->entries.size()) { |
| 49 | apphubdetails::start(self->entries[index]); |
| 50 | } |
| 51 | self->mutex.unlock(); |
| 52 | } |
| 53 | |
| 54 | static void onRefreshPressed(lv_event_t* e) { |
| 55 | auto* self = static_cast<AppHubApp*>(lv_event_get_user_data(e)); |
| 56 | self->refresh(); |
| 57 | } |
| 58 | |
| 59 | void onRefreshSuccess() { |
| 60 | LOGGER.info("Request success"); |
| 61 | auto lock = lvgl::getSyncLock()->asScopedLock(); |
| 62 | lock.lock(); |
| 63 | |
| 64 | showApps(); |
| 65 | } |
| 66 | |
| 67 | void onRefreshError(const char* error) { |
| 68 | LOGGER.error("Request failed: {}", error); |
| 69 | auto lock = lvgl::getSyncLock()->asScopedLock(); |
| 70 | lock.lock(); |
| 71 | |
| 72 | showRefreshFailedError("Cannot reach server"); |
| 73 | } |
| 74 | |
| 75 | static void createAppWidget(const std::shared_ptr<AppManifest>& manifest, lv_obj_t* list) { |
| 76 | lv_obj_t* btn = lv_list_add_button(list, nullptr, manifest->appName.c_str()); |
| 77 | lv_obj_add_event_cb(btn, &onAppPressed, LV_EVENT_SHORT_CLICKED, manifest.get()); |
| 78 | } |
| 79 | |
| 80 | void showRefreshFailedError(const char* message) { |
| 81 | lv_obj_clean(contentWrapper); |
| 82 |
nothing calls this directly
no test coverage detected