33 auto exportsObj = QNapi::checkedCast<QNapi::Object>(QNapi::Value{env, exports});
34 auto xComponentWrappedValue = QNapi::getOptionalPropOrEmpty<QNapi::Object>(
36 OH_NATIVE_XCOMPONENT_OBJ);
37 if (xComponentWrappedValue.IsEmpty())
40 ::OH_NativeXComponent *xComponent =
nullptr;
41 auto status = ::napi_unwrap(
43 xComponentWrappedValue,
44 reinterpret_cast<
void **>(&xComponent));
45 if (status != ::napi_ok) {
46 qOhosPrintfError(
"Failed to unwrap xcomponent with napi_status: %d", status);
50 auto optXComponentId = QXComponentId::tryCreateFromXComponent(xComponent);
51 if (!optXComponentId.hasValue()) {
52 qOhosPrintfError(
"Failed to retrieve id from xcomponent. Ignoring the component");
56 auto xComponentId = optXComponentId.value();
58 auto optXComponentIdType = xComponentId.recognizedType();
59 if (!optXComponentIdType.hasValue()) {
61 "Ignoring xComponent due to unrecognized id value: %s",
62 xComponentId.stringId().c_str());
66 bool canRegister =
false;
67 switch (optXComponentIdType.value()) {
80 "Ignoring xComponent because its id type is not supported in registry. id: %s type: %d",
81 xComponentId.stringId().c_str(),
82 optXComponentIdType.value());
88 bool xComponentRegistered;
89 std::tie(
std::ignore, xComponentRegistered) =
90 registry.m_xComponents.emplace(xComponentId,
QXComponentNode(xComponent));
92 if (!xComponentRegistered) {
93 qOhosReportFatalErrorAndAbort(
94 "Error: Duplicate xComponent detected. Duplicate ID: %s",
95 xComponentId.stringId().c_str());