fix(epub): add retry logic for SD card streaming

Add 3 retry attempts with 50ms delay for ZIP to SD card streaming
to handle timing issues after display refresh.
This commit is contained in:
Eunchurn Park 2025-12-25 19:43:56 +09:00
parent 504c7b307d
commit 8c726549bf
No known key found for this signature in database
GPG Key ID: 29D94D9C697E3F92

View File

@ -118,15 +118,25 @@ bool Section::persistPageDataToSD(const int fontId, const float lineCompression,
const bool extraParagraphSpacing) {
const auto localPath = epub->getSpineItem(spineIndex).href;
const auto tmpHtmlPath = epub->getCachePath() + "/.tmp_" + std::to_string(spineIndex) + ".html";
// Retry logic for SD card timing issues
bool success = false;
for (int attempt = 0; attempt < 3 && !success; attempt++) {
if (attempt > 0) {
Serial.printf("[%lu] [SCT] Retrying stream (attempt %d)...\n", millis(), attempt + 1);
delay(50); // Brief delay before retry
}
File tmpHtml;
if (!FsHelpers::openFileForWrite("SCT", tmpHtmlPath, tmpHtml)) {
return false;
continue;
}
bool success = epub->readItemContentsToStream(localPath, tmpHtml, 1024);
success = epub->readItemContentsToStream(localPath, tmpHtml, 1024);
tmpHtml.close();
}
if (!success) {
Serial.printf("[%lu] [SCT] Failed to stream item contents to temp file\n", millis());
Serial.printf("[%lu] [SCT] Failed to stream item contents to temp file after retries\n", millis());
return false;
}