Skip to content

Commit 46c64c8

Browse files
authored
Improve the inspector page name for modern debugger (#15375) (#15397)
* visual studio 2026 strict check fix * Add HostTargetMetadata with app name and device name for inspector page naming * lint:fix * Change files * revert VS 2026 strict checks fix * review comments
1 parent 4983c4d commit 46c64c8

File tree

2 files changed

+46
-6
lines changed

2 files changed

+46
-6
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "Add HostTargetMetadata with app name and device name for inspector page naming",
4+
"packageName": "react-native-windows",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

vnext/Microsoft.ReactNative/ReactHost/ReactHost.cpp

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,32 @@ class ReactInspectorHostTargetDelegate : public jsinspector_modern::HostTargetDe
326326
ReactInspectorHostTargetDelegate(Mso::WeakPtr<ReactHost> &&reactHost) noexcept : m_reactHost(std::move(reactHost)) {}
327327

328328
jsinspector_modern::HostTargetMetadata getMetadata() override {
329-
// TODO: (vmoroz) provide more info
330-
return {
331-
.integrationName = "React Native Windows (Host)",
332-
};
329+
jsinspector_modern::HostTargetMetadata metadata{};
330+
metadata.integrationName = "React Native Windows (Host)";
331+
metadata.platform = "windows";
332+
333+
if (Mso::CntPtr<ReactHost> reactHost = m_reactHost.GetStrongPtr()) {
334+
const ReactOptions &options = reactHost->Options();
335+
if (!options.Identity.empty()) {
336+
std::string identity = options.Identity;
337+
// Replace illegal characters with underscore
338+
for (char &c : identity) {
339+
if (c == '\\' || c == '/' || c == ':' || c == '*' || c == '?' || c == '"' || c == '<' || c == '>' ||
340+
c == '|') {
341+
c = '_';
342+
}
343+
}
344+
metadata.appDisplayName = identity;
345+
}
346+
}
347+
348+
wchar_t computerName[MAX_COMPUTERNAME_LENGTH + 1];
349+
DWORD size = MAX_COMPUTERNAME_LENGTH + 1;
350+
if (GetComputerNameW(computerName, &size)) {
351+
metadata.deviceName = winrt::to_string(computerName);
352+
}
353+
354+
return metadata;
333355
}
334356

335357
void onReload(jsinspector_modern::HostTargetDelegate::PageReloadRequest const &request) override {
@@ -630,9 +652,20 @@ void ReactHost::AddInspectorPage() noexcept {
630652
jsinspector_modern::InspectorTargetCapabilities capabilities;
631653
capabilities.nativePageReloads = true;
632654
capabilities.prefersFuseboxFrontend = true;
633-
// TODO: (vmoroz) improve the page name
655+
656+
auto metadata = m_inspectorHostTargetDelegate->getMetadata();
657+
std::string pageName;
658+
if (metadata.appDisplayName.has_value() && !metadata.appDisplayName.value().empty()) {
659+
pageName = metadata.appDisplayName.value();
660+
} else {
661+
pageName = "React Native Windows (Experimental)";
662+
}
663+
if (metadata.deviceName.has_value() && !metadata.deviceName.value().empty()) {
664+
pageName += " (" + metadata.deviceName.value() + ")";
665+
}
666+
634667
inspectorPageId = jsinspector_modern::getInspectorInstance().addPage(
635-
"React Native Windows (Experimental)",
668+
pageName,
636669
"Hermes",
637670
[weakInspectorHostTarget =
638671
std::weak_ptr(m_inspectorHostTarget)](std::unique_ptr<jsinspector_modern::IRemoteConnection> remote)

0 commit comments

Comments
 (0)