You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(reader): never lose reading time — deep-sleep commit + incremental save + drop 10s floor
Ports the applicable subset of dawsonfi/aalu's (MIT) reading-stats
correctness fixes into our architecture. Three bugs in the stock
session-tracking path:
1. Deep-sleep didn't commit the reader's session. enterDeepSleep
called activityManager.goToSleep() which deferred the replace
(and therefore the reader's onExit) until the next loop tick —
but the hardware deep-sleep entry ran immediately after, so the
transition never fired. Every minute spent reading since the
last onExit was lost on each power-off.
2. A brown-out, hard hang, or sudden battery cut also lost the
whole session. stats.bin was only written at onExit, never
during reading.
3. Sessions under 10 seconds discarded reading time entirely
(floor-gated at 10s for totalReadingSeconds). Users who do many
short reads accumulated nothing.
Fixes:
- New Activity::onBeforeDeepSleep() virtual + ActivityManager::
notifyBeforeDeepSleep() that fans out to current + stacked. Wired
into main.cpp::enterDeepSleep BEFORE the hardware sleep call so
the reader commits its session before powering off.
- EpubReaderActivity::commitReadingSession() — idempotent helper
that banks elapsed time from the current segment (segment anchor
resets after commit so successive commits don't double-count).
Replaces the inline onExit() calculation and is shared with
onBeforeDeepSleep + the incremental-save tick.
- 60s incremental save in EpubReaderActivity::loop() — every minute
of reading, commitReadingSession flushes to stats.bin. Worst-case
loss on hard crash drops from "entire session" to "<=1 minute".
- Drop the 10s floor on totalReadingSeconds. All elapsed seconds
add to lifetime totals; sessionCount still uses the 60s floor
(only bumped once per open, even across multiple commits).
- Live in-reader stats popup now adds `millis() - sessionSegmentStartMs`
on top of saved stats instead of `millis() - sessionStartMs`.
With incremental saves, the previously-banked time is already in
stats — using sessionStartMs would double-count.
aalu's fixes#2 (don't walk progressPercent backwards) and #4
(beginSession doesn't overwrite progress) don't apply: our
architecture stores progress in a separate progress.bin file rather
than a progressPercent field in stats, and onEnter doesn't write
progress. Fix#5 (100%/99% off-by-one) doesn't appear to apply
either — our Epub::calculateProgress already does byte-weighted
cumulative-size math and reaches 1.0 at last-page/last-spine.
0 commit comments