Fixed crashes in Home and book selection

This commit is contained in:
CaptainFrito 2026-01-26 14:15:25 +07:00
parent 10f8ff8b22
commit c6640aa645
4 changed files with 11 additions and 46 deletions

View File

@ -149,7 +149,7 @@ void HomeActivity::onEnter() {
updateRequired = true; updateRequired = true;
xTaskCreate(&HomeActivity::taskTrampoline, "HomeActivityTask", xTaskCreate(&HomeActivity::taskTrampoline, "HomeActivityTask",
4096, // Stack size (increased for cover image rendering) 8192, // Stack size
this, // Parameters this, // Parameters
1, // Priority 1, // Priority
&displayTaskHandle // Task handle &displayTaskHandle // Task handle

View File

@ -157,6 +157,7 @@ void MyLibraryActivity::loop() {
if (currentTab == Tab::Recent) { if (currentTab == Tab::Recent) {
if (!bookPaths.empty() && selectorIndex < static_cast<int>(bookPaths.size())) { if (!bookPaths.empty() && selectorIndex < static_cast<int>(bookPaths.size())) {
onSelectBook(bookPaths[selectorIndex], currentTab); onSelectBook(bookPaths[selectorIndex], currentTab);
return;
} }
} else { } else {
if (files.empty()) { if (files.empty()) {
@ -171,6 +172,7 @@ void MyLibraryActivity::loop() {
updateRequired = true; updateRequired = true;
} else { } else {
onSelectBook(basepath + files[selectorIndex], currentTab); onSelectBook(basepath + files[selectorIndex], currentTab);
return;
} }
} }
} }
@ -207,18 +209,20 @@ void MyLibraryActivity::loop() {
updateRequired = true; updateRequired = true;
return; return;
} }
int listSize = (currentTab == Tab::Recent) ? static_cast<int>(bookTitles.size()) : static_cast<int>(files.size());
if (upReleased) { if (upReleased) {
if (skipPage) { if (skipPage) {
selectorIndex = ((selectorIndex / pageItems - 1) * pageItems + files.size()) % files.size(); selectorIndex = ((selectorIndex / pageItems - 1) * pageItems + listSize) % listSize;
} else { } else {
selectorIndex = (selectorIndex + files.size() - 1) % files.size(); selectorIndex = (selectorIndex + listSize - 1) % listSize;
} }
updateRequired = true; updateRequired = true;
} else if (downReleased) { } else if (downReleased) {
if (skipPage) { if (skipPage) {
selectorIndex = ((selectorIndex / pageItems + 1) * pageItems) % files.size(); selectorIndex = ((selectorIndex / pageItems + 1) * pageItems) % listSize;
} else { } else {
selectorIndex = (selectorIndex + 1) % files.size(); selectorIndex = (selectorIndex + 1) % listSize;
} }
updateRequired = true; updateRequired = true;
} }

View File

@ -285,45 +285,6 @@ void EpubReaderActivity::renderScreen() {
viewportHeight, SETTINGS.hyphenationEnabled)) { viewportHeight, SETTINGS.hyphenationEnabled)) {
Serial.printf("[%lu] [ERS] Cache not found, building...\n", millis()); 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..."); auto popupCallbacks = UITheme::drawPopupWithProgress(renderer, "Indexing...");
if (!section->createSectionFile(SETTINGS.getReaderFontId(), SETTINGS.getReaderLineCompression(), if (!section->createSectionFile(SETTINGS.getReaderFontId(), SETTINGS.getReaderLineCompression(),

View File

@ -319,7 +319,7 @@ void LyraTheme::drawButtonMenu(GfxRenderer& renderer, Rect rect, int buttonCount
} }
void LyraTheme::drawPopup(GfxRenderer& renderer, const char* message) { 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; constexpr int margin = 20;
const int x = (renderer.getScreenWidth() - textWidth - margin * 2) / 2; const int x = (renderer.getScreenWidth() - textWidth - margin * 2) / 2;
constexpr int y = 117; 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.fillRect(x - 5, y - 5, w + 10, h + 10, false);
renderer.drawRect(x + 5, y + 5, w - 10, h - 10, true); 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(); renderer.displayBuffer();
} }