Update status bar immediately on BLE connect/disconnect

Previously the status bar showed 'BT connecting' until the next page turn. Now monitors connection state in loop() and redraws the status bar immediately when connection completes or disconnects, restoring the chapter/book title. The connecting message now takes over the entire title slot instead of prepending to it.
This commit is contained in:
Justin Mitchell
2026-07-14 04:47:48 -04:00
parent 17e4230068
commit 078d9ef535
2 changed files with 24 additions and 2 deletions
+19 -2
View File
@@ -208,6 +208,8 @@ void EpubReaderActivity::onEnter() {
ImageBlock::clearSessionRenderFailures();
statusBarBleConnected = BleHid.isConnected();
// Configure screen orientation based on settings
// NOTE: This affects layout math and must be applied before any render calls.
ReaderUtils::applyOrientation(renderer, SETTINGS.orientation);
@@ -341,6 +343,19 @@ void EpubReaderActivity::loop() {
return;
}
// Swap the "BT connecting" status bar placeholder back to the chapter/book
// title the moment the connection completes (and back on disconnect). Skips
// while a render is in flight or the framebuffer is lent to a build; the
// next page render shows the right state anyway.
if (SETTINGS.bluetoothEnabled && section && renderer.hasFrameBuffer() && !RenderLock::peek()) {
const bool connected = BleHid.isConnected();
if (connected != statusBarBleConnected) {
statusBarBleConnected = connected;
renderStatusBar();
renderer.displayBuffer(HalDisplay::FAST_REFRESH);
}
}
// Lazily resume a partial's extension build once the reader nears its watermark. Far from
// it the rebuild is all cost (whole-chapter re-layout from page 0) and no benefit this
// session, so reopening a partial deliberately does NOT start it (see the deferral in
@@ -1790,8 +1805,10 @@ void EpubReaderActivity::renderStatusBar() const {
}
if (SETTINGS.bluetoothEnabled && !BleHid.isConnected()) {
const std::string btStatus = tr(STR_BT_CONNECTING_POPUP);
title = title.empty() ? btStatus : btStatus + " " + title;
// Take over the title slot entirely while connecting; the watcher in
// loop() redraws the bar on the connect/disconnect flip, restoring the
// chapter/book title.
title = tr(STR_BT_CONNECTING_POPUP);
}
GUI.drawStatusBar(renderer, bookProgress, currentPage, pageCount, title, 0, textYOffset, true, currentPageBookmarked,
@@ -41,6 +41,11 @@ class EpubReaderActivity final : public Activity {
bool showBookmarkMessage = false;
bool ignoreNextConfirmRelease = false;
bool currentPageBookmarked = false;
// BLE connection state the status bar last rendered with; loop() watches for
// a flip and redraws the bar so the "BT connecting" placeholder swaps back
// to the chapter/book title the moment the connection completes (and
// returns on disconnect) instead of waiting for the next page turn.
bool statusBarBleConnected = false;
bool bookmarkRemoved = false; // true when last toggle removed (controls popup text)
std::vector<BookmarkEntry> cachedBookmarks;
// Tracks whether this book is currently removed from Recent Books by the