Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Add HostTargetMetadata with app name and device name for inspector page naming",
"packageName": "react-native-windows",
"email": "[email protected]",
"dependentChangeType": "patch"
}
45 changes: 39 additions & 6 deletions vnext/Microsoft.ReactNative/ReactHost/ReactHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,32 @@ class ReactInspectorHostTargetDelegate : public jsinspector_modern::HostTargetDe
ReactInspectorHostTargetDelegate(Mso::WeakPtr<ReactHost> &&reactHost) noexcept : m_reactHost(std::move(reactHost)) {}

jsinspector_modern::HostTargetMetadata getMetadata() override {
// TODO: (vmoroz) provide more info
return {
.integrationName = "React Native Windows (Host)",
};
jsinspector_modern::HostTargetMetadata metadata{};
metadata.integrationName = "React Native Windows (Host)";
metadata.platform = "windows";

if (Mso::CntPtr<ReactHost> reactHost = m_reactHost.GetStrongPtr()) {
const ReactOptions &options = reactHost->Options();
if (!options.Identity.empty()) {
std::string identity = options.Identity;
// Replace illegal characters with underscore
for (char &c : identity) {
if (c == '\\' || c == '/' || c == ':' || c == '*' || c == '?' || c == '"' || c == '<' || c == '>' ||
c == '|') {
c = '_';
}
}
metadata.appDisplayName = identity;
}
}

wchar_t computerName[MAX_COMPUTERNAME_LENGTH + 1];
DWORD size = MAX_COMPUTERNAME_LENGTH + 1;
if (GetComputerNameW(computerName, &size)) {
metadata.deviceName = winrt::to_string(computerName);
}

return metadata;
}

void onReload(jsinspector_modern::HostTargetDelegate::PageReloadRequest const &request) override {
Expand Down Expand Up @@ -630,9 +652,20 @@ void ReactHost::AddInspectorPage() noexcept {
jsinspector_modern::InspectorTargetCapabilities capabilities;
capabilities.nativePageReloads = true;
capabilities.prefersFuseboxFrontend = true;
// TODO: (vmoroz) improve the page name

auto metadata = m_inspectorHostTargetDelegate->getMetadata();
std::string pageName;
if (metadata.appDisplayName.has_value() && !metadata.appDisplayName.value().empty()) {
pageName = metadata.appDisplayName.value();
} else {
pageName = "React Native Windows (Experimental)";
}
if (metadata.deviceName.has_value() && !metadata.deviceName.value().empty()) {
pageName += " (" + metadata.deviceName.value() + ")";
}

inspectorPageId = jsinspector_modern::getInspectorInstance().addPage(
"React Native Windows (Experimental)",
pageName,
"Hermes",
[weakInspectorHostTarget =
std::weak_ptr(m_inspectorHostTarget)](std::unique_ptr<jsinspector_modern::IRemoteConnection> remote)
Expand Down
Loading