Update logic to avoid collision

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
jpirnay
2026-04-26 16:46:22 +02:00
co-authored by Copilot
parent a1d0ddec49
commit f0fe02d77a
34 changed files with 233 additions and 294 deletions
+40 -31
View File
@@ -295,37 +295,6 @@ void EpubReaderActivity::loop() {
return;
}
const bool screenshotChordReleased = gpio.wasReleased(HalGPIO::BTN_POWER) && gpio.wasReleased(HalGPIO::BTN_DOWN);
// Handle short power button press for footnotes
if (SETTINGS.shortPwrBtn == CrossPointSettings::SHORT_PWRBTN::FOOTNOTES &&
mappedInput.wasReleased(MappedInputManager::Button::Power) && !screenshotChordReleased) {
if (currentPageFootnotes.size() == 1) {
navigateToHref(currentPageFootnotes[0].href, true);
} else if (currentPageFootnotes.size() > 1) {
ReaderUtils::enforceExitFullRefresh(renderer);
startActivityForResult(std::make_unique<EpubReaderFootnotesActivity>(renderer, mappedInput, currentPageFootnotes),
[this](const ActivityResult& result) {
if (!result.isCancelled) {
const auto& footnoteResult = std::get<FootnoteResult>(result.data);
navigateToHref(footnoteResult.href, true);
}
requestUpdate();
});
}
return;
}
// Star page toggle via short power button press
if (SETTINGS.shortPwrBtn == CrossPointSettings::SHORT_PWRBTN::STAR_PAGE &&
mappedInput.wasReleased(MappedInputManager::Button::Power)) {
if (section && section->currentPage >= 0 && section->currentPage < section->pageCount) {
bookmarkStore.toggle(static_cast<uint16_t>(currentSpineIndex), static_cast<uint16_t>(section->currentPage));
requestUpdate();
}
return;
}
auto [prevTriggered, nextTriggered] = ReaderUtils::detectPageTurn(mappedInput);
if (!prevTriggered && !nextTriggered) {
return;
@@ -1905,6 +1874,46 @@ void EpubReaderActivity::onButtonAction(const CrossPointSettings::BUTTON_ACTION
requestUpdate();
break;
}
case BA::BTN_EXIT_READER:
ReaderUtils::enforceExitFullRefresh(renderer);
finish();
break;
case BA::BTN_READER_MENU:
if (epub) {
const int currentPage = section ? section->currentPage + 1 : 0;
const int totalPages = section ? section->pageCount : 0;
float bookProgress = 0.0f;
if (epub->getBookSize() > 0 && section && section->pageCount > 0) {
const float chapterProgress =
static_cast<float>(section->currentPage) / static_cast<float>(section->pageCount);
bookProgress = epub->calculateProgress(currentSpineIndex, chapterProgress) * 100.0f;
}
const int bookProgressPercent = clampPercent(static_cast<int>(bookProgress + 0.5f));
const bool isCurrentPageStarred = section && bookmarkStore.has(static_cast<uint16_t>(currentSpineIndex),
static_cast<uint16_t>(section->currentPage));
ReaderUtils::enforceExitFullRefresh(renderer);
startActivityForResult(
std::make_unique<EpubReaderMenuActivity>(
renderer, mappedInput, epub->getTitle(), currentPage, totalPages, bookProgressPercent,
SETTINGS.orientation, !currentPageFootnotes.empty(), bookEmbeddedStyleOverride,
bookImageRenderingOverride, bookFontFamilyOverride, bookFontSizeOverride, SETTINGS.textDarkness,
!bookmarkStore.isEmpty(), isCurrentPageStarred),
[this](const ActivityResult& result) {
const auto& menu = std::get<MenuResult>(result.data);
applyOrientation(menu.orientation);
applyTextDarkness(menu.textDarkness);
toggleAutoPageTurn(menu.pageTurnOption);
applyBookReaderOverrides(menu.embeddedStyleOverride, menu.imageRenderingOverride, menu.fontFamilyOverride,
menu.fontSizeOverride);
if (!result.isCancelled) {
onReaderMenuConfirm(static_cast<EpubReaderMenuActivity::MenuAction>(menu.action));
}
});
}
break;
case BA::BTN_KOREADER_SYNC:
launchKOReaderSync(SyncLaunchMode::COMPARE);
break;
default:
break;
}
@@ -947,6 +947,10 @@ void MdReaderActivity::onButtonAction(const CrossPointSettings::BUTTON_ACTION ac
});
}
break;
case BA::BTN_EXIT_READER:
ReaderUtils::enforceExitFullRefresh(renderer);
finish();
break;
default:
break;
}
+1 -3
View File
@@ -64,9 +64,7 @@ struct PageTurnResult {
inline PageTurnResult detectPageTurn(const MappedInputManager& input) {
const bool prev =
input.wasReleased(MappedInputManager::Button::PageBack) || input.wasReleased(MappedInputManager::Button::Left);
const bool powerTurn = SETTINGS.shortPwrBtn == CrossPointSettings::SHORT_PWRBTN::PAGE_TURN &&
input.wasReleased(MappedInputManager::Button::Power);
const bool next = input.wasReleased(MappedInputManager::Button::PageForward) || powerTurn ||
const bool next = input.wasReleased(MappedInputManager::Button::PageForward) ||
input.wasReleased(MappedInputManager::Button::Right);
return {prev, next};
}
+4 -10
View File
@@ -155,16 +155,6 @@ void TxtReaderActivity::loop() {
return;
}
// Star page toggle via short power button press
if (SETTINGS.shortPwrBtn == CrossPointSettings::SHORT_PWRBTN::STAR_PAGE &&
mappedInput.wasReleased(MappedInputManager::Button::Power)) {
if (currentPage >= 0) {
bookmarkStore.toggle(0, static_cast<uint16_t>(currentPage));
}
requestUpdate();
return;
}
// Open starred pages list via Confirm button
if (mappedInput.wasReleased(MappedInputManager::Button::Confirm) && !bookmarkStore.isEmpty()) {
ReaderUtils::enforceExitFullRefresh(renderer);
@@ -826,6 +816,10 @@ void TxtReaderActivity::onButtonAction(const CrossPointSettings::BUTTON_ACTION a
clampPage();
requestUpdate();
break;
case BA::BTN_EXIT_READER:
ReaderUtils::enforceExitFullRefresh(renderer);
finish();
break;
default:
break;
}
+5 -3
View File
@@ -94,9 +94,7 @@ void XtcReaderActivity::loop() {
const bool prevTriggered = mappedInput.wasReleased(MappedInputManager::Button::PageBack) ||
mappedInput.wasReleased(MappedInputManager::Button::Left);
const bool powerPageTurn = SETTINGS.shortPwrBtn == CrossPointSettings::SHORT_PWRBTN::PAGE_TURN &&
mappedInput.wasReleased(MappedInputManager::Button::Power);
const bool nextTriggered = mappedInput.wasReleased(MappedInputManager::Button::PageForward) || powerPageTurn ||
const bool nextTriggered = mappedInput.wasReleased(MappedInputManager::Button::PageForward) ||
mappedInput.wasReleased(MappedInputManager::Button::Right);
if (!prevTriggered && !nextTriggered) {
@@ -469,6 +467,10 @@ void XtcReaderActivity::onButtonAction(const CrossPointSettings::BUTTON_ACTION a
currentPage = (currentPage >= 10) ? currentPage - 10 : 0;
requestUpdate();
break;
case BA::BTN_EXIT_READER:
ReaderUtils::enforceExitFullRefresh(renderer);
finish();
break;
default:
break;
}