Compare commits

...

2 Commits

Author SHA1 Message Date
CaptainFrito
c6640aa645 Fixed crashes in Home and book selection 2026-01-26 14:15:25 +07:00
CaptainFrito
10f8ff8b22 Generate empty thumbnail for books without a cover 2026-01-26 10:42:19 +07:00
5 changed files with 17 additions and 51 deletions

View File

@ -435,11 +435,8 @@ bool Epub::generateThumbBmp(int height) const {
const auto coverImageHref = bookMetadataCache->coreMetadata.coverItemHref;
if (coverImageHref.empty()) {
Serial.printf("[%lu] [EBP] No known cover image for thumbnail\n", millis());
return false;
}
if (coverImageHref.substr(coverImageHref.length() - 4) == ".jpg" ||
coverImageHref.substr(coverImageHref.length() - 5) == ".jpeg") {
} else if (coverImageHref.substr(coverImageHref.length() - 4) == ".jpg" ||
coverImageHref.substr(coverImageHref.length() - 5) == ".jpeg") {
Serial.printf("[%lu] [EBP] Generating thumb BMP from JPG cover image\n", millis());
const auto coverJpgTempPath = getCachePath() + "/.cover.jpg";
@ -480,6 +477,10 @@ bool Epub::generateThumbBmp(int height) const {
Serial.printf("[%lu] [EBP] Cover image is not a JPG, skipping thumbnail\n", millis());
}
// Write an empty bmp file to avoid generation attempts in the future
FsFile thumbBmp;
SdMan.openFileForWrite("EBP", getThumbBmpPath(height), thumbBmp);
thumbBmp.close();
return false;
}

View File

@ -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

View File

@ -157,6 +157,7 @@ void MyLibraryActivity::loop() {
if (currentTab == Tab::Recent) {
if (!bookPaths.empty() && selectorIndex < static_cast<int>(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<int>(bookTitles.size()) : static_cast<int>(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;
}

View File

@ -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(),

View File

@ -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();
}