Ensure new custom sleep image every time (#300)
When picking a random sleep image from a set of custom images, compare the randomly chosen index against a cached value in settings. If the value matches, use the next image (rolling over if it's the last image). Cache the chosen image index to settings in either case. ## Summary Implements a tweak on the custom sleep image feature that ensures that the user gets a new image every time the device goes to sleep. This change adds a new setting (perhaps there's a better place to cache this?) that stores the most recently used file index. During picking the random image index, we compare this against the random index and choose the next one (modulo the number of image files) if it matches, ensuring we get a new image. ## Additional Context As mentioned, I used settings to cache this value since it is a persisted store, perhaps that's overkill. Open to suggestions on if there's a better way.
This commit is contained in:
@@ -303,6 +303,7 @@ void setup() {
|
||||
// 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.lastSleepImage = 0;
|
||||
APP_STATE.saveToFile();
|
||||
onGoToReader(path);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user