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.

feat: show crash reason on boot (#1453)

## Summary

If the system reboots from crash, display the reason and tell user to
include `crash_report.txt` file.

To test this, simply add an `assert(false)` somewhere inside the code.


![screenshot-74453.bmp](https://github.com/user-attachments/files/26160373/screenshot-74453.bmp)

---

### 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

Xuan-Son Nguyen and committed by
GitHub
243ae8b4 4e9c7a78

+89 -5
+4
lib/I18n/translations/english.yaml
··· 294 294 STR_SCREENSHOT_BUTTON: "Take screenshot" 295 295 STR_AUTO_TURN_ENABLED: "Auto Turn Enabled: " 296 296 STR_AUTO_TURN_PAGES_PER_MIN: "Auto Turn (Pages Per Minute)" 297 + STR_CRASH_TITLE: "System Crash" 298 + STR_CRASH_DESCRIPTION: "A detailed report was saved to crash_report.txt. Please include this file in your bug report." 299 + STR_CRASH_REASON: "Crash reason:" 300 + STR_CRASH_NO_REASON: "(No reason was recorded)"
+3
src/activities/ActivityManager.cpp
··· 5 5 #include "boot_sleep/BootActivity.h" 6 6 #include "boot_sleep/SleepActivity.h" 7 7 #include "browser/OpdsBookBrowserActivity.h" 8 + #include "home/CrashActivity.h" 8 9 #include "home/FileBrowserActivity.h" 9 10 #include "home/HomeActivity.h" 10 11 #include "home/RecentBooksActivity.h" ··· 195 196 void ActivityManager::goToFullScreenMessage(std::string message, EpdFontFamily::Style style) { 196 197 replaceActivity(std::make_unique<FullScreenMessageActivity>(renderer, mappedInput, std::move(message), style)); 197 198 } 199 + 200 + void ActivityManager::goToCrashReport() { replaceActivity(std::make_unique<CrashActivity>(renderer, mappedInput)); } 198 201 199 202 void ActivityManager::goHome() { replaceActivity(std::make_unique<HomeActivity>(renderer, mappedInput)); } 200 203
+1
src/activities/ActivityManager.h
··· 86 86 void goToSleep(); 87 87 void goToBoot(); 88 88 void goToFullScreenMessage(std::string message, EpdFontFamily::Style style = EpdFontFamily::REGULAR); 89 + void goToCrashReport(); 89 90 void goHome(); 90 91 91 92 // This will move current activity to stack instead of deleting it
+61
src/activities/home/CrashActivity.cpp
··· 1 + #include "CrashActivity.h" 2 + 3 + #include <GfxRenderer.h> 4 + #include <HalSystem.h> 5 + #include <I18n.h> 6 + 7 + #include "components/UITheme.h" 8 + #include "fontIds.h" 9 + 10 + void CrashActivity::onEnter() { 11 + Activity::onEnter(); 12 + 13 + panicMessage = HalSystem::getPanicInfo(false); 14 + if (panicMessage.empty()) { 15 + panicMessage = tr(STR_CRASH_NO_REASON); 16 + } 17 + HalSystem::clearPanic(); 18 + 19 + requestUpdateAndWait(); 20 + } 21 + 22 + void CrashActivity::loop() { 23 + if (mappedInput.isPressed(MappedInputManager::Button::Back)) { 24 + finish(); 25 + } 26 + } 27 + 28 + void CrashActivity::render(RenderLock&&) { 29 + renderer.clearScreen(); 30 + 31 + const auto& metrics = UITheme::getInstance().getMetrics(); 32 + const auto pageWidth = renderer.getScreenWidth(); 33 + const auto contentWidth = pageWidth - 2 * metrics.contentSidePadding; 34 + const auto x = metrics.contentSidePadding; 35 + const auto lineHeight = renderer.getLineHeight(UI_10_FONT_ID); 36 + 37 + GUI.drawHeader(renderer, Rect{0, metrics.topPadding, pageWidth, metrics.headerHeight}, tr(STR_CRASH_TITLE)); 38 + 39 + int y = metrics.topPadding + metrics.headerHeight + metrics.verticalSpacing; 40 + 41 + auto descLines = renderer.wrappedText(UI_10_FONT_ID, tr(STR_CRASH_DESCRIPTION), contentWidth, 10); 42 + for (const auto& line : descLines) { 43 + renderer.drawText(UI_10_FONT_ID, x, y, line.c_str()); 44 + y += lineHeight; 45 + } 46 + 47 + y += metrics.verticalSpacing * 2; 48 + renderer.drawText(UI_10_FONT_ID, x, y, tr(STR_CRASH_REASON)); 49 + y += lineHeight + metrics.verticalSpacing; 50 + 51 + auto panicLines = renderer.wrappedText(UI_10_FONT_ID, panicMessage.c_str(), contentWidth, 5); 52 + for (const auto& line : panicLines) { 53 + renderer.drawText(UI_10_FONT_ID, x, y, line.c_str()); 54 + y += lineHeight; 55 + } 56 + 57 + const auto labels = mappedInput.mapLabels(tr(STR_BACK), "", "", ""); 58 + GUI.drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4); 59 + 60 + renderer.displayBuffer(); 61 + }
+13
src/activities/home/CrashActivity.h
··· 1 + #pragma once 2 + #include "../Activity.h" 3 + 4 + class CrashActivity final : public Activity { 5 + std::string panicMessage; 6 + 7 + public: 8 + explicit CrashActivity(GfxRenderer& renderer, MappedInputManager& mappedInput) 9 + : Activity("Crash", renderer, mappedInput) {} 10 + void onEnter() override; 11 + void loop() override; 12 + void render(RenderLock&&) override; 13 + };
+7 -5
src/main.cpp
··· 253 253 } 254 254 255 255 HalSystem::checkPanic(); 256 - HalSystem::clearPanic(); // TODO: move this to an activity when we have one to display the panic info 257 256 258 257 SETTINGS.loadFromFile(); 259 258 I18N.loadSettings(); ··· 290 289 APP_STATE.loadFromFile(); 291 290 RECENT_BOOKS.loadFromFile(); 292 291 293 - // Boot to home screen if no book is open, last sleep was not from reader, back button is held, or reader activity 294 - // crashed (indicated by readerActivityLoadCount > 0) 295 - if (APP_STATE.openEpubPath.empty() || !APP_STATE.lastSleepFromReader || 296 - mappedInputManager.isPressed(MappedInputManager::Button::Back) || APP_STATE.readerActivityLoadCount > 0) { 292 + if (HalSystem::isRebootFromPanic()) { 293 + // If we rebooted from a panic, go to crash report screen to show the panic info 294 + activityManager.goToCrashReport(); 295 + } else if (APP_STATE.openEpubPath.empty() || !APP_STATE.lastSleepFromReader || 296 + mappedInputManager.isPressed(MappedInputManager::Button::Back) || APP_STATE.readerActivityLoadCount > 0) { 297 + // Boot to home screen if no book is open, last sleep was not from reader, back button is held, or reader activity 298 + // crashed (indicated by readerActivityLoadCount > 0) 297 299 activityManager.goHome(); 298 300 } else { 299 301 // Clear app state to avoid getting into a boot loop if the epub doesn't load