Unset openEpubPath on boot and set once epub fully loaded

This commit is contained in:
Dave Allie 2025-12-21 17:17:16 +11:00
parent 2a27c6d068
commit 41e6fa17a5
No known key found for this signature in database
GPG Key ID: F2FDDB3AD8D0276F
3 changed files with 10 additions and 4 deletions

View File

@ -8,6 +8,7 @@
#include "CrossPointSettings.h"
#include "EpubReaderChapterSelectionActivity.h"
#include "config.h"
#include "CrossPointState.h"
namespace {
constexpr int pagesPerRefresh = 15;
@ -44,6 +45,10 @@ void EpubReaderActivity::onEnter() {
f.close();
}
// Save current epub as last opened epub
APP_STATE.openEpubPath = epub->getPath();
APP_STATE.saveToFile();
// Trigger first update
updateRequired = true;

View File

@ -2,7 +2,6 @@
#include <SD.h>
#include "CrossPointState.h"
#include "Epub.h"
#include "EpubReaderActivity.h"
#include "FileSelectionActivity.h"
@ -29,8 +28,6 @@ void ReaderActivity::onSelectEpubFile(const std::string& path) {
auto epub = loadEpub(path);
if (epub) {
APP_STATE.openEpubPath = path;
APP_STATE.saveToFile();
onGoToEpubReader(std::move(epub));
} else {
exitActivity();

View File

@ -194,7 +194,11 @@ void setup() {
if (APP_STATE.openEpubPath.empty()) {
onGoHome();
} else {
onGoToReader(APP_STATE.openEpubPath);
// Clear app state to avoid getting into a boot loop if the epub doesn't load
const auto path = APP_STATE.openEpubPath;
APP_STATE.openEpubPath = "";
APP_STATE.saveToFile();
onGoToReader(path);
}
// Ensure we're not still holding the power button before leaving setup