Merge branch 'feat-indexing-feedback' of https://github.com/jpirnay/crosspoint-reader into mybuild

This commit is contained in:
jpirnay
2026-03-23 12:03:00 +01:00
5 changed files with 31 additions and 10 deletions
@@ -1012,9 +1012,13 @@ bool ChapterHtmlSlimParser::parseAndBuildPages() {
return false;
}
// Get file size to decide whether to show indexing popup.
if (popupFn && file.size() >= MIN_SIZE_FOR_POPUP) {
popupFn();
const size_t totalFileSize = file.size();
size_t bytesRead = 0;
int lastReportedProgress = -1;
// Show initial progress popup for files above threshold.
if (progressFn && totalFileSize >= MIN_SIZE_FOR_POPUP) {
progressFn(0);
}
XML_SetUserData(parser, this);
@@ -1036,6 +1040,16 @@ bool ChapterHtmlSlimParser::parseAndBuildPages() {
}
const size_t len = file.read(buf, PARSE_BUFFER_SIZE);
bytesRead += len;
// Report progress in 5% increments to limit e-ink refreshes.
if (progressFn && totalFileSize >= MIN_SIZE_FOR_POPUP) {
const int progress = static_cast<int>(bytesRead * 100 / totalFileSize);
if (progress / 5 > lastReportedProgress / 5) {
lastReportedProgress = progress;
progressFn(progress);
}
}
if (len == 0 && file.available() > 0) {
LOG_ERR("EHP", "File read error");
@@ -26,7 +26,7 @@ class ChapterHtmlSlimParser {
const std::string& filepath;
GfxRenderer& renderer;
std::function<void(std::unique_ptr<Page>)> completePageFn;
std::function<void()> popupFn; // Popup callback
std::function<void(int)> progressFn; // Progress callback (0-100)
int depth = 0;
int skipUntilDepth = INT_MAX;
int boldUntilDepth = INT_MAX;
@@ -110,7 +110,8 @@ class ChapterHtmlSlimParser {
const std::function<void(std::unique_ptr<Page>)>& completePageFn,
const bool embeddedStyle, const std::string& contentBase,
const std::string& imageBasePath, const uint8_t imageRendering = 0,
const std::function<void()>& popupFn = nullptr, const CssParser* cssParser = nullptr)
const std::function<void(int)>& progressFn = nullptr,
const CssParser* cssParser = nullptr)
: epub(epub),
filepath(filepath),
@@ -123,7 +124,7 @@ class ChapterHtmlSlimParser {
viewportHeight(viewportHeight),
hyphenationEnabled(hyphenationEnabled),
completePageFn(completePageFn),
popupFn(popupFn),
progressFn(progressFn),
cssParser(cssParser),
embeddedStyle(embeddedStyle),
imageRendering(imageRendering),