From c6640aa645696362a0a6d66c611a7deac9bae3eb Mon Sep 17 00:00:00 2001 From: CaptainFrito Date: Mon, 26 Jan 2026 14:15:25 +0700 Subject: [PATCH] Fixed crashes in Home and book selection --- src/activities/home/HomeActivity.cpp | 2 +- src/activities/home/MyLibraryActivity.cpp | 12 ++++-- src/activities/reader/EpubReaderActivity.cpp | 39 -------------------- src/components/themes/lyra/LyraTheme.cpp | 4 +- 4 files changed, 11 insertions(+), 46 deletions(-) diff --git a/src/activities/home/HomeActivity.cpp b/src/activities/home/HomeActivity.cpp index 06c23304..4a0bd349 100644 --- a/src/activities/home/HomeActivity.cpp +++ b/src/activities/home/HomeActivity.cpp @@ -149,7 +149,7 @@ void HomeActivity::onEnter() { updateRequired = true; xTaskCreate(&HomeActivity::taskTrampoline, "HomeActivityTask", - 4096, // Stack size (increased for cover image rendering) + 8192, // Stack size this, // Parameters 1, // Priority &displayTaskHandle // Task handle diff --git a/src/activities/home/MyLibraryActivity.cpp b/src/activities/home/MyLibraryActivity.cpp index 2ce3664a..aadcd2dd 100644 --- a/src/activities/home/MyLibraryActivity.cpp +++ b/src/activities/home/MyLibraryActivity.cpp @@ -157,6 +157,7 @@ void MyLibraryActivity::loop() { if (currentTab == Tab::Recent) { if (!bookPaths.empty() && selectorIndex < static_cast(bookPaths.size())) { onSelectBook(bookPaths[selectorIndex], currentTab); + return; } } else { if (files.empty()) { @@ -171,6 +172,7 @@ void MyLibraryActivity::loop() { updateRequired = true; } else { onSelectBook(basepath + files[selectorIndex], currentTab); + return; } } } @@ -207,18 +209,20 @@ void MyLibraryActivity::loop() { updateRequired = true; return; } + + int listSize = (currentTab == Tab::Recent) ? static_cast(bookTitles.size()) : static_cast(files.size()); if (upReleased) { if (skipPage) { - selectorIndex = ((selectorIndex / pageItems - 1) * pageItems + files.size()) % files.size(); + selectorIndex = ((selectorIndex / pageItems - 1) * pageItems + listSize) % listSize; } else { - selectorIndex = (selectorIndex + files.size() - 1) % files.size(); + selectorIndex = (selectorIndex + listSize - 1) % listSize; } updateRequired = true; } else if (downReleased) { if (skipPage) { - selectorIndex = ((selectorIndex / pageItems + 1) * pageItems) % files.size(); + selectorIndex = ((selectorIndex / pageItems + 1) * pageItems) % listSize; } else { - selectorIndex = (selectorIndex + 1) % files.size(); + selectorIndex = (selectorIndex + 1) % listSize; } updateRequired = true; } diff --git a/src/activities/reader/EpubReaderActivity.cpp b/src/activities/reader/EpubReaderActivity.cpp index a8198c50..fa8ef9cf 100644 --- a/src/activities/reader/EpubReaderActivity.cpp +++ b/src/activities/reader/EpubReaderActivity.cpp @@ -285,45 +285,6 @@ void EpubReaderActivity::renderScreen() { viewportHeight, SETTINGS.hyphenationEnabled)) { Serial.printf("[%lu] [ERS] Cache not found, building...\n", millis()); - // // Progress bar dimensions - // constexpr int barWidth = 200; - // constexpr int barHeight = 10; - // constexpr int boxMargin = 20; - // const int textWidth = renderer.getTextWidth(UI_12_FONT_ID, "Indexing..."); - // const int boxWidthWithBar = (barWidth > textWidth ? barWidth : textWidth) + boxMargin * 2; - // const int boxWidthNoBar = textWidth + boxMargin * 2; - // const int boxHeightWithBar = renderer.getLineHeight(UI_12_FONT_ID) + barHeight + boxMargin * 3; - // const int boxHeightNoBar = renderer.getLineHeight(UI_12_FONT_ID) + boxMargin * 2; - // const int boxXWithBar = (renderer.getScreenWidth() - boxWidthWithBar) / 2; - // const int boxXNoBar = (renderer.getScreenWidth() - boxWidthNoBar) / 2; - // constexpr int boxY = 50; - // const int barX = boxXWithBar + (boxWidthWithBar - barWidth) / 2; - // const int barY = boxY + renderer.getLineHeight(UI_12_FONT_ID) + boxMargin * 2; - - // // Always show "Indexing..." text first - // { - // renderer.fillRect(boxXNoBar, boxY, boxWidthNoBar, boxHeightNoBar, false); - // renderer.drawText(UI_12_FONT_ID, boxXNoBar + boxMargin, boxY + boxMargin, "Indexing..."); - // renderer.drawRect(boxXNoBar + 5, boxY + 5, boxWidthNoBar - 10, boxHeightNoBar - 10); - // renderer.displayBuffer(); - // pagesUntilFullRefresh = 0; - // } - - // // Setup callback - only called for chapters >= 50KB, redraws with progress bar - // auto progressSetup = [this, boxXWithBar, boxWidthWithBar, boxHeightWithBar, barX, barY] { - // renderer.fillRect(boxXWithBar, boxY, boxWidthWithBar, boxHeightWithBar, false); - // renderer.drawText(UI_12_FONT_ID, boxXWithBar + boxMargin, boxY + boxMargin, "Indexing..."); - // renderer.drawRect(boxXWithBar + 5, boxY + 5, boxWidthWithBar - 10, boxHeightWithBar - 10); - // renderer.drawRect(barX, barY, barWidth, barHeight); - // renderer.displayBuffer(); - // }; - - // // Progress callback to update progress bar - // auto progressCallback = [this, barX, barY, barWidth, barHeight](int progress) { - // const int fillWidth = (barWidth - 2) * progress / 100; - // renderer.fillRect(barX + 1, barY + 1, fillWidth, barHeight - 2, true); - // renderer.displayBuffer(EInkDisplay::FAST_REFRESH); - // }; auto popupCallbacks = UITheme::drawPopupWithProgress(renderer, "Indexing..."); if (!section->createSectionFile(SETTINGS.getReaderFontId(), SETTINGS.getReaderLineCompression(), diff --git a/src/components/themes/lyra/LyraTheme.cpp b/src/components/themes/lyra/LyraTheme.cpp index 73e3671b..0826ed0e 100644 --- a/src/components/themes/lyra/LyraTheme.cpp +++ b/src/components/themes/lyra/LyraTheme.cpp @@ -319,7 +319,7 @@ void LyraTheme::drawButtonMenu(GfxRenderer& renderer, Rect rect, int buttonCount } void LyraTheme::drawPopup(GfxRenderer& renderer, const char* message) { - const int textWidth = renderer.getTextWidth(UI_12_FONT_ID, message, EpdFontFamily::BOLD); + const int textWidth = renderer.getTextWidth(UI_12_FONT_ID, message, EpdFontFamily::REGULAR); constexpr int margin = 20; const int x = (renderer.getScreenWidth() - textWidth - margin * 2) / 2; constexpr int y = 117; @@ -328,6 +328,6 @@ void LyraTheme::drawPopup(GfxRenderer& renderer, const char* message) { renderer.fillRect(x - 5, y - 5, w + 10, h + 10, false); renderer.drawRect(x + 5, y + 5, w - 10, h - 10, true); - renderer.drawText(UI_12_FONT_ID, x + margin, y + margin, message, true, EpdFontFamily::BOLD); + renderer.drawText(UI_12_FONT_ID, x + margin, y + margin, message, true, EpdFontFamily::REGULAR); renderer.displayBuffer(); } \ No newline at end of file