#pragma once #include #include #include #include #include #include #include "../Activity.h" // Cached data for a recent book struct CachedBookInfo { std::string path; // Full path to the book file std::string title; std::string coverPath; int progressPercent = 0; }; class HomeActivity final : public Activity { TaskHandle_t displayTaskHandle = nullptr; SemaphoreHandle_t renderingMutex = nullptr; int selectorIndex = 0; // Unified index: 0..bookCount-1 = books, bookCount+ = menu bool updateRequired = false; bool hasContinueReading = false; bool hasOpdsUrl = false; bool hasCoverImage = false; bool coverRendered = false; // Track if cover has been rendered once bool coverBufferStored = false; // Track if cover buffer is stored uint8_t* coverBuffer = nullptr; // HomeActivity's own buffer for cover image std::string lastBookTitle; std::string lastBookAuthor; std::string coverBmpPath; uint8_t cachedBatteryLevel = 0; uint32_t lastBatteryCheck = 0; // Cached recent books data (loaded once in onEnter) std::vector cachedRecentBooks; const std::function onContinueReading; const std::function onMyLibraryOpen; const std::function onSettingsOpen; const std::function onFileTransferOpen; const std::function onOpdsBrowserOpen; static void taskTrampoline(void* param); [[noreturn]] void displayTaskLoop(); void render(); int getMenuItemCount() const; bool storeCoverBuffer(); // Store frame buffer for cover image void freeCoverBuffer(); // Free the stored cover buffer void loadRecentBooksData(); // Load and cache recent books data public: explicit HomeActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, const std::function& onContinueReading, const std::function& onMyLibraryOpen, const std::function& onSettingsOpen, const std::function& onFileTransferOpen, const std::function& onOpdsBrowserOpen) : Activity("Home", renderer, mappedInput), onContinueReading(onContinueReading), onMyLibraryOpen(onMyLibraryOpen), onSettingsOpen(onSettingsOpen), onFileTransferOpen(onFileTransferOpen), onOpdsBrowserOpen(onOpdsBrowserOpen) {} void onEnter() override; void onExit() override; void loop() override; };