Ensure activitytracker updates get flushed to disk

This commit is contained in:
jpirnay
2026-05-23 09:55:58 +02:00
parent 39228b7631
commit f5dee12646
3 changed files with 8 additions and 3 deletions
+1 -1
View File
@@ -77,7 +77,7 @@ void ReadingSessionTracker::end() {
LOG_DBG("RST", "Session end doc=%s secs=%u pages=%u prog=%u wall=%lld", docId.c_str(), seconds,
pagesTurnedThisSession, lastKnownProgress, (long long)walltime);
if (seconds > 0 && !docId.empty()) {
if (!docId.empty()) {
READING_STATS.recordSession(docId, title, author, seconds, pagesTurnedThisSession, lastKnownProgress,
static_cast<time_t>(walltime));
if (!READING_STATS.saveToFile()) {
+2 -2
View File
@@ -64,8 +64,8 @@ ReadingStatsStore ReadingStatsStore::instance;
void ReadingStatsStore::recordSession(const std::string& docId, const std::string& title, const std::string& author,
uint32_t sessionSeconds, uint32_t sessionPagesTurned, uint8_t progress,
time_t walltimeEpoch) {
if (docId.empty() || sessionSeconds == 0) {
// Nothing to credit. Title-update-only flows go through a different path.
if (docId.empty()) {
// Title-update-only flows go through a different path.
return;
}
+5
View File
@@ -28,6 +28,7 @@
#include "KOReaderCredentialStore.h"
#include "MappedInputManager.h"
#include "OpdsServerStore.h"
#include "ReadingSessionTracker.h"
#include "ReadingStats.h"
#include "RecentBooksStore.h"
#include "SdCardFontSystem.h"
@@ -154,6 +155,9 @@ static bool deepSleepInProgress = false;
void silentRestart() {
if (deepSleepInProgress) return; // sleeping supersedes the heap-defrag reboot
// ESP.restart() bypasses activity onExit(), so flush any in-flight reading
// session manually — otherwise a heap-defrag reboot mid-read loses the session.
globalReadingSessionTracker().end();
silentRebootTarget = SILENT_REBOOT_TARGET_HOME;
silentRebootMagic = SILENT_REBOOT_MAGIC;
LOG_DBG("MAIN", "Silent restart (target=home)");
@@ -163,6 +167,7 @@ void silentRestart() {
void silentRestartToReader() {
if (deepSleepInProgress) return; // sleeping supersedes the heap-defrag reboot
globalReadingSessionTracker().end();
silentRebootTarget = SILENT_REBOOT_TARGET_READER;
silentRebootMagic = SILENT_REBOOT_MAGIC;
LOG_DBG("MAIN", "Silent restart (target=reader)");