feat(DM+SdDDL): sequential full-season download queue, fix close crash, return true
- DM: add dl_missing_* fields to AppCtx for sequential queue - DM player: count_missing_in_season, find_next_missing, download_episode, download_missing_season_start/next - DM main onResult: auto-continue queue when dl_missing_active, updates status DL X/Y, finishes with done ok/fail - SdDownloader: file exists returns true (Already on SD) with total=file size, not false - SdDownloader: set_result_and_close minimal bundle (only success bool) to avoid internal heap OOM crash on close - SdDownloader: Cancel button becomes Close after done, calls tt_app_stop() directly (manual close per request, auto-close unreliable) - Fixes crash on close observed in demo mode (file exists) and after download done Tested on 192.168.68.133: SdDownloader shows Already on SD + Close, DM shows S10 5/6 after sequential, no crash on open/close cycles
This commit is contained in:
@@ -90,24 +90,29 @@ static void update_ui_status(const char *txt) {
|
||||
|
||||
static void set_result_and_close(bool success) {
|
||||
G.result_success = success;
|
||||
BundleHandle result_bundle = tt_bundle_alloc();
|
||||
size_t free_internal = heap_caps_get_free_size(MALLOC_CAP_INTERNAL);
|
||||
BundleHandle result_bundle = NULL;
|
||||
if (free_internal > 8000) {
|
||||
result_bundle = tt_bundle_alloc();
|
||||
}
|
||||
if (result_bundle) {
|
||||
tt_bundle_put_bool(result_bundle, "success", success);
|
||||
tt_bundle_put_string(result_bundle, "path", G.path);
|
||||
tt_bundle_put_int32(result_bundle, "bytes", G.total);
|
||||
if (!success) {
|
||||
tt_lvgl_lock(portMAX_DELAY);
|
||||
const char *status = G.lbl_status ? lv_label_get_text(G.lbl_status) : "failed";
|
||||
char status_copy[128];
|
||||
strncpy(status_copy, status, sizeof(status_copy)-1);
|
||||
status_copy[sizeof(status_copy)-1]=0;
|
||||
tt_lvgl_unlock();
|
||||
tt_bundle_put_string(result_bundle, "error", status_copy);
|
||||
}
|
||||
// Keep bundle minimal to avoid low heap crash (previous put_string path 512B caused OOM)
|
||||
tt_app_set_result(G.app_handle, success ? APP_RESULT_OK : APP_RESULT_ERROR, result_bundle);
|
||||
} else {
|
||||
// Low heap – return OK without bundle (DM will still refresh via has_slug)
|
||||
if (free_internal <= 8000) {
|
||||
ESP_LOGW(TAG, "Low heap %d, returning result without bundle", free_internal);
|
||||
}
|
||||
tt_app_set_result(G.app_handle, success ? APP_RESULT_OK : APP_RESULT_ERROR, NULL);
|
||||
}
|
||||
// Change Cancel button to Close once done (manual close, auto-close unreliable)
|
||||
tt_lvgl_lock(portMAX_DELAY);
|
||||
if (G.btn_cancel) {
|
||||
lv_obj_t* lbl = lv_obj_get_child(G.btn_cancel, 0);
|
||||
if (lbl) lv_label_set_text(lbl, "Close");
|
||||
}
|
||||
tt_lvgl_unlock();
|
||||
}
|
||||
|
||||
static bool download_one_file(const char *url, const char *path) {
|
||||
@@ -116,9 +121,10 @@ static bool download_one_file(const char *url, const char *path) {
|
||||
struct stat st;
|
||||
if (stat(path, &st)==0) {
|
||||
if (!G.override_existing) {
|
||||
ESP_LOGW(TAG, "File exists and override=false: %s", path);
|
||||
update_ui_status("File exists");
|
||||
return false;
|
||||
ESP_LOGW(TAG, "File exists and override=false: %s (returning true as cached)", path);
|
||||
G.total = st.st_size;
|
||||
update_ui_status("Already on SD");
|
||||
return true;
|
||||
} else {
|
||||
ESP_LOGI(TAG, "File exists but override=true, overwriting %s", path);
|
||||
unlink(path);
|
||||
@@ -294,7 +300,10 @@ static void download_task(void *arg) {
|
||||
|
||||
static void btn_cancel_cb(lv_event_t *e) {
|
||||
(void)e;
|
||||
if (!G.downloading) { tt_app_stop(); return; }
|
||||
if (!G.downloading) {
|
||||
tt_app_stop();
|
||||
return;
|
||||
}
|
||||
G.cancel_req = true;
|
||||
tt_lvgl_lock(portMAX_DELAY);
|
||||
if (G.lbl_status) lv_label_set_text(G.lbl_status, "Canceling...");
|
||||
|
||||
Reference in New Issue
Block a user