mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-04 14:47:37 +03:00
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.
24 lines
456 B
C++
24 lines
456 B
C++
#pragma once
|
|
#include <iosfwd>
|
|
#include <string>
|
|
|
|
class CrossPointState {
|
|
// Static instance
|
|
static CrossPointState instance;
|
|
|
|
public:
|
|
std::string openEpubPath;
|
|
uint8_t lastSleepImage;
|
|
~CrossPointState() = default;
|
|
|
|
// Get singleton instance
|
|
static CrossPointState& getInstance() { return instance; }
|
|
|
|
bool saveToFile() const;
|
|
|
|
bool loadFromFile();
|
|
};
|
|
|
|
// Helper macro to access settings
|
|
#define APP_STATE CrossPointState::getInstance()
|