| 62 | } |
| 63 | |
| 64 | void ScreenshotTask::taskMain() { |
| 65 | uint8_t screenshots_taken = 0; |
| 66 | std::string last_app_id; |
| 67 | |
| 68 | while (!isInterrupted()) { |
| 69 | if (work.type == TASK_WORK_TYPE_DELAY) { |
| 70 | // Splitting up the delays makes it easier to stop the service |
| 71 | for (int i = 0; i < (work.delay_in_seconds * 10) && !isInterrupted(); ++i){ |
| 72 | kernel::delayMillis(100); |
| 73 | } |
| 74 | |
| 75 | if (!isInterrupted()) { |
| 76 | screenshots_taken++; |
| 77 | std::string filename = std::format("{}/screenshot-{}.png", work.path, screenshots_taken); |
| 78 | makeScreenshot(filename); |
| 79 | |
| 80 | if (work.amount > 0 && screenshots_taken >= work.amount) { |
| 81 | break; // Interrupted loop |
| 82 | } |
| 83 | } |
| 84 | } else if (work.type == TASK_WORK_TYPE_APPS) { |
| 85 | auto appContext = app::getCurrentAppContext(); |
| 86 | if (appContext != nullptr) { |
| 87 | const app::AppManifest& manifest = appContext->getManifest(); |
| 88 | if (manifest.appId != last_app_id) { |
| 89 | kernel::delayMillis(100); |
| 90 | last_app_id = manifest.appId; |
| 91 | auto filename = std::format("{}/screenshot-{}.png", work.path, manifest.appId); |
| 92 | makeScreenshot(filename); |
| 93 | } |
| 94 | } |
| 95 | // Ensure the LVGL widgets are rendered as the app just started |
| 96 | kernel::delayMillis(250); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | setFinished(); |
| 101 | } |
| 102 | |
| 103 | void ScreenshotTask::taskStart() { |
| 104 | auto lock = mutex.asScopedLock(); |
no test coverage detected