| 150 | } |
| 151 | |
| 152 | bool PyUIHookRegistry::invoke_document(const std::string& panel, |
| 153 | const std::string& section, |
| 154 | Rml::ElementDocument* document, |
| 155 | PyHookPosition position) { |
| 156 | nb::gil_scoped_acquire gil; |
| 157 | std::vector<HookEntry> callbacks; |
| 158 | { |
| 159 | std::lock_guard lock(mutex_); |
| 160 | const std::string key = panel + ":" + section; |
| 161 | auto it = hooks_.find(key); |
| 162 | if (it == hooks_.end()) { |
| 163 | return consume_document_dirty_with_attribution( |
| 164 | document, panel, section, position, "<none>", "no_hooks"); |
| 165 | } |
| 166 | for (const auto& entry : it->second) { |
| 167 | if (entry.position == position) { |
| 168 | callbacks.push_back(entry); |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | if (callbacks.empty()) { |
| 174 | return consume_document_dirty_with_attribution( |
| 175 | document, panel, section, position, "<none>", "no_callbacks"); |
| 176 | } |
| 177 | |
| 178 | bool dirty = consume_document_dirty_with_attribution( |
| 179 | document, panel, section, position, "<pre_hooks>", "before_callbacks"); |
| 180 | for (const auto& entry : callbacks) { |
| 181 | try { |
| 182 | if (document) { |
| 183 | entry.callback(PyRmlDocument(document)); |
| 184 | } else { |
| 185 | PyUILayout layout; |
| 186 | entry.callback(layout); |
| 187 | } |
| 188 | } catch (const std::exception& e) { |
| 189 | LOG_ERROR("Hook {}:{} error: {}", panel, section, e.what()); |
| 190 | } |
| 191 | dirty |= consume_document_dirty_with_attribution( |
| 192 | document, panel, section, position, entry.name, "after_callback"); |
| 193 | } |
| 194 | return dirty; |
| 195 | } |
| 196 | |
| 197 | bool PyUIHookRegistry::has_hooks(const std::string& panel, const std::string& section) const { |
| 198 | std::lock_guard lock(mutex_); |
no test coverage detected