f660550f86
- Added `AppHub` app - Added `AppHubDetails` app - Added `cJSON` dependency - Renamed `AppSim` module to `FirmwareSim` - Added extra `tt::app::alertdialg::start()` - Renamed `addApp()`, `removeApp()`, `findAppById()` and `getApps()` to `addAppManifest()`, `removeAppManifest()`, `findAppManifestById()` and `getAppManifests()` - Added `tt::lvgl::toolbar_clear_actions()` - Added `tt::network::EspHttpClient` as a thread-safe wrapper around `esp_http_client` - Added `tt::network::http::download()` to download files - Added `tt::network::ntp::isSynced()` - When time is synced, the timestamp is stored in NVS flash. On boot, it is restored. This helps SSL connections when doing a quick reset: when WiFi reconnects, the user doesn't have to wait for NTP sync before SSL works. - Added `tt::json::Reader` as a `cJSON` wrapper - Added `int64_t` support for `Preferences` - Added `int64_t` support for `Bundle` - Added dependencies: `cJSON`, `esp-tls` - When time is synced via NTP, disable time sync. - Added docs to 'tt::file::` functions - Added `tt::string::join()` that works with `std::vector<const char*>` - Fixed `tt::file::getLastPathSegment()` for the scenario when a path was passed with only a single segment - Set `CONFIG_ESP_MAIN_TASK_STACK_SIZE=5120` (from about 3k) for all boards - Set `CONFIG_MBEDTLS_SSL_PROTO_TLS1_3=y` for all boards
57 lines
1.8 KiB
C++
57 lines
1.8 KiB
C++
#include <Tactility/app/apphub/AppHubEntry.h>
|
|
#include <Tactility/file/File.h>
|
|
#include <Tactility/json/Reader.h>
|
|
|
|
namespace tt::app::apphub {
|
|
|
|
constexpr auto* TAG = "AppHubJson";
|
|
|
|
static bool parseEntry(const cJSON* object, AppHubEntry& entry) {
|
|
const json::Reader reader(object);
|
|
return reader.readString("appId", entry.appId) &&
|
|
reader.readString("appVersionName", entry.appVersionName) &&
|
|
reader.readInt32("appVersionCode", entry.appVersionCode) &&
|
|
reader.readString("appName", entry.appName) &&
|
|
reader.readString("appDescription", entry.appDescription) &&
|
|
reader.readString("targetSdk", entry.targetSdk) &&
|
|
reader.readString("file", entry.file) &&
|
|
reader.readStringArray("targetPlatforms", entry.targetPlatforms);
|
|
}
|
|
|
|
bool parseJson(const std::string& filePath, std::vector<AppHubEntry>& entries) {
|
|
auto lock = file::getLock(filePath)->asScopedLock();
|
|
lock.lock();
|
|
|
|
auto data = file::readString(filePath);
|
|
auto data_ptr = reinterpret_cast<const char*>(data.get());
|
|
auto* json = cJSON_Parse(data_ptr);
|
|
if (json == nullptr) {
|
|
TT_LOG_E(TAG, "Failed to parse %s", filePath.c_str());
|
|
return false;
|
|
}
|
|
|
|
const cJSON* apps_json = cJSON_GetObjectItemCaseSensitive(json, "apps");
|
|
if (!cJSON_IsArray(apps_json)) {
|
|
cJSON_Delete(json);
|
|
TT_LOG_E(TAG, "apps is not an array");
|
|
return false;
|
|
}
|
|
|
|
auto apps_size = cJSON_GetArraySize(apps_json);
|
|
entries.resize(apps_size);
|
|
for (int i = 0; i < apps_size; ++i) {
|
|
auto& entry = entries.at(i);
|
|
auto* entry_json = cJSON_GetArrayItem(apps_json, i);
|
|
if (!parseEntry(entry_json, entry)) {
|
|
TT_LOG_E(TAG, "Failed to read entry");
|
|
cJSON_Delete(json);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
cJSON_Delete(json);
|
|
return true;
|
|
}
|
|
|
|
}
|