mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-04 14:47:37 +03:00
feat: add automatic bootloop recovery
This commit is contained in:
parent
74f2552c29
commit
7f9b5787c1
@ -5,7 +5,7 @@
|
|||||||
#include <Serialization.h>
|
#include <Serialization.h>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
constexpr uint8_t STATE_FILE_VERSION = 2;
|
constexpr uint8_t STATE_FILE_VERSION = 3;
|
||||||
constexpr char STATE_FILE[] = "/.crosspoint/state.bin";
|
constexpr char STATE_FILE[] = "/.crosspoint/state.bin";
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
@ -20,6 +20,7 @@ bool CrossPointState::saveToFile() const {
|
|||||||
serialization::writePod(outputFile, STATE_FILE_VERSION);
|
serialization::writePod(outputFile, STATE_FILE_VERSION);
|
||||||
serialization::writeString(outputFile, openEpubPath);
|
serialization::writeString(outputFile, openEpubPath);
|
||||||
serialization::writePod(outputFile, lastSleepImage);
|
serialization::writePod(outputFile, lastSleepImage);
|
||||||
|
serialization::writePod(outputFile, readerActivityLoadCount);
|
||||||
outputFile.close();
|
outputFile.close();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -45,6 +46,10 @@ bool CrossPointState::loadFromFile() {
|
|||||||
lastSleepImage = 0;
|
lastSleepImage = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (version >= 3) {
|
||||||
|
serialization::readPod(inputFile, readerActivityLoadCount);
|
||||||
|
}
|
||||||
|
|
||||||
inputFile.close();
|
inputFile.close();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,6 +9,7 @@ class CrossPointState {
|
|||||||
public:
|
public:
|
||||||
std::string openEpubPath;
|
std::string openEpubPath;
|
||||||
uint8_t lastSleepImage;
|
uint8_t lastSleepImage;
|
||||||
|
uint8_t readerActivityLoadCount = 0;
|
||||||
~CrossPointState() = default;
|
~CrossPointState() = default;
|
||||||
|
|
||||||
// Get singleton instance
|
// Get singleton instance
|
||||||
|
|||||||
@ -112,6 +112,8 @@ void EpubReaderActivity::onExit() {
|
|||||||
}
|
}
|
||||||
vSemaphoreDelete(renderingMutex);
|
vSemaphoreDelete(renderingMutex);
|
||||||
renderingMutex = nullptr;
|
renderingMutex = nullptr;
|
||||||
|
APP_STATE.readerActivityLoadCount = 0;
|
||||||
|
APP_STATE.saveToFile();
|
||||||
section.reset();
|
section.reset();
|
||||||
epub.reset();
|
epub.reset();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -89,6 +89,8 @@ void TxtReaderActivity::onExit() {
|
|||||||
renderingMutex = nullptr;
|
renderingMutex = nullptr;
|
||||||
pageOffsets.clear();
|
pageOffsets.clear();
|
||||||
currentPageLines.clear();
|
currentPageLines.clear();
|
||||||
|
APP_STATE.readerActivityLoadCount = 0;
|
||||||
|
APP_STATE.saveToFile();
|
||||||
txt.reset();
|
txt.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -69,6 +69,8 @@ void XtcReaderActivity::onExit() {
|
|||||||
}
|
}
|
||||||
vSemaphoreDelete(renderingMutex);
|
vSemaphoreDelete(renderingMutex);
|
||||||
renderingMutex = nullptr;
|
renderingMutex = nullptr;
|
||||||
|
APP_STATE.readerActivityLoadCount = 0;
|
||||||
|
APP_STATE.saveToFile();
|
||||||
xtc.reset();
|
xtc.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -311,13 +311,16 @@ void setup() {
|
|||||||
APP_STATE.loadFromFile();
|
APP_STATE.loadFromFile();
|
||||||
RECENT_BOOKS.loadFromFile();
|
RECENT_BOOKS.loadFromFile();
|
||||||
|
|
||||||
if (APP_STATE.openEpubPath.empty() || mappedInputManager.isPressed(MappedInputManager::Button::Back)) {
|
// Boot to home screen directly when back button is held or when reader activity crashes 3 times
|
||||||
|
if (APP_STATE.openEpubPath.empty() || mappedInputManager.isPressed(MappedInputManager::Button::Back) ||
|
||||||
|
APP_STATE.readerActivityLoadCount > 2) {
|
||||||
onGoHome();
|
onGoHome();
|
||||||
} else {
|
} else {
|
||||||
// Clear app state to avoid getting into a boot loop if the epub doesn't load
|
// Clear app state to avoid getting into a boot loop if the epub doesn't load
|
||||||
const auto path = APP_STATE.openEpubPath;
|
const auto path = APP_STATE.openEpubPath;
|
||||||
APP_STATE.openEpubPath = "";
|
APP_STATE.openEpubPath = "";
|
||||||
APP_STATE.lastSleepImage = 0;
|
APP_STATE.lastSleepImage = 0;
|
||||||
|
APP_STATE.readerActivityLoadCount++;
|
||||||
APP_STATE.saveToFile();
|
APP_STATE.saveToFile();
|
||||||
onGoToReader(path, MyLibraryActivity::Tab::Recent);
|
onGoToReader(path, MyLibraryActivity::Tab::Recent);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user