diff --git a/packages/react-native/ReactCommon/jsinspector-modern/InspectorInterfaces.cpp b/packages/react-native/ReactCommon/jsinspector-modern/InspectorInterfaces.cpp index 38d015e8357..b98cb113f72 100644 --- a/packages/react-native/ReactCommon/jsinspector-modern/InspectorInterfaces.cpp +++ b/packages/react-native/ReactCommon/jsinspector-modern/InspectorInterfaces.cpp @@ -31,7 +31,8 @@ class InspectorImpl : public IInspector { int addPage( const std::string& title, const std::string& vm, - ConnectFunc connectFunc) override; + ConnectFunc connectFunc, + InspectorPageType type) override; void removePage(int pageId) override; std::vector getPages() const override; @@ -49,7 +50,8 @@ class InspectorImpl : public IInspector { int id, const std::string& title, const std::string& vm, - ConnectFunc connectFunc); + ConnectFunc connectFunc, + InspectorPageType type); operator InspectorPageDescription() const; ConnectFunc getConnectFunc() const; @@ -59,6 +61,7 @@ class InspectorImpl : public IInspector { std::string title_; std::string vm_; ConnectFunc connectFunc_; + InspectorPageType type_; }; mutable std::mutex mutex_; int nextPageId_{1}; @@ -70,14 +73,20 @@ InspectorImpl::Page::Page( int id, const std::string& title, const std::string& vm, - ConnectFunc connectFunc) - : id_(id), title_(title), vm_(vm), connectFunc_(std::move(connectFunc)) {} + ConnectFunc connectFunc, + InspectorPageType type) + : id_(id), + title_(title), + vm_(vm), + connectFunc_(std::move(connectFunc)), + type_(type) {} InspectorImpl::Page::operator InspectorPageDescription() const { return InspectorPageDescription{ .id = id_, .title = title_, .vm = vm_, + .type = type_, }; } @@ -88,12 +97,13 @@ InspectorImpl::ConnectFunc InspectorImpl::Page::getConnectFunc() const { int InspectorImpl::addPage( const std::string& title, const std::string& vm, - ConnectFunc connectFunc) { + ConnectFunc connectFunc, + InspectorPageType type) { std::scoped_lock lock(mutex_); int pageId = nextPageId_++; assert(pages_.count(pageId) == 0 && "Unexpected duplicate page ID"); - pages_.emplace(pageId, Page{pageId, title, vm, std::move(connectFunc)}); + pages_.emplace(pageId, Page{pageId, title, vm, std::move(connectFunc), type}); return pageId; } diff --git a/packages/react-native/ReactCommon/jsinspector-modern/InspectorInterfaces.h b/packages/react-native/ReactCommon/jsinspector-modern/InspectorInterfaces.h index 6af3aec14db..ff07be1b25f 100644 --- a/packages/react-native/ReactCommon/jsinspector-modern/InspectorInterfaces.h +++ b/packages/react-native/ReactCommon/jsinspector-modern/InspectorInterfaces.h @@ -31,10 +31,25 @@ class IDestructible { virtual ~IDestructible() = 0; }; +enum class InspectorPageType { + Legacy, + Modern, +}; + +inline const char* pageTypeToString(InspectorPageType type) { + switch (type) { + case InspectorPageType::Legacy: + return "Legacy"; + case InspectorPageType::Modern: + return "Modern"; + } +} + struct InspectorPageDescription { const int id; const std::string title; const std::string vm; + const InspectorPageType type; }; // Alias for backwards compatibility. @@ -82,7 +97,8 @@ class JSINSPECTOR_EXPORT IInspector : public IDestructible { virtual int addPage( const std::string& title, const std::string& vm, - ConnectFunc connectFunc) = 0; + ConnectFunc connectFunc, + InspectorPageType type = InspectorPageType::Legacy) = 0; /// removePage is called by the VM to remove a page from the list of /// debuggable pages. diff --git a/packages/react-native/ReactCommon/jsinspector-modern/InspectorPackagerConnection.cpp b/packages/react-native/ReactCommon/jsinspector-modern/InspectorPackagerConnection.cpp index cbfdc3fb953..2ef3c40df97 100644 --- a/packages/react-native/ReactCommon/jsinspector-modern/InspectorPackagerConnection.cpp +++ b/packages/react-native/ReactCommon/jsinspector-modern/InspectorPackagerConnection.cpp @@ -148,7 +148,8 @@ folly::dynamic InspectorPackagerConnection::Impl::pages() { for (const auto& page : pages) { array.push_back(folly::dynamic::object("id", std::to_string(page.id))( - "title", page.title + " [C++ connection]")("app", app_)("vm", page.vm)); + "title", page.title + " [C++ connection]")( + "app", app_)("vm", page.vm)("type", pageTypeToString(page.type))); } return array; } diff --git a/packages/react-native/ReactCommon/jsinspector-modern/tests/InspectorPackagerConnectionTest.cpp b/packages/react-native/ReactCommon/jsinspector-modern/tests/InspectorPackagerConnectionTest.cpp index f38c80229e4..d0b62cfabbc 100644 --- a/packages/react-native/ReactCommon/jsinspector-modern/tests/InspectorPackagerConnectionTest.cpp +++ b/packages/react-native/ReactCommon/jsinspector-modern/tests/InspectorPackagerConnectionTest.cpp @@ -216,7 +216,8 @@ TEST_F(InspectorPackagerConnectionTest, TestGetPages) { AtJsonPtr("/app", Eq("my-app")), AtJsonPtr("/title", Eq("mock-title [C++ connection]")), AtJsonPtr("/vm", Eq("mock-vm")), - AtJsonPtr("/id", Eq(std::to_string(pageId))))})))))) + AtJsonPtr("/id", Eq(std::to_string(pageId))), + AtJsonPtr("/type", Eq("Legacy")))})))))) .RetiresOnSaturation(); webSockets_[0]->getDelegate().didReceiveMessage(R"({ "event": "getPages"