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.

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**_

authored by

Zach Nelson and committed by
GitHub
050a3bd1 3b4f2a11

+21 -15
+3 -1
src/activities/Activity.h
··· 13 13 #include "RenderLock.h" 14 14 15 15 class Activity { 16 + friend class ActivityManager; 17 + 16 18 protected: 17 19 std::string name; 18 20 GfxRenderer& renderer; 19 21 MappedInputManager& mappedInput; 20 22 21 - public: 22 23 ActivityResultHandler resultHandler; 23 24 ActivityResult result; 24 25 26 + public: 25 27 explicit Activity(std::string name, GfxRenderer& renderer, MappedInputManager& mappedInput) 26 28 : name(std::move(name)), renderer(renderer), mappedInput(mappedInput) {} 27 29 virtual ~Activity() = default;
+1 -1
src/activities/ActivityManager.cpp
··· 232 232 isLocked = true; 233 233 } 234 234 235 - RenderLock::RenderLock(Activity& /* unused */) { 235 + RenderLock::RenderLock([[maybe_unused]] Activity&) { 236 236 xSemaphoreTake(activityManager.renderingMutex, portMAX_DELAY); 237 237 isLocked = true; 238 238 }
+6 -5
src/activities/ActivityManager.h
··· 11 11 12 12 #include "GfxRenderer.h" 13 13 #include "MappedInputManager.h" 14 - #include "RenderLock.h" 15 14 16 15 class Activity; // forward declaration 17 16 class RenderLock; // forward declaration ··· 31 30 * - onActivityResult is implemented via a callback instead of a separate method, for simplicity 32 31 */ 33 32 class ActivityManager { 33 + friend class RenderLock; 34 + 34 35 protected: 35 36 GfxRenderer& renderer; 36 37 MappedInputManager& mappedInput; ··· 49 50 static void renderTaskTrampoline(void* param); 50 51 [[noreturn]] virtual void renderTaskLoop(); 51 52 53 + // Mutex to protect rendering operations from race conditions 54 + // Must only be used via RenderLock 55 + SemaphoreHandle_t renderingMutex = nullptr; 56 + 52 57 // Whether to trigger a render after the current loop() 53 58 // This variable must only be set by the main loop, to avoid race conditions 54 59 bool requestedUpdate = false; ··· 60 65 stackActivities.reserve(10); 61 66 } 62 67 ~ActivityManager() { assert(false); /* should never be called */ }; 63 - 64 - // Mutex to protect rendering operations from race conditions 65 - // Must only be used via RenderLock 66 - SemaphoreHandle_t renderingMutex = nullptr; 67 68 68 69 void begin(); 69 70 void loop();
+1
src/activities/browser/OpdsBookBrowserActivity.cpp
··· 383 383 WiFi.mode(WIFI_OFF); 384 384 state = BrowserState::ERROR; 385 385 errorMessage = tr(STR_WIFI_CONN_FAILED); 386 + requestUpdate(); 386 387 } 387 388 }
+2 -2
src/activities/network/CalibreConnectActivity.cpp
··· 63 63 64 64 void CalibreConnectActivity::onWifiSelectionComplete(const bool connected) { 65 65 if (!connected) { 66 - activityManager.popActivity(); 66 + finish(); 67 67 return; 68 68 } 69 69 ··· 162 162 } 163 163 164 164 if (exitRequested) { 165 - activityManager.popActivity(); 165 + finish(); 166 166 return; 167 167 } 168 168 }
+2
src/activities/reader/EpubReaderActivity.cpp
··· 320 320 std::make_unique<EpubReaderChapterSelectionActivity>(renderer, mappedInput, epub, path, spineIdx), 321 321 [this](const ActivityResult& result) { 322 322 if (!result.isCancelled && currentSpineIndex != std::get<ChapterResult>(result.data).spineIndex) { 323 + RenderLock lock(*this); 323 324 currentSpineIndex = std::get<ChapterResult>(result.data).spineIndex; 324 325 nextPageNumber = 0; 325 326 section.reset(); ··· 421 422 if (!result.isCancelled) { 422 423 const auto& sync = std::get<SyncResult>(result.data); 423 424 if (currentSpineIndex != sync.spineIndex || (section && section->currentPage != sync.page)) { 425 + RenderLock lock(*this); 424 426 currentSpineIndex = sync.spineIndex; 425 427 nextPageNumber = sync.page; 426 428 section.reset();
+1 -1
src/activities/settings/CalibreSettingsActivity.cpp
··· 27 27 28 28 void CalibreSettingsActivity::loop() { 29 29 if (mappedInput.wasPressed(MappedInputManager::Button::Back)) { 30 - activityManager.popActivity(); 30 + finish(); 31 31 return; 32 32 } 33 33
+1 -1
src/activities/settings/KOReaderSettingsActivity.cpp
··· 29 29 30 30 void KOReaderSettingsActivity::loop() { 31 31 if (mappedInput.wasPressed(MappedInputManager::Button::Back)) { 32 - activityManager.popActivity(); 32 + finish(); 33 33 return; 34 34 } 35 35
+4 -4
src/activities/settings/OtaUpdateActivity.cpp
··· 13 13 void OtaUpdateActivity::onWifiSelectionComplete(const bool success) { 14 14 if (!success) { 15 15 LOG_ERR("OTA", "WiFi connection failed, exiting"); 16 - activityManager.popActivity(); 16 + finish(); 17 17 return; 18 18 } 19 19 ··· 172 172 } 173 173 174 174 if (mappedInput.wasPressed(MappedInputManager::Button::Back)) { 175 - activityManager.popActivity(); 175 + finish(); 176 176 } 177 177 178 178 return; ··· 180 180 181 181 if (state == FAILED) { 182 182 if (mappedInput.wasPressed(MappedInputManager::Button::Back)) { 183 - activityManager.popActivity(); 183 + finish(); 184 184 } 185 185 return; 186 186 } 187 187 188 188 if (state == NO_UPDATE) { 189 189 if (mappedInput.wasPressed(MappedInputManager::Button::Back)) { 190 - activityManager.popActivity(); 190 + finish(); 191 191 } 192 192 return; 193 193 }