#pragma once #include #include #include #include #include #include #include "freertos/FreeRTOS.h" #include "freertos/task.h" #ifdef __cplusplus extern "C" { #endif #define TAG "DM" #define PB "http://192.168.68.110:8095" #define DM_DIR "/sdcard/dm" #define STATE_PATH "/sdcard/apps/one.tactility.discoverymountain/userdata/state.json" #define CACHE_PATH "/sdcard/apps/one.tactility.discoverymountain/userdata/cache.json" #define MAX_SEASONS 40 #define MAX_EPS 250 #define MP3_BUF 4096 typedef struct { int num; } SeasonInfo; typedef struct { char title[64]; char slug[96]; int season; int ep_num; char audio_url[128]; bool seen; } EpInfo; typedef struct { char slug[96]; int pos; } SavedPos; typedef struct { SeasonInfo seasons[MAX_SEASONS]; int season_cnt; EpInfo eps[MAX_EPS]; int ep_cnt; int cur_season; int cur_ep_idx; struct Device* stream_dev; AudioStreamHandle stream_handle; bool is_playing; bool is_paused; bool need_stop; TaskHandle_t play_handle; TaskHandle_t fetch_handle; TaskHandle_t dl_handle; int pos_sec; int total_sec; int volume; int last_pct; lv_obj_t *root; lv_obj_t *lbl_title, *lbl_meta, *bar, *lbl_time, *lbl_status, *btn_play; lv_obj_t *lbl_season; lv_obj_t *ep_list_cont; lv_obj_t *btn_seasons; lv_obj_t *btn_dl_missing; lv_obj_t *overlay, *dropdown; lv_obj_t *season_list_cont; lv_timer_t *ui_timer_handle; // Download UI lv_obj_t *dl_overlay; lv_obj_t *dl_bar; lv_obj_t *dl_lbl_pct; lv_obj_t *dl_lbl_detail; lv_obj_t *dl_lbl_title; lv_obj_t *dl_lbl_sub; char cur_title[128]; char last_slug[96]; bool fetching; bool downloading; volatile int dl_total; int dl_expected; int dl_last_ui_update; volatile bool dl_cancel_req; volatile bool fetch_cancel_req; char dl_ep_title[128]; char dl_slug[96]; int dl_season; int dl_ep_num; int dl_last_pct; // Per-episode resume SavedPos saved_pos[MAX_EPS]; int saved_pos_cnt; int last_save_tick; // External downloader integration (SdDownloader) int pending_dl_idx; // Full season download queue (sequential single-file to avoid batch crash) bool dl_missing_active; int dl_missing_season; int dl_missing_total; int dl_missing_done; int dl_missing_failed; } AppCtx; extern AppCtx G; #ifdef __cplusplus } #endif