A fork of https://github.com/crosspoint-reader/crosspoint-reader
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: wakeup target detection (#731)

## Summary

* If going to sleep was from the Reader view, wake up to the same book.
Otherwise, wakeup to the Home view

authored by

Arthur Tazhitdinov and committed by
GitHub
1caad578 5b90b68e

+17 -4
+8 -1
src/CrossPointState.cpp
··· 5 5 #include <Serialization.h> 6 6 7 7 namespace { 8 - constexpr uint8_t STATE_FILE_VERSION = 3; 8 + constexpr uint8_t STATE_FILE_VERSION = 4; 9 9 constexpr char STATE_FILE[] = "/.crosspoint/state.bin"; 10 10 } // namespace 11 11 ··· 21 21 serialization::writeString(outputFile, openEpubPath); 22 22 serialization::writePod(outputFile, lastSleepImage); 23 23 serialization::writePod(outputFile, readerActivityLoadCount); 24 + serialization::writePod(outputFile, lastSleepFromReader); 24 25 outputFile.close(); 25 26 return true; 26 27 } ··· 48 49 49 50 if (version >= 3) { 50 51 serialization::readPod(inputFile, readerActivityLoadCount); 52 + } 53 + 54 + if (version >= 4) { 55 + serialization::readPod(inputFile, lastSleepFromReader); 56 + } else { 57 + lastSleepFromReader = false; 51 58 } 52 59 53 60 inputFile.close();
+1
src/CrossPointState.h
··· 10 10 std::string openEpubPath; 11 11 uint8_t lastSleepImage; 12 12 uint8_t readerActivityLoadCount = 0; 13 + bool lastSleepFromReader = false; 13 14 ~CrossPointState() = default; 14 15 15 16 // Get singleton instance
+1
src/activities/Activity.h
··· 23 23 virtual void loop() {} 24 24 virtual bool skipLoopDelay() { return false; } 25 25 virtual bool preventAutoSleep() { return false; } 26 + virtual bool isReaderActivity() const { return false; } 26 27 };
+1
src/activities/reader/ReaderActivity.h
··· 34 34 onGoBack(onGoBack), 35 35 onGoToLibrary(onGoToLibrary) {} 36 36 void onEnter() override; 37 + bool isReaderActivity() const override { return true; } 37 38 };
+6 -3
src/main.cpp
··· 194 194 195 195 // Enter deep sleep mode 196 196 void enterDeepSleep() { 197 + APP_STATE.lastSleepFromReader = currentActivity && currentActivity->isReaderActivity(); 198 + APP_STATE.saveToFile(); 197 199 exitActivity(); 198 200 enterNewActivity(new SleepActivity(renderer, mappedInputManager)); 199 201 ··· 331 333 APP_STATE.loadFromFile(); 332 334 RECENT_BOOKS.loadFromFile(); 333 335 334 - // Boot to home screen directly when back button is held or when reader activity crashes 3 times 335 - if (APP_STATE.openEpubPath.empty() || mappedInputManager.isPressed(MappedInputManager::Button::Back) || 336 - APP_STATE.readerActivityLoadCount > 0) { 336 + // Boot to home screen if no book is open, last sleep was not from reader, back button is held, or reader activity 337 + // crashed (indicated by readerActivityLoadCount > 0) 338 + if (APP_STATE.openEpubPath.empty() || !APP_STATE.lastSleepFromReader || 339 + mappedInputManager.isPressed(MappedInputManager::Button::Back) || APP_STATE.readerActivityLoadCount > 0) { 337 340 onGoHome(); 338 341 } else { 339 342 // Clear app state to avoid getting into a boot loop if the epub doesn't load