App hub and more (#383)
- 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
This commit is contained in:
committed by
GitHub
parent
e9384e0c11
commit
f660550f86
@@ -188,7 +188,7 @@ bool install(const std::string& path) {
|
||||
|
||||
manifest.appLocation = Location::external(renamed_target_path);
|
||||
|
||||
addApp(manifest);
|
||||
addAppManifest(manifest);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -211,7 +211,7 @@ bool uninstall(const std::string& appId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!removeApp(appId)) {
|
||||
if (!removeAppManifest(appId)) {
|
||||
TT_LOG_W(TAG, "Failed to remove app %s from registry", appId.c_str());
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ typedef std::unordered_map<std::string, std::shared_ptr<AppManifest>> AppManifes
|
||||
static AppManifestMap app_manifest_map;
|
||||
static Mutex hash_mutex(Mutex::Type::Normal);
|
||||
|
||||
void addApp(const AppManifest& manifest) {
|
||||
void addAppManifest(const AppManifest& manifest) {
|
||||
TT_LOG_I(TAG, "Registering manifest %s", manifest.appId.c_str());
|
||||
|
||||
hash_mutex.lock();
|
||||
@@ -29,7 +29,7 @@ void addApp(const AppManifest& manifest) {
|
||||
hash_mutex.unlock();
|
||||
}
|
||||
|
||||
bool removeApp(const std::string& id) {
|
||||
bool removeAppManifest(const std::string& id) {
|
||||
TT_LOG_I(TAG, "Removing manifest for %s", id.c_str());
|
||||
|
||||
auto lock = hash_mutex.asScopedLock();
|
||||
@@ -38,7 +38,7 @@ bool removeApp(const std::string& id) {
|
||||
return app_manifest_map.erase(id) == 1;
|
||||
}
|
||||
|
||||
_Nullable std::shared_ptr<AppManifest> findAppById(const std::string& id) {
|
||||
_Nullable std::shared_ptr<AppManifest> findAppManifestById(const std::string& id) {
|
||||
hash_mutex.lock();
|
||||
auto result = app_manifest_map.find(id);
|
||||
hash_mutex.unlock();
|
||||
@@ -49,7 +49,7 @@ _Nullable std::shared_ptr<AppManifest> findAppById(const std::string& id) {
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<AppManifest>> getApps() {
|
||||
std::vector<std::shared_ptr<AppManifest>> getAppManifests() {
|
||||
std::vector<std::shared_ptr<AppManifest>> manifests;
|
||||
hash_mutex.lock();
|
||||
for (const auto& item: app_manifest_map) {
|
||||
|
||||
@@ -31,6 +31,15 @@ LaunchId start(const std::string& title, const std::string& message, const std::
|
||||
return app::start(manifest.appId, bundle);
|
||||
}
|
||||
|
||||
LaunchId start(const std::string& title, const std::string& message, const std::vector<const char*>& buttonLabels) {
|
||||
std::string items_joined = string::join(buttonLabels, PARAMETER_ITEM_CONCATENATION_TOKEN);
|
||||
auto bundle = std::make_shared<Bundle>();
|
||||
bundle->putString(PARAMETER_BUNDLE_KEY_TITLE, title);
|
||||
bundle->putString(PARAMETER_BUNDLE_KEY_MESSAGE, message);
|
||||
bundle->putString(PARAMETER_BUNDLE_KEY_BUTTON_LABELS, items_joined);
|
||||
return app::start(manifest.appId, bundle);
|
||||
}
|
||||
|
||||
LaunchId start(const std::string& title, const std::string& message) {
|
||||
auto bundle = std::make_shared<Bundle>();
|
||||
bundle->putString(PARAMETER_BUNDLE_KEY_TITLE, title);
|
||||
@@ -57,8 +66,6 @@ static std::string getTitleParameter(std::shared_ptr<const Bundle> bundle) {
|
||||
|
||||
class AlertDialogApp : public App {
|
||||
|
||||
private:
|
||||
|
||||
static void onButtonClickedCallback(lv_event_t* e) {
|
||||
auto app = std::static_pointer_cast<AlertDialogApp>(getCurrentApp());
|
||||
assert(app != nullptr);
|
||||
@@ -66,7 +73,6 @@ private:
|
||||
}
|
||||
|
||||
void onButtonClicked(lv_event_t* e) {
|
||||
lv_event_code_t code = lv_event_get_code(e);
|
||||
auto index = reinterpret_cast<std::size_t>(lv_event_get_user_data(e));
|
||||
TT_LOG_I(TAG, "Selected item at index %d", index);
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
const auto parameters = app.getParameters();
|
||||
tt_check(parameters != nullptr, "Parameters missing");
|
||||
auto app_id = parameters->getString("appId");
|
||||
manifest = findAppById(app_id);
|
||||
manifest = findAppManifestById(app_id);
|
||||
assert(manifest != nullptr);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
#include <Tactility/app/apphub/AppHub.h>
|
||||
|
||||
#include <format>
|
||||
|
||||
namespace tt::app::apphub {
|
||||
|
||||
constexpr auto* BASE_URL = "https://cdn.tactility.one/apps";
|
||||
|
||||
static std::string getVersionWithoutPostfix() {
|
||||
std::string version(TT_VERSION);
|
||||
auto index = version.find_first_of('-');
|
||||
if (index == std::string::npos) {
|
||||
return version;
|
||||
} else {
|
||||
return version.substr(0, index);
|
||||
}
|
||||
}
|
||||
|
||||
std::string getAppsJsonUrl() {
|
||||
return std::format("{}/{}/apps.json", BASE_URL, getVersionWithoutPostfix());
|
||||
}
|
||||
|
||||
std::string getDownloadUrl(const std::string& relativePath) {
|
||||
return std::format("{}/{}/{}", BASE_URL, getVersionWithoutPostfix(), relativePath);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
#include <Tactility/app/apphub/AppHub.h>
|
||||
#include <Tactility/app/apphub/AppHubEntry.h>
|
||||
#include <Tactility/app/apphubdetails/AppHubDetailsApp.h>
|
||||
#include <Tactility/file/File.h>
|
||||
#include <Tactility/lvgl/LvglSync.h>
|
||||
#include <Tactility/lvgl/Spinner.h>
|
||||
#include <Tactility/lvgl/Toolbar.h>
|
||||
#include <Tactility/network/Http.h>
|
||||
#include <Tactility/Paths.h>
|
||||
#include <Tactility/service/loader/Loader.h>
|
||||
#include <Tactility/service/wifi/Wifi.h>
|
||||
|
||||
#include <lvgl.h>
|
||||
#include <format>
|
||||
|
||||
namespace tt::app::apphub {
|
||||
|
||||
constexpr auto* TAG = "AppHub";
|
||||
|
||||
extern const AppManifest manifest;
|
||||
|
||||
class AppHubApp final : public App {
|
||||
|
||||
lv_obj_t* contentWrapper = nullptr;
|
||||
lv_obj_t* refreshButton = nullptr;
|
||||
std::string cachedAppsJsonFile = std::format("{}/app_hub.json", getTempPath());
|
||||
std::unique_ptr<Thread> thread;
|
||||
std::vector<AppHubEntry> entries;
|
||||
Mutex mutex;
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
static void onAppPressed(lv_event_t* e) {
|
||||
const auto* self = static_cast<AppHubApp*>(lv_event_get_user_data(e));
|
||||
auto* widget = lv_event_get_target_obj(e);
|
||||
const auto* user_data = lv_obj_get_user_data(widget);
|
||||
#ifdef ESP_PLATFORM
|
||||
const int index = reinterpret_cast<int>(user_data);
|
||||
#else
|
||||
const long long index = reinterpret_cast<long long>(user_data);
|
||||
#endif
|
||||
self->mutex.lock();
|
||||
if (index < self->entries.size()) {
|
||||
apphubdetails::start(self->entries[index]);
|
||||
}
|
||||
self->mutex.unlock();
|
||||
}
|
||||
|
||||
static void onRefreshPressed(lv_event_t* e) {
|
||||
auto* self = static_cast<AppHubApp*>(lv_event_get_user_data(e));
|
||||
self->refresh();
|
||||
}
|
||||
|
||||
void onRefreshSuccess() {
|
||||
TT_LOG_I(TAG, "Request success");
|
||||
auto lock = lvgl::getSyncLock()->asScopedLock();
|
||||
lock.lock();
|
||||
|
||||
showApps();
|
||||
}
|
||||
|
||||
void onRefreshError(const char* error) {
|
||||
TT_LOG_E(TAG, "Request failed: %s", error);
|
||||
auto lock = lvgl::getSyncLock()->asScopedLock();
|
||||
lock.lock();
|
||||
|
||||
showRefreshFailedError("Cannot reach server");
|
||||
}
|
||||
|
||||
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_add_event_cb(btn, &onAppPressed, LV_EVENT_SHORT_CLICKED, manifest.get());
|
||||
}
|
||||
|
||||
void showRefreshFailedError(const char* message) {
|
||||
lv_obj_clean(contentWrapper);
|
||||
|
||||
auto* label = lv_label_create(contentWrapper);
|
||||
lv_label_set_text(label, message);
|
||||
lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);
|
||||
|
||||
lv_obj_remove_flag(refreshButton, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
|
||||
void showNoInternet() {
|
||||
showRefreshFailedError("No Internet Connection");
|
||||
}
|
||||
|
||||
void showTimeNotSynced() {
|
||||
showRefreshFailedError("Time is not synced yet.\nIt's required to establish a secure connection.");
|
||||
}
|
||||
|
||||
void showApps() {
|
||||
lv_obj_clean(contentWrapper);
|
||||
mutex.lock();
|
||||
if (parseJson(cachedAppsJsonFile, entries)) {
|
||||
std::ranges::sort(entries, [](auto left, auto right) {
|
||||
return left.appName < right.appName;
|
||||
});
|
||||
|
||||
auto* list = lv_list_create(contentWrapper);
|
||||
lv_obj_set_style_pad_all(list, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_size(list, LV_PCT(100), LV_SIZE_CONTENT);
|
||||
for (int i = 0; i < entries.size(); i++) {
|
||||
auto& entry = entries[i];
|
||||
TT_LOG_I(TAG, "Adding %s", entry.appName.c_str());
|
||||
const char* icon = findAppManifestById(entry.appId) != nullptr ? LV_SYMBOL_OK : nullptr;
|
||||
auto* entry_button = lv_list_add_button(list, icon, entry.appName.c_str());
|
||||
lv_obj_set_user_data(entry_button, reinterpret_cast<void*>(i));
|
||||
lv_obj_add_event_cb(entry_button, onAppPressed, LV_EVENT_SHORT_CLICKED, this);
|
||||
}
|
||||
} else {
|
||||
showRefreshFailedError("Failed to load content");
|
||||
}
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
void refresh() {
|
||||
lv_obj_clean(contentWrapper);
|
||||
auto* spinner = lvgl::spinner_create(contentWrapper);
|
||||
lv_obj_align(spinner, LV_ALIGN_CENTER, 0, 0);
|
||||
|
||||
lv_obj_add_flag(refreshButton, LV_OBJ_FLAG_HIDDEN);
|
||||
|
||||
if (service::wifi::getRadioState() != service::wifi::RadioState::ConnectionActive) {
|
||||
showNoInternet();
|
||||
return;
|
||||
}
|
||||
|
||||
if (file::isFile(cachedAppsJsonFile)) {
|
||||
showApps();
|
||||
}
|
||||
|
||||
network::http::download(
|
||||
getAppsJsonUrl(),
|
||||
CERTIFICATE_PATH,
|
||||
cachedAppsJsonFile,
|
||||
[] {
|
||||
auto app = findAppInstance();
|
||||
if (app != nullptr) {
|
||||
app->onRefreshSuccess();
|
||||
}
|
||||
},
|
||||
[](const char* error) {
|
||||
auto app = findAppInstance();
|
||||
if (app != nullptr) {
|
||||
app->onRefreshError(error);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
void onShow(TT_UNUSED AppContext& app, lv_obj_t* parent) override {
|
||||
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
|
||||
lv_obj_set_style_pad_row(parent, 0, LV_STATE_DEFAULT);
|
||||
|
||||
auto* toolbar = lvgl::toolbar_create(parent, app);
|
||||
refreshButton = lvgl::toolbar_add_image_button_action(toolbar, LV_SYMBOL_REFRESH, onRefreshPressed, this);
|
||||
lv_obj_add_flag(refreshButton, LV_OBJ_FLAG_HIDDEN);
|
||||
|
||||
contentWrapper = lv_obj_create(parent);
|
||||
lv_obj_set_width(contentWrapper, LV_PCT(100));
|
||||
lv_obj_set_flex_grow(contentWrapper, 1);
|
||||
lv_obj_set_style_pad_all(contentWrapper, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_pad_ver(contentWrapper, 0, LV_STATE_DEFAULT);
|
||||
|
||||
refresh();
|
||||
}
|
||||
};
|
||||
|
||||
extern const AppManifest manifest = {
|
||||
.appId = "AppHub",
|
||||
.appName = "App Hub",
|
||||
.appCategory = Category::System,
|
||||
.createApp = create<AppHubApp>,
|
||||
};
|
||||
|
||||
} // namespace
|
||||
@@ -0,0 +1,56 @@
|
||||
#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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,248 @@
|
||||
#include <Tactility/app/alertdialog/AlertDialog.h>
|
||||
#include <Tactility/app/apphub/AppHub.h>
|
||||
#include <Tactility/app/apphub/AppHubEntry.h>
|
||||
#include <Tactility/app/AppRegistration.h>
|
||||
#include <Tactility/file/File.h>
|
||||
#include <Tactility/lvgl/LvglSync.h>
|
||||
#include <Tactility/lvgl/Toolbar.h>
|
||||
#include <Tactility/network/Http.h>
|
||||
#include <Tactility/Paths.h>
|
||||
#include <Tactility/service/loader/Loader.h>
|
||||
#include <Tactility/StringUtils.h>
|
||||
|
||||
#include <lvgl.h>
|
||||
#include <format>
|
||||
|
||||
namespace tt::app::apphubdetails {
|
||||
|
||||
extern const AppManifest manifest;
|
||||
constexpr auto* TAG = "AppHubDetails";
|
||||
|
||||
static std::shared_ptr<Bundle> toBundle(const apphub::AppHubEntry& entry) {
|
||||
auto bundle = std::make_shared<Bundle>();
|
||||
bundle->putString("appId", entry.appId);
|
||||
bundle->putString("appVersionName", entry.appVersionName);
|
||||
bundle->putInt32("appVersionCode", entry.appVersionCode);
|
||||
bundle->putString("appName", entry.appName);
|
||||
bundle->putString("appDescription", entry.appDescription);
|
||||
bundle->putString("targetSdk", entry.targetSdk);
|
||||
bundle->putString("file", entry.file);
|
||||
bundle->putString("targetPlatforms", string::join(entry.targetPlatforms, ","));
|
||||
return bundle;
|
||||
}
|
||||
|
||||
static bool fromBundle(const Bundle& bundle, apphub::AppHubEntry& entry) {
|
||||
std::string target_platforms_string;
|
||||
auto result = bundle.optString("appId", entry.appId) &&
|
||||
bundle.optString("appVersionName", entry.appVersionName) &&
|
||||
bundle.optInt32("appVersionCode", entry.appVersionCode) &&
|
||||
bundle.optString("appName", entry.appName) &&
|
||||
bundle.optString("appDescription", entry.appDescription) &&
|
||||
bundle.optString("targetSdk", entry.targetSdk) &&
|
||||
bundle.optString("file", entry.file) &&
|
||||
bundle.optString("targetPlatforms", target_platforms_string);
|
||||
entry.targetPlatforms = string::split(target_platforms_string, ",");
|
||||
return result;
|
||||
}
|
||||
|
||||
class AppHubDetailsApp final : public App {
|
||||
|
||||
static constexpr auto* CONFIRM_TEXT = "Confirm";
|
||||
static constexpr auto* CANCEL_TEXT = "Cancel";
|
||||
static constexpr auto CONFIRMATION_BUTTON_INDEX = 0;
|
||||
const std::vector<const char*> CONFIRM_CANCEL_LABELS = { CONFIRM_TEXT, CANCEL_TEXT };
|
||||
|
||||
apphub::AppHubEntry entry;
|
||||
std::shared_ptr<AppManifest> entryManifest;
|
||||
lv_obj_t* toolbar = nullptr;
|
||||
lv_obj_t* spinner = nullptr;
|
||||
lv_obj_t* updateButton = nullptr;
|
||||
lv_obj_t* updateLabel = nullptr;
|
||||
LaunchId installLaunchId = -1;
|
||||
LaunchId uninstallLaunchId = -1;
|
||||
LaunchId updateLaunchId = -1;
|
||||
|
||||
LaunchId showConfirmDialog(const char* action) {
|
||||
const auto message = std::format("{} {}?", action, entry.appName);
|
||||
return alertdialog::start(CONFIRM_TEXT, message, CONFIRM_CANCEL_LABELS);
|
||||
}
|
||||
|
||||
static void onInstallPressed(lv_event_t* e) {
|
||||
auto* self = static_cast<AppHubDetailsApp*>(lv_event_get_user_data(e));
|
||||
self->installLaunchId = self->showConfirmDialog("Install");
|
||||
}
|
||||
|
||||
static void onUninstallPressed(lv_event_t* e) {
|
||||
auto* self = static_cast<AppHubDetailsApp*>(lv_event_get_user_data(e));
|
||||
self->uninstallLaunchId = self->showConfirmDialog("Uninstall");
|
||||
}
|
||||
|
||||
static void onUpdatePressed(lv_event_t* e) {
|
||||
auto* self = static_cast<AppHubDetailsApp*>(lv_event_get_user_data(e));
|
||||
self->updateLaunchId = self->showConfirmDialog("Update");
|
||||
}
|
||||
|
||||
void uninstallApp() {
|
||||
TT_LOG_I(TAG, "Uninstall");
|
||||
|
||||
lvgl::getSyncLock()->lock();
|
||||
lv_obj_remove_flag(spinner, LV_OBJ_FLAG_HIDDEN);
|
||||
lvgl::getSyncLock()->unlock();
|
||||
|
||||
uninstall(entry.appId);
|
||||
|
||||
lvgl::getSyncLock()->lock();
|
||||
updateViews();
|
||||
lvgl::getSyncLock()->unlock();
|
||||
}
|
||||
|
||||
void doInstall() {
|
||||
auto url = apphub::getDownloadUrl(entry.file);
|
||||
auto file_name = file::getLastPathSegment(entry.file);
|
||||
auto temp_file_path = std::format("{}/{}", getTempPath(), file_name);
|
||||
network::http::download(
|
||||
url,
|
||||
apphub::CERTIFICATE_PATH,
|
||||
temp_file_path,
|
||||
[this, temp_file_path] {
|
||||
install(temp_file_path);
|
||||
|
||||
if (!file::deleteFile(temp_file_path.c_str())) {
|
||||
TT_LOG_W(TAG, "Failed to remove %s", temp_file_path.c_str());
|
||||
} else {
|
||||
TT_LOG_I(TAG, "Deleted temporary file %s", temp_file_path.c_str());
|
||||
}
|
||||
|
||||
lvgl::getSyncLock()->lock();
|
||||
updateViews();
|
||||
lvgl::getSyncLock()->unlock();
|
||||
},
|
||||
[temp_file_path](const char* errorMessage) {
|
||||
TT_LOG_E(TAG, "Download failed: %s", errorMessage);
|
||||
alertdialog::start("Error", "Failed to install app");
|
||||
|
||||
if (file::isFile(temp_file_path) && !file::deleteFile(temp_file_path.c_str())) {
|
||||
TT_LOG_W(TAG, "Failed to remove %s", temp_file_path.c_str());
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void installApp() {
|
||||
TT_LOG_I(TAG, "Install");
|
||||
|
||||
lvgl::getSyncLock()->lock();
|
||||
lv_obj_remove_flag(spinner, LV_OBJ_FLAG_HIDDEN);
|
||||
lvgl::getSyncLock()->unlock();
|
||||
|
||||
doInstall();
|
||||
}
|
||||
|
||||
void updateApp() {
|
||||
TT_LOG_I(TAG, "Update");
|
||||
|
||||
lvgl::getSyncLock()->lock();
|
||||
lv_obj_remove_flag(spinner, LV_OBJ_FLAG_HIDDEN);
|
||||
lvgl::getSyncLock()->unlock();
|
||||
|
||||
TT_LOG_I(TAG, "Removing previous version");
|
||||
uninstall(entry.appId);
|
||||
TT_LOG_I(TAG, "Installing new version");
|
||||
doInstall();
|
||||
}
|
||||
|
||||
void updateViews() {
|
||||
lvgl::toolbar_clear_actions(toolbar);
|
||||
const auto manifest = findAppManifestById(entry.appId);
|
||||
spinner = lvgl::toolbar_add_spinner_action(toolbar);
|
||||
lv_obj_add_flag(spinner, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_add_flag(updateLabel, LV_OBJ_FLAG_HIDDEN);
|
||||
if (manifest != nullptr) {
|
||||
if (manifest->appVersionCode < entry.appVersionCode) {
|
||||
updateButton = lvgl::toolbar_add_image_button_action(toolbar, LV_SYMBOL_DOWNLOAD, onUpdatePressed, this);
|
||||
lv_obj_remove_flag(updateLabel, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
lvgl::toolbar_add_image_button_action(toolbar, LV_SYMBOL_TRASH, onUninstallPressed, this);
|
||||
} else {
|
||||
lvgl::toolbar_add_image_button_action(toolbar, LV_SYMBOL_DOWNLOAD, onInstallPressed, this);
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
void onCreate(AppContext& appContext) override {
|
||||
auto parameters = appContext.getParameters();
|
||||
if (parameters == nullptr) {
|
||||
TT_LOG_E(TAG, "No parameters");
|
||||
stop();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!fromBundle(*parameters.get(), entry)) {
|
||||
TT_LOG_E(TAG, "Invalid parameters");
|
||||
stop();
|
||||
}
|
||||
}
|
||||
|
||||
void onShow(TT_UNUSED AppContext& app, lv_obj_t* parent) override {
|
||||
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
|
||||
lv_obj_set_style_pad_row(parent, 0, LV_STATE_DEFAULT);
|
||||
|
||||
toolbar = lvgl::toolbar_create(parent, entry.appName.c_str());
|
||||
auto* wrapper = lv_obj_create(parent);
|
||||
lv_obj_set_width(wrapper, LV_PCT(100));
|
||||
lv_obj_set_flex_grow(wrapper, 1);
|
||||
lv_obj_set_flex_flow(wrapper, LV_FLEX_FLOW_COLUMN);
|
||||
|
||||
updateLabel = lv_label_create(wrapper);
|
||||
lv_label_set_text(updateLabel, "Update available!");
|
||||
lv_obj_set_style_text_color(updateLabel, lv_color_make(0xff, 0xff, 00), LV_STATE_DEFAULT);
|
||||
|
||||
auto* description_label = lv_label_create(wrapper);
|
||||
lv_obj_set_width(description_label, LV_PCT(100));
|
||||
lv_label_set_long_mode(description_label, LV_LABEL_LONG_MODE_WRAP);
|
||||
if (!entry.appDescription.empty()) {
|
||||
lv_label_set_text(description_label, entry.appDescription.c_str());
|
||||
} else {
|
||||
lv_label_set_text(description_label, "This app has no description yet.");
|
||||
}
|
||||
|
||||
auto* version_label = lv_label_create(wrapper);
|
||||
lv_label_set_text_fmt(version_label, "Version %s", entry.appVersionName.c_str());
|
||||
|
||||
updateViews();
|
||||
}
|
||||
|
||||
void onResult(AppContext& appContext, LaunchId launchId, Result result, std::unique_ptr<Bundle> resultData) override {
|
||||
if (result != Result::Ok) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (alertdialog::getResultIndex(*resultData.get()) != CONFIRMATION_BUTTON_INDEX) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (launchId == installLaunchId) {
|
||||
installApp();
|
||||
} else if (launchId == uninstallLaunchId) {
|
||||
uninstallApp();
|
||||
} else if (launchId == updateLaunchId) {
|
||||
updateApp();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void start(const apphub::AppHubEntry& entry) {
|
||||
const auto bundle = toBundle(entry);
|
||||
app::start(manifest.appId, bundle);
|
||||
}
|
||||
|
||||
extern const AppManifest manifest = {
|
||||
.appId = "AppHubDetails",
|
||||
.appName = "App Details",
|
||||
.appCategory = Category::System,
|
||||
.appFlags = AppManifest::Flags::Hidden,
|
||||
.createApp = create<AppHubDetailsApp>,
|
||||
};
|
||||
|
||||
} // namespace
|
||||
@@ -36,7 +36,7 @@ public:
|
||||
auto parent_content_height = lv_obj_get_content_height(parent);
|
||||
lv_obj_set_height(list, parent_content_height - toolbar_height);
|
||||
|
||||
auto manifests = getApps();
|
||||
auto manifests = getAppManifests();
|
||||
std::ranges::sort(manifests, SortAppManifestByName);
|
||||
|
||||
for (const auto& manifest: manifests) {
|
||||
|
||||
@@ -37,7 +37,7 @@ public:
|
||||
auto parent_content_height = lv_obj_get_content_height(parent);
|
||||
lv_obj_set_height(list, parent_content_height - toolbar_height);
|
||||
|
||||
auto manifests = getApps();
|
||||
auto manifests = getAppManifests();
|
||||
std::ranges::sort(manifests, SortAppManifestByName);
|
||||
|
||||
size_t app_count = 0;
|
||||
|
||||
@@ -92,7 +92,8 @@ void View::viewFile(const std::string& path, const std::string& filename) {
|
||||
// install(filename);
|
||||
auto message = std::format("Do you want to install {}?", filename);
|
||||
installAppPath = processed_filepath;
|
||||
installAppLaunchId = alertdialog::start("Install?", message, { "Yes", "No" });
|
||||
auto choices = std::vector { "Yes", "No" };
|
||||
installAppLaunchId = alertdialog::start("Install?", message, choices);
|
||||
#endif
|
||||
} else if (isSupportedImageFile(filename)) {
|
||||
imageviewer::start(processed_filepath);
|
||||
|
||||
@@ -35,7 +35,7 @@ class SettingsApp final : public App {
|
||||
lv_obj_set_width(list, LV_PCT(100));
|
||||
lv_obj_set_flex_grow(list, 1);
|
||||
|
||||
auto manifests = getApps();
|
||||
auto manifests = getAppManifests();
|
||||
std::ranges::sort(manifests, SortAppManifestByName);
|
||||
for (const auto& manifest: manifests) {
|
||||
if (manifest->appCategory == Category::Settings) {
|
||||
|
||||
Reference in New Issue
Block a user