fix: ActivityManager tweaks (#1220)

## Summary

**What is the goal of this PR?**

Small tweaks to #1016:
- Only Activity and ActivityManager can access activityResultHandler and
activityResult
- `[[maybe_unused]]` in RenderLock constructor
- Only ActivityManager and RenderLock can access renderingMutex
- Missing renderUpdate after failed wifi selection
- Standardize on activities calling finish instead of
activityManager.popActivity
- Hold RenderLock while mutating state in EpubReaderActivity result
handlers

---

### AI Usage

While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.

Did you use AI tools to help write this code? _**NO**_
This commit is contained in:
Zach Nelson
2026-02-27 15:48:24 -06:00
committed by GitHub
parent 3b4f2a1129
commit 050a3bd1b6
9 changed files with 21 additions and 15 deletions

View File

@@ -13,15 +13,17 @@
#include "RenderLock.h"
class Activity {
friend class ActivityManager;
protected:
std::string name;
GfxRenderer& renderer;
MappedInputManager& mappedInput;
public:
ActivityResultHandler resultHandler;
ActivityResult result;
public:
explicit Activity(std::string name, GfxRenderer& renderer, MappedInputManager& mappedInput)
: name(std::move(name)), renderer(renderer), mappedInput(mappedInput) {}
virtual ~Activity() = default;

View File

@@ -232,7 +232,7 @@ RenderLock::RenderLock() {
isLocked = true;
}
RenderLock::RenderLock(Activity& /* unused */) {
RenderLock::RenderLock([[maybe_unused]] Activity&) {
xSemaphoreTake(activityManager.renderingMutex, portMAX_DELAY);
isLocked = true;
}

View File

@@ -11,7 +11,6 @@
#include "GfxRenderer.h"
#include "MappedInputManager.h"
#include "RenderLock.h"
class Activity; // forward declaration
class RenderLock; // forward declaration
@@ -31,6 +30,8 @@ class RenderLock; // forward declaration
* - onActivityResult is implemented via a callback instead of a separate method, for simplicity
*/
class ActivityManager {
friend class RenderLock;
protected:
GfxRenderer& renderer;
MappedInputManager& mappedInput;
@@ -49,6 +50,10 @@ class ActivityManager {
static void renderTaskTrampoline(void* param);
[[noreturn]] virtual void renderTaskLoop();
// Mutex to protect rendering operations from race conditions
// Must only be used via RenderLock
SemaphoreHandle_t renderingMutex = nullptr;
// Whether to trigger a render after the current loop()
// This variable must only be set by the main loop, to avoid race conditions
bool requestedUpdate = false;
@@ -61,10 +66,6 @@ class ActivityManager {
}
~ActivityManager() { assert(false); /* should never be called */ };
// Mutex to protect rendering operations from race conditions
// Must only be used via RenderLock
SemaphoreHandle_t renderingMutex = nullptr;
void begin();
void loop();

View File

@@ -383,5 +383,6 @@ void OpdsBookBrowserActivity::onWifiSelectionComplete(const bool connected) {
WiFi.mode(WIFI_OFF);
state = BrowserState::ERROR;
errorMessage = tr(STR_WIFI_CONN_FAILED);
requestUpdate();
}
}

View File

@@ -63,7 +63,7 @@ void CalibreConnectActivity::onExit() {
void CalibreConnectActivity::onWifiSelectionComplete(const bool connected) {
if (!connected) {
activityManager.popActivity();
finish();
return;
}
@@ -162,7 +162,7 @@ void CalibreConnectActivity::loop() {
}
if (exitRequested) {
activityManager.popActivity();
finish();
return;
}
}

View File

@@ -320,6 +320,7 @@ void EpubReaderActivity::onReaderMenuConfirm(EpubReaderMenuActivity::MenuAction
std::make_unique<EpubReaderChapterSelectionActivity>(renderer, mappedInput, epub, path, spineIdx),
[this](const ActivityResult& result) {
if (!result.isCancelled && currentSpineIndex != std::get<ChapterResult>(result.data).spineIndex) {
RenderLock lock(*this);
currentSpineIndex = std::get<ChapterResult>(result.data).spineIndex;
nextPageNumber = 0;
section.reset();
@@ -421,6 +422,7 @@ void EpubReaderActivity::onReaderMenuConfirm(EpubReaderMenuActivity::MenuAction
if (!result.isCancelled) {
const auto& sync = std::get<SyncResult>(result.data);
if (currentSpineIndex != sync.spineIndex || (section && section->currentPage != sync.page)) {
RenderLock lock(*this);
currentSpineIndex = sync.spineIndex;
nextPageNumber = sync.page;
section.reset();

View File

@@ -27,7 +27,7 @@ void CalibreSettingsActivity::onExit() { Activity::onExit(); }
void CalibreSettingsActivity::loop() {
if (mappedInput.wasPressed(MappedInputManager::Button::Back)) {
activityManager.popActivity();
finish();
return;
}

View File

@@ -29,7 +29,7 @@ void KOReaderSettingsActivity::onExit() { Activity::onExit(); }
void KOReaderSettingsActivity::loop() {
if (mappedInput.wasPressed(MappedInputManager::Button::Back)) {
activityManager.popActivity();
finish();
return;
}

View File

@@ -13,7 +13,7 @@
void OtaUpdateActivity::onWifiSelectionComplete(const bool success) {
if (!success) {
LOG_ERR("OTA", "WiFi connection failed, exiting");
activityManager.popActivity();
finish();
return;
}
@@ -172,7 +172,7 @@ void OtaUpdateActivity::loop() {
}
if (mappedInput.wasPressed(MappedInputManager::Button::Back)) {
activityManager.popActivity();
finish();
}
return;
@@ -180,14 +180,14 @@ void OtaUpdateActivity::loop() {
if (state == FAILED) {
if (mappedInput.wasPressed(MappedInputManager::Button::Back)) {
activityManager.popActivity();
finish();
}
return;
}
if (state == NO_UPDATE) {
if (mappedInput.wasPressed(MappedInputManager::Button::Back)) {
activityManager.popActivity();
finish();
}
return;
}