MCPcopy Create free account
hub / github.com/FastLED/FastLED / ensureWasmUiSystemInitialized

Function ensureWasmUiSystemInitialized

src/platforms/wasm/ui.cpp.hpp:126–164  ·  view source on GitHub ↗

* Async-aware UI system initializer * Ensures the UI system is initialized with proper async support */

Source from the content-addressed store, hash-verified

124 * Ensures the UI system is initialized with proper async support
125 */
126void ensureWasmUiSystemInitialized() {
127 // FL_WARN("*** ASYNC CODE UPDATE VERIFICATION: This message confirms the C++ code has been rebuilt! ***");
128 // FL_WARN("*** ensureWasmUiSystemInitialized ASYNC ENTRY: g_uiSystemInitialized=" << (getUiSystemInitialized() ? "true" : "false") << ", g_updateEngineState=" << (getUpdateEngineState() ? "VALID" : "nullptr"));
129
130 // Return early if already initialized - CRITICAL FIX
131 if (getUiSystemInitialized()) {
132 FL_WARN("*** ensureWasmUiSystemInitialized ASYNC: Already initialized, returning early");
133 return;
134 }
135
136 if (!getUiSystemInitialized() || !getUpdateEngineState()) {
137 FL_WARN("*** ASYNC WASM INITIALIZING UI SYSTEM ***");
138
139 // Create UI update handler that posts message to main thread
140 // In PROXY_TO_PTHREAD mode, C++ runs in worker thread, UI manager runs on main thread
141 JsonUiUpdateOutput updateJsHandler = [](const char* jsonStr) {
142 if (!jsonStr) {
143 FL_WARN("*** UI UPDATE HANDLER ERROR: Received null jsonStr");
144 return; // Early return on error
145 }
146
147 // Post message to main thread with UI JSON
148 // Main thread will call uiManager.addUiElements()
149 js_post_ui_elements(jsonStr);
150 };
151
152 // Initialize with error checking via early return
153 auto tempResult = setJsonUiHandlers(updateJsHandler);
154 if (!tempResult) {
155 FL_WARN("*** ASYNC WASM UI SYSTEM INITIALIZATION FAILED: setJsonUiHandlers returned null");
156 return; // Early return on failure
157 }
158
159 getUpdateEngineState() = tempResult;
160 getUiSystemInitialized() = true;
161
162 FL_WARN("*** ASYNC WASM UI SYSTEM INITIALIZATION COMPLETED ***");
163 }
164}
165
166/**
167 * Async-aware startup initializer

Callers 2

jsUpdateUiComponentsFunction · 0.85

Calls 1

setJsonUiHandlersFunction · 0.85

Tested by

no test coverage detected