feat(ui): Enhance AppClickUserData management for proper cleanup and tracking
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "ui/ui_handler.h"
|
||||
#include "ui/apps/registry.h"
|
||||
#include "esp_log.h"
|
||||
#include <algorithm>
|
||||
|
||||
#define TAG "UIHandler"
|
||||
|
||||
@@ -11,6 +12,11 @@ struct AppClickUserData {
|
||||
|
||||
UIHandler::~UIHandler() {
|
||||
deinit();
|
||||
// Clean up all allocated AppClickUserData
|
||||
for (void* data : app_click_user_data_) {
|
||||
delete static_cast<AppClickUserData*>(data);
|
||||
}
|
||||
app_click_user_data_.clear();
|
||||
}
|
||||
|
||||
esp_err_t UIHandler::init(void) {
|
||||
@@ -267,6 +273,10 @@ esp_err_t UIHandler::create_main_screen_(lv_obj_t* parent) {
|
||||
// Center the icon container
|
||||
lv_obj_center(app_icon_container);
|
||||
|
||||
// Create and track user data for the callback
|
||||
auto* click_data = new AppClickUserData { this, name };
|
||||
app_click_user_data_.push_back(click_data);
|
||||
|
||||
// Register click event to switch to the app
|
||||
lv_obj_add_event_cb(app_icon_container,
|
||||
[](lv_event_t* e) {
|
||||
@@ -282,7 +292,7 @@ esp_err_t UIHandler::create_main_screen_(lv_obj_t* parent) {
|
||||
}
|
||||
},
|
||||
LV_EVENT_CLICKED,
|
||||
new AppClickUserData { this, name }
|
||||
click_data
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user