Compare commits

...

2 Commits

Author SHA1 Message Date
Rivair Sabino dos Santos
7e24105d0c
Implement pagination for file entries in View class (#486)
* Implement pagination for file entries in View class

* Add resolveDirentFromListIndex method and refactor entry handling in View class

* Fix current_start_index calculation in View::update to prevent out-of-bounds access
2026-02-07 12:15:55 +01:00
Ken Van Hoeylandt
2aa41cb562
Revert LVGL from 9.4.0 to 9.3.0 (#488)
Because of stability issues on T-Deck
2026-02-07 08:26:21 +01:00
4 changed files with 134 additions and 73 deletions

View File

@ -44,6 +44,7 @@
- Support direct installation of an `.app` file with `tactility.py install helloworld.app <ip>` - Support direct installation of an `.app` file with `tactility.py install helloworld.app <ip>`
- Support `tactility.py target <ip>` to remember the device IP address. - Support `tactility.py target <ip>` to remember the device IP address.
- minitar/untarFile(): "entry->metadata.path" can escape its confined path (e.g. "../something") - minitar/untarFile(): "entry->metadata.path" can escape its confined path (e.g. "../something")
- Refactor elf loader code to make it multi-platform and to support multiple types of executables
## Medium Priority ## Medium Priority
@ -61,13 +62,10 @@
- Bug: Turn on WiFi (when testing it wasn't connected/connecting - just active). Open chat. Observe crash. - Bug: Turn on WiFi (when testing it wasn't connected/connecting - just active). Open chat. Observe crash.
- Bug: Crash handling app cannot be exited with an EncoderDevice. (current work-around is to manually reset the device) - Bug: Crash handling app cannot be exited with an EncoderDevice. (current work-around is to manually reset the device)
- I2C app should show error when I2C port is disabled when the scan button was manually pressed - I2C app should show error when I2C port is disabled when the scan button was manually pressed
- TactilitySDK: Support automatic scanning of header files so that we can generate the `tt_init.cpp` symbols list.
- elf_loader: split up symbol lists further (after radio support is implemented)
## Lower Priority ## Lower Priority
- Rename `Lock::lock()` and `Lock::unlock()` to `Lock::acquire()` and `Lock::release()`? - Rename `Lock::lock()` and `Lock::unlock()` to `Lock::acquire()` and `Lock::release()`?
- elf_loader: make main() entry-point optional (so we can build libraries, or have the `manifest` as a global symbol)
- Implement system suspend that turns off the screen - Implement system suspend that turns off the screen
- The boot button on some devices can be used as GPIO_NUM_0 at runtime - The boot button on some devices can be used as GPIO_NUM_0 at runtime
- Localize all apps - Localize all apps

View File

@ -55,7 +55,7 @@ dependencies:
rules: rules:
- if: "target == esp32s3" - if: "target == esp32s3"
espressif/esp_lvgl_port: "2.7.0" espressif/esp_lvgl_port: "2.7.0"
lvgl/lvgl: "9.4.0" lvgl/lvgl: "9.3.0"
FastEPD: FastEPD:
git: https://github.com/bitbank2/FastEPD.git git: https://github.com/bitbank2/FastEPD.git
version: 1.4.2 version: 1.4.2

View File

@ -11,6 +11,10 @@ namespace tt::app::files {
class View final { class View final {
std::shared_ptr<State> state; std::shared_ptr<State> state;
size_t current_start_index = 0;
size_t last_loaded_index = 0;
const size_t MAX_BATCH = 50;
lv_obj_t* dir_entry_list = nullptr; lv_obj_t* dir_entry_list = nullptr;
lv_obj_t* action_list = nullptr; lv_obj_t* action_list = nullptr;
@ -33,7 +37,7 @@ public:
explicit View(const std::shared_ptr<State>& state) : state(state) {} explicit View(const std::shared_ptr<State>& state) : state(state) {}
void init(const AppContext& appContext, lv_obj_t* parent); void init(const AppContext& appContext, lv_obj_t* parent);
void update(); void update(size_t start_index = 0);
void onNavigateUpPressed(); void onNavigateUpPressed();
void onDirEntryPressed(uint32_t index); void onDirEntryPressed(uint32_t index);
@ -45,6 +49,10 @@ public:
void onDirEntryListScrollBegin(); void onDirEntryListScrollBegin();
void onResult(LaunchId launchId, Result result, std::unique_ptr<Bundle> bundle); void onResult(LaunchId launchId, Result result, std::unique_ptr<Bundle> bundle);
void deinit(const AppContext& appContext); void deinit(const AppContext& appContext);
private:
bool resolveDirentFromListIndex(int32_t list_index, dirent& out_entry);
}; };
} }

View File

@ -1,5 +1,5 @@
#include <Tactility/app/files/View.h>
#include <Tactility/app/files/SupportedFiles.h> #include <Tactility/app/files/SupportedFiles.h>
#include <Tactility/app/files/View.h>
#include <Tactility/LogMessages.h> #include <Tactility/LogMessages.h>
#include <Tactility/Logger.h> #include <Tactility/Logger.h>
@ -10,11 +10,11 @@
#include <Tactility/app/imageviewer/ImageViewer.h> #include <Tactility/app/imageviewer/ImageViewer.h>
#include <Tactility/app/inputdialog/InputDialog.h> #include <Tactility/app/inputdialog/InputDialog.h>
#include <Tactility/app/notes/Notes.h> #include <Tactility/app/notes/Notes.h>
#include <tactility/check.h>
#include <Tactility/file/File.h> #include <Tactility/file/File.h>
#include <Tactility/kernel/Platform.h> #include <Tactility/kernel/Platform.h>
#include <Tactility/lvgl/LvglSync.h> #include <Tactility/lvgl/LvglSync.h>
#include <Tactility/lvgl/Toolbar.h> #include <Tactility/lvgl/Toolbar.h>
#include <tactility/check.h>
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
@ -104,7 +104,7 @@ void View::viewFile(const std::string& path, const std::string& filename) {
// install(filename); // install(filename);
auto message = std::format("Do you want to install {}?", filename); auto message = std::format("Do you want to install {}?", filename);
installAppPath = processed_filepath; installAppPath = processed_filepath;
auto choices = std::vector { "Yes", "No" }; auto choices = std::vector {"Yes", "No"};
installAppLaunchId = alertdialog::start("Install?", message, choices); installAppLaunchId = alertdialog::start("Install?", message, choices);
#endif #endif
} else if (isSupportedImageFile(filename)) { } else if (isSupportedImageFile(filename)) {
@ -123,59 +123,72 @@ void View::viewFile(const std::string& path, const std::string& filename) {
onNavigate(); onNavigate();
} }
bool View::resolveDirentFromListIndex(int32_t list_index, dirent& out_entry) {
const bool is_root = (state->getCurrentPath() == "/");
const bool has_back = (!is_root && current_start_index > 0);
if (has_back && list_index == 0) {
return false; // Back button
}
const size_t adjusted_index =
current_start_index + static_cast<size_t>(list_index) - (has_back ? 1 : 0);
return state->getDirent(static_cast<uint32_t>(adjusted_index), out_entry);
}
void View::onDirEntryPressed(uint32_t index) { void View::onDirEntryPressed(uint32_t index) {
dirent dir_entry; dirent dir_entry;
if (state->getDirent(index, dir_entry)) { if (!resolveDirentFromListIndex(static_cast<int32_t>(index), dir_entry)) {
LOGGER.info("Pressed {} {}", dir_entry.d_name, dir_entry.d_type); return;
state->setSelectedChildEntry(dir_entry.d_name); }
using namespace tt::file;
switch (dir_entry.d_type) { LOGGER.info("Pressed {} {}", dir_entry.d_name, dir_entry.d_type);
case TT_DT_DIR: state->setSelectedChildEntry(dir_entry.d_name);
case TT_DT_CHR:
state->setEntriesForChildPath(dir_entry.d_name); using namespace tt::file;
onNavigate(); switch (dir_entry.d_type) {
update(); case TT_DT_DIR:
break; case TT_DT_CHR:
case TT_DT_LNK: state->setEntriesForChildPath(dir_entry.d_name);
LOGGER.warn("opening links is not supported"); onNavigate();
break; update();
case TT_DT_REG: break;
viewFile(state->getCurrentPath(), dir_entry.d_name);
onNavigate(); case TT_DT_LNK:
break; LOGGER.warn("opening links is not supported");
default: break;
// Assume it's a file
// TODO: Find a better way to identify a file default:
viewFile(state->getCurrentPath(), dir_entry.d_name); viewFile(state->getCurrentPath(), dir_entry.d_name);
onNavigate(); onNavigate();
break; break;
}
} }
} }
void View::onDirEntryLongPressed(int32_t index) { void View::onDirEntryLongPressed(int32_t index) {
dirent dir_entry; dirent dir_entry;
if (state->getDirent(index, dir_entry)) { if (!resolveDirentFromListIndex(index, dir_entry)) {
LOGGER.info("Pressed {} {}", dir_entry.d_name, dir_entry.d_type); return;
state->setSelectedChildEntry(dir_entry.d_name); }
using namespace file;
switch (dir_entry.d_type) { LOGGER.info("Pressed {} {}", dir_entry.d_name, dir_entry.d_type);
case TT_DT_DIR: state->setSelectedChildEntry(dir_entry.d_name);
case TT_DT_CHR:
showActionsForDirectory(); using namespace file;
break; switch (dir_entry.d_type) {
case TT_DT_LNK: case TT_DT_DIR:
LOGGER.warn("Opening links is not supported"); case TT_DT_CHR:
break; showActionsForDirectory();
case TT_DT_REG: break;
showActionsForFile();
break; case TT_DT_LNK:
default: LOGGER.warn("Opening links is not supported");
// Assume it's a file break;
// TODO: Find a better way to identify a file
showActionsForFile(); default:
break; showActionsForFile();
} break;
} }
} }
@ -251,7 +264,7 @@ void View::onDeletePressed() {
LOGGER.info("Pending delete {}", file_path); LOGGER.info("Pending delete {}", file_path);
state->setPendingAction(State::ActionDelete); state->setPendingAction(State::ActionDelete);
std::string message = "Do you want to delete this?\n" + file_path; std::string message = "Do you want to delete this?\n" + file_path;
const std::vector<std::string> choices = { "Yes", "No" }; const std::vector<std::string> choices = {"Yes", "No"};
alertdialog::start("Are you sure?", message, choices); alertdialog::start("Are you sure?", message, choices);
} }
@ -289,25 +302,67 @@ void View::showActionsForFile() {
lv_obj_remove_flag(action_list, LV_OBJ_FLAG_HIDDEN); lv_obj_remove_flag(action_list, LV_OBJ_FLAG_HIDDEN);
} }
void View::update() { void View::update(size_t start_index) {
const bool is_root = (state->getCurrentPath() == "/");
auto scoped_lockable = lvgl::getSyncLock()->asScopedLock(); auto scoped_lockable = lvgl::getSyncLock()->asScopedLock();
if (scoped_lockable.lock(lvgl::defaultLockTime)) { if (!scoped_lockable.lock(lvgl::defaultLockTime)) {
lv_obj_clean(dir_entry_list);
state->withEntries([this](const std::vector<dirent>& entries) {
for (auto entry : entries) {
LOGGER.debug("Entry: {} {}", entry.d_name, entry.d_type);
createDirEntryWidget(dir_entry_list, entry);
}
});
if (state->getCurrentPath() == "/") {
lv_obj_add_flag(navigate_up_button, LV_OBJ_FLAG_HIDDEN);
} else {
lv_obj_remove_flag(navigate_up_button, LV_OBJ_FLAG_HIDDEN);
}
} else {
LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "lvgl"); LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "lvgl");
return;
}
lv_obj_clean(dir_entry_list);
current_start_index = start_index;
state->withEntries([this, is_root](const std::vector<dirent>& entries) {
size_t total_entries = entries.size();
if (current_start_index >= total_entries) {
current_start_index = (total_entries > MAX_BATCH)
? (total_entries - MAX_BATCH)
: 0;
}
size_t count = 0;
if (!is_root && current_start_index > 0) {
auto* back_btn = lv_list_add_btn(dir_entry_list, LV_SYMBOL_LEFT, "Back");
lv_obj_add_event_cb(back_btn, [](lv_event_t* event) {
auto* view = static_cast<View*>(lv_event_get_user_data(event));
size_t new_index = (view->current_start_index >= view->MAX_BATCH) ?
view->current_start_index - view->MAX_BATCH : 0;
view->update(new_index); }, LV_EVENT_SHORT_CLICKED, this);
}
for (size_t i = current_start_index; i < total_entries; ++i) {
auto entry = entries[i];
createDirEntryWidget(dir_entry_list, entry);
count++;
if (count >= MAX_BATCH) {
break;
}
}
last_loaded_index = std::min(current_start_index + count, total_entries);
if (!is_root && last_loaded_index < total_entries) {
if (total_entries > current_start_index &&
+ (total_entries - current_start_index) > MAX_BATCH) {
auto* next_btn = lv_list_add_btn(dir_entry_list, LV_SYMBOL_RIGHT, "Next");
lv_obj_add_event_cb(next_btn, [](lv_event_t* event) {
auto* view = static_cast<View*>(lv_event_get_user_data(event));
view->update(view->last_loaded_index); }, LV_EVENT_SHORT_CLICKED, this);
}
} else {
last_loaded_index = total_entries;
}
});
if (is_root) {
lv_obj_add_flag(navigate_up_button, LV_OBJ_FLAG_HIDDEN);
} else {
lv_obj_remove_flag(navigate_up_button, LV_OBJ_FLAG_HIDDEN);
} }
} }
@ -476,4 +531,4 @@ void View::deinit(const AppContext& appContext) {
lv_obj_remove_event_cb(dir_entry_list, dirEntryListScrollBeginCallback); lv_obj_remove_event_cb(dir_entry_list, dirEntryListScrollBeginCallback);
} }
} } // namespace tt::app::files