Address review comments
This commit is contained in:
@@ -86,7 +86,17 @@ ResponseBuffer g_sessionResponseBuf;
|
|||||||
void clearResponseBuffer(ResponseBuffer* buf) {
|
void clearResponseBuffer(ResponseBuffer* buf) {
|
||||||
if (!buf) return;
|
if (!buf) return;
|
||||||
if (buf->data) {
|
if (buf->data) {
|
||||||
buf->len = 0;
|
free(buf->data);
|
||||||
|
buf->data = nullptr;
|
||||||
|
}
|
||||||
|
buf->len = 0;
|
||||||
|
buf->capacity = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void resetResponseBuffer(ResponseBuffer* buf) {
|
||||||
|
if (!buf) return;
|
||||||
|
buf->len = 0;
|
||||||
|
if (buf->data) {
|
||||||
buf->data[0] = '\0';
|
buf->data[0] = '\0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -272,7 +282,7 @@ KOReaderSyncClient::Error KOReaderSyncClient::registerUser() {
|
|||||||
|
|
||||||
ResponseBuffer buf;
|
ResponseBuffer buf;
|
||||||
ResponseBuffer* activeBuf = effectiveResponseBuffer(&buf);
|
ResponseBuffer* activeBuf = effectiveResponseBuffer(&buf);
|
||||||
clearResponseBuffer(activeBuf);
|
resetResponseBuffer(activeBuf);
|
||||||
esp_http_client_handle_t client = createClient(url.c_str(), &buf, HTTP_METHOD_POST);
|
esp_http_client_handle_t client = createClient(url.c_str(), &buf, HTTP_METHOD_POST);
|
||||||
if (!client) {
|
if (!client) {
|
||||||
lastEspError = ESP_ERR_NO_MEM;
|
lastEspError = ESP_ERR_NO_MEM;
|
||||||
@@ -334,7 +344,7 @@ KOReaderSyncClient::Error KOReaderSyncClient::authenticate() {
|
|||||||
|
|
||||||
ResponseBuffer buf;
|
ResponseBuffer buf;
|
||||||
ResponseBuffer* activeBuf = effectiveResponseBuffer(&buf);
|
ResponseBuffer* activeBuf = effectiveResponseBuffer(&buf);
|
||||||
clearResponseBuffer(activeBuf);
|
resetResponseBuffer(activeBuf);
|
||||||
esp_http_client_handle_t client = createClient(url.c_str(), &buf);
|
esp_http_client_handle_t client = createClient(url.c_str(), &buf);
|
||||||
if (!client) {
|
if (!client) {
|
||||||
lastEspError = ESP_ERR_NO_MEM;
|
lastEspError = ESP_ERR_NO_MEM;
|
||||||
@@ -385,7 +395,7 @@ KOReaderSyncClient::Error KOReaderSyncClient::getProgress(const std::string& doc
|
|||||||
return NETWORK_ERROR;
|
return NETWORK_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
clearResponseBuffer(activeBuf);
|
resetResponseBuffer(activeBuf);
|
||||||
|
|
||||||
esp_http_client_handle_t client = createClient(url.c_str(), &buf);
|
esp_http_client_handle_t client = createClient(url.c_str(), &buf);
|
||||||
if (!client) {
|
if (!client) {
|
||||||
@@ -487,7 +497,7 @@ KOReaderSyncClient::Error KOReaderSyncClient::updateProgress(const KOReaderProgr
|
|||||||
return NETWORK_ERROR;
|
return NETWORK_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
clearResponseBuffer(activeBuf);
|
resetResponseBuffer(activeBuf);
|
||||||
|
|
||||||
esp_http_client_handle_t client = createClient(url.c_str(), &buf, HTTP_METHOD_PUT);
|
esp_http_client_handle_t client = createClient(url.c_str(), &buf, HTTP_METHOD_PUT);
|
||||||
if (!client) {
|
if (!client) {
|
||||||
|
|||||||
@@ -127,7 +127,15 @@ void KOReaderSyncActivity::performSync() {
|
|||||||
statusMessage = tr(STR_MAPPING_LOCAL);
|
statusMessage = tr(STR_MAPPING_LOCAL);
|
||||||
}
|
}
|
||||||
requestUpdateAndWait();
|
requestUpdateAndWait();
|
||||||
computeLocalProgressAndChapter();
|
if (!computeLocalProgressAndChapter()) {
|
||||||
|
{
|
||||||
|
RenderLock lock(*this);
|
||||||
|
state = SYNC_FAILED;
|
||||||
|
statusMessage = tr(STR_SYNC_FAILED_MSG);
|
||||||
|
}
|
||||||
|
requestUpdate(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Drop EPUB state before HTTPS to maximize contiguous heap for TLS.
|
// Drop EPUB state before HTTPS to maximize contiguous heap for TLS.
|
||||||
@@ -221,19 +229,14 @@ void KOReaderSyncActivity::performSync() {
|
|||||||
// Defer remote EPUB mapping until user chooses Apply. Upload only needs the
|
// Defer remote EPUB mapping until user chooses Apply. Upload only needs the
|
||||||
// precomputed local XPath, so this avoids post-fetch inflate churn and keeps
|
// precomputed local XPath, so this avoids post-fetch inflate churn and keeps
|
||||||
// the GET session reusable for PUT.
|
// the GET session reusable for PUT.
|
||||||
hasRemoteProgress = true;
|
hasRemoteProgress = false;
|
||||||
remotePositionMapped = false;
|
remotePositionMapped = false;
|
||||||
remotePosition.spineIndex = currentSpineIndex;
|
remotePosition.spineIndex = -1;
|
||||||
remotePosition.pageNumber = 0;
|
remotePosition.pageNumber = -1;
|
||||||
remotePosition.totalPages = 0;
|
remotePosition.totalPages = 0;
|
||||||
remotePosition.paragraphIndex = 0;
|
remotePosition.paragraphIndex = 0;
|
||||||
remotePosition.hasParagraphIndex = false;
|
remotePosition.hasParagraphIndex = false;
|
||||||
int xpathSpineIndex = -1;
|
remoteChapterLabel.clear();
|
||||||
if (ChapterXPathIndexer::tryExtractSpineIndexFromXPath(remoteProgress.progress, xpathSpineIndex) &&
|
|
||||||
xpathSpineIndex >= 0) {
|
|
||||||
remotePosition.spineIndex = xpathSpineIndex;
|
|
||||||
}
|
|
||||||
remoteChapterLabel = tr(STR_UNNAMED);
|
|
||||||
|
|
||||||
if (syncIntent == SyncIntent::PULL_REMOTE) {
|
if (syncIntent == SyncIntent::PULL_REMOTE) {
|
||||||
// Pull intent applies immediately and exits. We bypass chooser UI to keep
|
// Pull intent applies immediately and exits. We bypass chooser UI to keep
|
||||||
@@ -291,7 +294,15 @@ void KOReaderSyncActivity::performUpload() {
|
|||||||
// If sync reached this screen without cached local progress, compute it now.
|
// If sync reached this screen without cached local progress, compute it now.
|
||||||
// This keeps upload robust when UI flow changes or retries happen.
|
// This keeps upload robust when UI flow changes or retries happen.
|
||||||
if (localProgress.xpath.empty()) {
|
if (localProgress.xpath.empty()) {
|
||||||
computeLocalProgressAndChapter();
|
if (!computeLocalProgressAndChapter()) {
|
||||||
|
{
|
||||||
|
RenderLock lock(*this);
|
||||||
|
state = SYNC_FAILED;
|
||||||
|
statusMessage = tr(STR_SYNC_FAILED_MSG);
|
||||||
|
}
|
||||||
|
requestUpdate(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
releaseEpubForMapping();
|
releaseEpubForMapping();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -431,13 +442,15 @@ void KOReaderSyncActivity::render(RenderLock&&) {
|
|||||||
|
|
||||||
// Remote progress - chapter and page
|
// Remote progress - chapter and page
|
||||||
renderer.drawText(UI_10_FONT_ID, contentRect.x + 20, 160, tr(STR_REMOTE_LABEL), true);
|
renderer.drawText(UI_10_FONT_ID, contentRect.x + 20, 160, tr(STR_REMOTE_LABEL), true);
|
||||||
char remoteChapterStr[128];
|
if (hasRemoteProgress) {
|
||||||
snprintf(remoteChapterStr, sizeof(remoteChapterStr), " %s", remoteChapter.c_str());
|
char remoteChapterStr[128];
|
||||||
renderer.drawText(UI_10_FONT_ID, contentRect.x + 20, 185, remoteChapterStr);
|
snprintf(remoteChapterStr, sizeof(remoteChapterStr), " %s", remoteChapter.c_str());
|
||||||
char remotePageStr[64];
|
renderer.drawText(UI_10_FONT_ID, contentRect.x + 20, 185, remoteChapterStr);
|
||||||
snprintf(remotePageStr, sizeof(remotePageStr), tr(STR_PAGE_OVERALL_FORMAT), remotePosition.pageNumber + 1,
|
char remotePageStr[64];
|
||||||
remoteProgress.percentage * 100);
|
snprintf(remotePageStr, sizeof(remotePageStr), tr(STR_PAGE_OVERALL_FORMAT), remotePosition.pageNumber + 1,
|
||||||
renderer.drawText(UI_10_FONT_ID, contentRect.x + 20, 210, remotePageStr);
|
remoteProgress.percentage * 100);
|
||||||
|
renderer.drawText(UI_10_FONT_ID, contentRect.x + 20, 210, remotePageStr);
|
||||||
|
}
|
||||||
|
|
||||||
if (!remoteProgress.device.empty()) {
|
if (!remoteProgress.device.empty()) {
|
||||||
char deviceStr[64];
|
char deviceStr[64];
|
||||||
@@ -556,15 +569,18 @@ bool KOReaderSyncActivity::ensureRemotePositionMapped() {
|
|||||||
remotePosition = ProgressMapper::toCrossPoint(epub, koPos, currentSpineIndex, totalPagesInSpine);
|
remotePosition = ProgressMapper::toCrossPoint(epub, koPos, currentSpineIndex, totalPagesInSpine);
|
||||||
computeRemoteChapter();
|
computeRemoteChapter();
|
||||||
releaseEpubForMapping();
|
releaseEpubForMapping();
|
||||||
|
hasRemoteProgress = true;
|
||||||
remotePositionMapped = true;
|
remotePositionMapped = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KOReaderSyncActivity::releaseEpubForMapping() { epub.reset(); }
|
void KOReaderSyncActivity::releaseEpubForMapping() { epub.reset(); }
|
||||||
|
|
||||||
void KOReaderSyncActivity::computeLocalProgressAndChapter() {
|
bool KOReaderSyncActivity::computeLocalProgressAndChapter() {
|
||||||
if (!ensureEpubLoadedForMapping()) {
|
if (!ensureEpubLoadedForMapping()) {
|
||||||
return;
|
localProgress = KOReaderPosition{};
|
||||||
|
localChapterLabel.clear();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CrossPointPosition localPos = {currentSpineIndex, currentPage, totalPagesInSpine, localParagraphIndex,
|
CrossPointPosition localPos = {currentSpineIndex, currentPage, totalPagesInSpine, localParagraphIndex,
|
||||||
@@ -575,6 +591,7 @@ void KOReaderSyncActivity::computeLocalProgressAndChapter() {
|
|||||||
localChapterLabel = (localTocIndex >= 0)
|
localChapterLabel = (localTocIndex >= 0)
|
||||||
? epub->getTocItem(localTocIndex).title
|
? epub->getTocItem(localTocIndex).title
|
||||||
: (std::string(tr(STR_SECTION_PREFIX)) + std::to_string(currentSpineIndex + 1));
|
: (std::string(tr(STR_SECTION_PREFIX)) + std::to_string(currentSpineIndex + 1));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KOReaderSyncActivity::computeRemoteChapter() {
|
void KOReaderSyncActivity::computeRemoteChapter() {
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ class KOReaderSyncActivity final : public Activity {
|
|||||||
void closeCancelled();
|
void closeCancelled();
|
||||||
bool ensureEpubLoadedForMapping();
|
bool ensureEpubLoadedForMapping();
|
||||||
void releaseEpubForMapping();
|
void releaseEpubForMapping();
|
||||||
void computeLocalProgressAndChapter();
|
bool computeLocalProgressAndChapter();
|
||||||
void computeRemoteChapter();
|
void computeRemoteChapter();
|
||||||
bool ensureRemotePositionMapped();
|
bool ensureRemotePositionMapped();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user