| 57 | } |
| 58 | |
| 59 | void JsonUiManager::processPendingUpdates() FL_NOEXCEPT { |
| 60 | // Force immediate processing of pending updates (for testing) |
| 61 | |
| 62 | if (mHasPendingUpdate) { |
| 63 | executeUiUpdates(mPendingJsonUpdate); |
| 64 | mPendingJsonUpdate = fl::json(); // Clear the pending update |
| 65 | mHasPendingUpdate = false; |
| 66 | } |
| 67 | |
| 68 | |
| 69 | bool shouldUpdate = false; |
| 70 | { |
| 71 | fl::unique_lock<fl::mutex> lock(mMutex); |
| 72 | // Check if new components were added |
| 73 | shouldUpdate = mItemsAdded; |
| 74 | mItemsAdded = false; |
| 75 | |
| 76 | // Poll all components for changes (eliminates need for manual notifications) |
| 77 | if (!shouldUpdate) { |
| 78 | for (auto &componentRef : mComponents) { |
| 79 | if (auto component = componentRef.lock()) { |
| 80 | if (component->hasChanged()) { |
| 81 | shouldUpdate = true; |
| 82 | break; // Found at least one change, no need to check more |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | if (shouldUpdate) { |
| 90 | fl::json doc = fl::json::array(); |
| 91 | toJson(doc); |
| 92 | fl::string jsonStr = doc.to_string(); |
| 93 | //FL_WARN("*** SENDING UI TO FRONTEND: " << jsonStr.substr(0, 100).c_str() << "..."); |
| 94 | mUpdateJs(jsonStr.c_str()); |
| 95 | |
| 96 | // Clear the changed flag for all components after sending the update |
| 97 | fl::unique_lock<fl::mutex> lock(mMutex); // Acquire lock again for modifying mComponents |
| 98 | for (auto &componentRef : mComponents) { |
| 99 | if (auto component = componentRef.lock()) { |
| 100 | component->clearChanged(); |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | } |
| 111 | |
| 112 | fl::vector<JsonUiInternalPtr> JsonUiManager::getComponents() FL_NOEXCEPT { |
| 113 | fl::unique_lock<fl::mutex> lock(mMutex); |
no test coverage detected