* Async-aware UI component updater * Now handles async operations and provides better error handling */
| 74 | * Now handles async operations and provides better error handling |
| 75 | */ |
| 76 | void jsUpdateUiComponents(const char* jsonStr) { |
| 77 | // FL_WARN("*** jsUpdateUiComponents ASYNC ENTRY ***"); |
| 78 | // FL_WARN("*** jsUpdateUiComponents ASYNC RECEIVED JSON: " << jsonStr.c_str()); |
| 79 | // FL_WARN("*** jsUpdateUiComponents ASYNC JSON LENGTH: " << jsonStr.length()); |
| 80 | // FL_WARN("*** jsUpdateUiComponents ASYNC ENTRY: g_uiSystemInitialized=" << (getUiSystemInitialized() ? "true" : "false") << ", g_updateEngineState=" << (getUpdateEngineState() ? "VALID" : "nullptr")); |
| 81 | |
| 82 | // Only initialize if not already initialized - don't force reinitialization |
| 83 | if (!getUiSystemInitialized()) { |
| 84 | FL_WARN("*** ASYNC WASM: UI system not initialized, initializing for first time"); |
| 85 | ensureWasmUiSystemInitialized(); |
| 86 | } |
| 87 | |
| 88 | //FL_WARN("*** jsUpdateUiComponents ASYNC AFTER INIT: g_uiSystemInitialized=" << (getUiSystemInitialized() ? "true" : "false") << ", g_updateEngineState=" << (getUpdateEngineState() ? "VALID" : "nullptr")); |
| 89 | |
| 90 | if (getUpdateEngineState()) { |
| 91 | //FL_WARN("*** ASYNC WASM CALLING BACKEND WITH JSON: " << jsonStr.c_str()); |
| 92 | |
| 93 | // Call the backend function - handle errors via early return |
| 94 | if (getUpdateEngineState()) { |
| 95 | getUpdateEngineState()(jsonStr); |
| 96 | //FL_WARN("*** ASYNC WASM BACKEND CALL COMPLETED SUCCESSFULLY"); |
| 97 | } else { |
| 98 | FL_WARN("*** ASYNC WASM BACKEND CALL FAILED: updateEngineState is null"); |
| 99 | return; // Early return on error |
| 100 | } |
| 101 | |
| 102 | } else { |
| 103 | FL_WARN("*** ASYNC WASM ERROR: No driver state updater available, attempting emergency reinitialization..."); |
| 104 | |
| 105 | // Try to reinitialize as a recovery mechanism |
| 106 | getUiSystemInitialized() = false; // Force reinitialization |
| 107 | ensureWasmUiSystemInitialized(); |
| 108 | |
| 109 | FL_WARN("*** ASYNC AFTER EMERGENCY REINIT: g_updateEngineState=" << (getUpdateEngineState() ? "VALID" : "nullptr")); |
| 110 | |
| 111 | if (getUpdateEngineState()) { |
| 112 | FL_WARN("*** ASYNC EMERGENCY REINIT SUCCESSFUL - retrying JSON processing"); |
| 113 | getUpdateEngineState()(jsonStr); |
| 114 | FL_WARN("*** ASYNC EMERGENCY RETRY COMPLETED SUCCESSFULLY"); |
| 115 | } else { |
| 116 | FL_WARN("*** ASYNC EMERGENCY REINIT FAILED - g_updateEngineState still nullptr"); |
| 117 | return; // Early return on failure |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Async-aware UI system initializer |
no test coverage detected