From 958508eb6bf53c0b2ec6443a08937dc188948e81 Mon Sep 17 00:00:00 2001 From: Dave Allie Date: Sun, 21 Dec 2025 18:41:52 +1100 Subject: [PATCH] Prevent boot loop if last open epub crashes on load (#87) ## Summary * Unset openEpubPath on boot and set once epub fully loaded ## Additional Context * If an epub was crashing when loading, it was possible to get the device stuck into a loop. There was no way to get back to the home screen as we'd always load you back into old epub * Break this loop by clearing the stored value when we boot, still jumping to the last open epub, but only resetting that value once the epub has been fully loaded --- src/activities/reader/EpubReaderActivity.cpp | 5 +++++ src/activities/reader/ReaderActivity.cpp | 3 --- src/main.cpp | 6 +++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/activities/reader/EpubReaderActivity.cpp b/src/activities/reader/EpubReaderActivity.cpp index 8827e998..9635952e 100644 --- a/src/activities/reader/EpubReaderActivity.cpp +++ b/src/activities/reader/EpubReaderActivity.cpp @@ -6,6 +6,7 @@ #include "Battery.h" #include "CrossPointSettings.h" +#include "CrossPointState.h" #include "EpubReaderChapterSelectionActivity.h" #include "config.h" @@ -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; diff --git a/src/activities/reader/ReaderActivity.cpp b/src/activities/reader/ReaderActivity.cpp index 099d7e2c..93389fe7 100644 --- a/src/activities/reader/ReaderActivity.cpp +++ b/src/activities/reader/ReaderActivity.cpp @@ -2,7 +2,6 @@ #include -#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(); diff --git a/src/main.cpp b/src/main.cpp index 89d2af48..5dfc25ba 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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