MCPcopy Create free account
hub / github.com/TactilityProject/Tactility / taskMain

Method taskMain

Tactility/Source/service/screenshot/ScreenshotTask.cpp:64–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62}
63
64void 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
103void ScreenshotTask::taskStart() {
104 auto lock = mutex.asScopedLock();

Callers 1

taskStartMethod · 0.95

Calls 3

delayMillisFunction · 0.85
makeScreenshotFunction · 0.85
getCurrentAppContextFunction · 0.85

Tested by

no test coverage detected