Skip to content

Commit d3cce3d

Browse files
committed
Update window title for profiling builds
1 parent a130be4 commit d3cce3d

File tree

6 files changed

+94
-30
lines changed

6 files changed

+94
-30
lines changed

config/gni/devtools_grd_files.gni

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,8 +842,10 @@ grd_files_debug_sources = [
842842
"front_end/entrypoints/node_app/NodeConnectionsPanel.js",
843843
"front_end/entrypoints/node_app/NodeMain.js",
844844
"front_end/entrypoints/node_app/nodeConnectionsPanel.css.js",
845+
"front_end/entrypoints/rn_fusebox/FuseboxAppMetadataObserver.js",
845846
"front_end/entrypoints/rn_fusebox/FuseboxProfilingBuildObserver.js",
846847
"front_end/entrypoints/rn_fusebox/FuseboxReconnectDeviceButton.js",
848+
"front_end/entrypoints/rn_fusebox/FuseboxWindowTitleManager.js",
847849
"front_end/entrypoints/shell/browser_compatibility_guard.js",
848850
"front_end/entrypoints/wasmparser_worker/WasmParserWorker.js",
849851
"front_end/entrypoints/worker_app/WorkerMain.js",

front_end/entrypoints/rn_fusebox/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ import("../visibility.gni")
99

1010
devtools_module("rn_fusebox") {
1111
sources = [
12+
"FuseboxAppMetadataObserver.ts",
1213
"FuseboxReconnectDeviceButton.ts",
1314
"FuseboxProfilingBuildObserver.ts",
15+
"FuseboxWindowTitleManager.ts",
1416
]
1517

1618
deps = [
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) Meta Platforms, Inc. and affiliates.
2+
// Copyright 2024 The Chromium Authors. All rights reserved.
3+
// Use of this source code is governed by a BSD-style license that can be
4+
// found in the LICENSE file.
5+
6+
import * as Common from '../../core/common/common.js';
7+
import * as Protocol from '../../generated/protocol.js';
8+
import * as SDK from '../../core/sdk/sdk.js';
9+
import FuseboxWindowTitleManager from './FuseboxWindowTitleManager.js';
10+
11+
/**
12+
* Model observer which updates the DevTools window title based on the connected
13+
* React Native app metadata.
14+
*/
15+
export default class FuseboxAppMetadataObserver implements
16+
SDK.TargetManager.SDKModelObserver<SDK.ReactNativeApplicationModel.ReactNativeApplicationModel> {
17+
constructor(targetManager: SDK.TargetManager.TargetManager) {
18+
targetManager.observeModels(SDK.ReactNativeApplicationModel.ReactNativeApplicationModel, this);
19+
}
20+
21+
modelAdded(model: SDK.ReactNativeApplicationModel.ReactNativeApplicationModel): void {
22+
model.ensureEnabled();
23+
model.addEventListener(SDK.ReactNativeApplicationModel.Events.MetadataUpdated, this.#handleMetadataUpdated, this);
24+
}
25+
26+
modelRemoved(model: SDK.ReactNativeApplicationModel.ReactNativeApplicationModel): void {
27+
model.removeEventListener(
28+
SDK.ReactNativeApplicationModel.Events.MetadataUpdated, this.#handleMetadataUpdated, this);
29+
}
30+
31+
#handleMetadataUpdated(
32+
event: Common.EventTarget.EventTargetEvent<Protocol.ReactNativeApplication.MetadataUpdatedEvent>): void {
33+
const {appDisplayName, deviceName} = event.data;
34+
35+
// Update window title
36+
FuseboxWindowTitleManager.instance().setAppInfo(appDisplayName, deviceName);
37+
}
38+
}

front_end/entrypoints/rn_fusebox/FuseboxProfilingBuildObserver.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as Root from '../../core/root/root.js';
99
import * as SDK from '../../core/sdk/sdk.js';
1010
import * as UI from '../../ui/legacy/legacy.js';
1111
import * as i18n from '../../core/i18n/i18n.js';
12+
import FuseboxWindowTitleManager from './FuseboxWindowTitleManager.js';
1213

1314
const UIStrings = {
1415
/**
@@ -45,6 +46,7 @@ export default class FuseboxProfilingBuildObserver implements
4546
const {unstable_isProfilingBuild} = event.data;
4647

4748
if (unstable_isProfilingBuild) {
49+
FuseboxWindowTitleManager.instance().setSuffix('[PROFILING]');
4850
this.#hideUnsupportedFeatures();
4951
this.#ensurePerformancePanelEnabled();
5052
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright (c) Meta Platforms, Inc. and affiliates.
2+
// Copyright 2024 The Chromium Authors. All rights reserved.
3+
// Use of this source code is governed by a BSD-style license that can be
4+
// found in the LICENSE file.
5+
6+
export default class FuseboxWindowTitleManager {
7+
static #instance: FuseboxWindowTitleManager;
8+
#appDisplayName?: string;
9+
#deviceName?: string;
10+
#suffix?: string;
11+
12+
private constructor() {}
13+
14+
static instance(): FuseboxWindowTitleManager {
15+
if (!this.#instance) {
16+
this.#instance = new FuseboxWindowTitleManager();
17+
}
18+
return this.#instance;
19+
}
20+
21+
setAppInfo(appDisplayName: string | undefined, deviceName: string | undefined): void {
22+
this.#appDisplayName = appDisplayName;
23+
this.#deviceName = deviceName;
24+
this.#updateTitle();
25+
}
26+
27+
setSuffix(suffix: string): void {
28+
this.#suffix = suffix;
29+
this.#updateTitle();
30+
}
31+
32+
#updateTitle(): void {
33+
const parts: string[] = [];
34+
35+
if (this.#appDisplayName) {
36+
parts.push(this.#appDisplayName);
37+
}
38+
if (this.#deviceName) {
39+
parts.push(`(${this.#deviceName})`);
40+
}
41+
if (this.#suffix) {
42+
parts.push(this.#suffix);
43+
}
44+
parts.push('- React Native DevTools');
45+
46+
document.title = parts.join(' ');
47+
}
48+
}

front_end/entrypoints/rn_fusebox/rn_fusebox.ts

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ import * as RNExperiments from '../../core/rn_experiments/rn_experiments.js';
2323
import * as SDK from '../../core/sdk/sdk.js';
2424
import * as UI from '../../ui/legacy/legacy.js';
2525
import * as Main from '../main/main.js';
26-
import * as Common from '../../core/common/common.js';
27-
import * as Protocol from '../../generated/protocol.js';
26+
import FuseboxAppMetadataObserver from './FuseboxAppMetadataObserver.js';
2827
import FuseboxReconnectDeviceButton from './FuseboxReconnectDeviceButton.js';
2928
import FuseboxProfilingBuildObserver from './FuseboxProfilingBuildObserver.js';
3029

@@ -164,34 +163,7 @@ UI.Toolbar.registerToolbarItem({
164163
},
165164
});
166165

167-
class FuseboxReactNativeApplicationObserver implements
168-
SDK.TargetManager.SDKModelObserver<SDK.ReactNativeApplicationModel.ReactNativeApplicationModel> {
169-
constructor(targetManager: SDK.TargetManager.TargetManager) {
170-
targetManager.observeModels(SDK.ReactNativeApplicationModel.ReactNativeApplicationModel, this);
171-
}
172-
173-
modelAdded(model: SDK.ReactNativeApplicationModel.ReactNativeApplicationModel): void {
174-
model.ensureEnabled();
175-
model.addEventListener(SDK.ReactNativeApplicationModel.Events.MetadataUpdated, this.#handleMetadataUpdated, this);
176-
}
177-
178-
modelRemoved(model: SDK.ReactNativeApplicationModel.ReactNativeApplicationModel): void {
179-
model.removeEventListener(
180-
SDK.ReactNativeApplicationModel.Events.MetadataUpdated, this.#handleMetadataUpdated, this);
181-
}
182-
183-
#handleMetadataUpdated(
184-
event: Common.EventTarget.EventTargetEvent<Protocol.ReactNativeApplication.MetadataUpdatedEvent>): void {
185-
const {appDisplayName, deviceName} = event.data;
186-
187-
// Update window title
188-
if (appDisplayName !== null && appDisplayName !== undefined) {
189-
document.title = `${appDisplayName}${deviceName !== null && deviceName !== undefined ? ` (${deviceName})` : ''} - React Native DevTools`;
190-
}
191-
}
192-
}
193-
194-
new FuseboxReactNativeApplicationObserver(SDK.TargetManager.TargetManager.instance());
166+
new FuseboxAppMetadataObserver(SDK.TargetManager.TargetManager.instance());
195167
new FuseboxProfilingBuildObserver(SDK.TargetManager.TargetManager.instance());
196168

197169
Host.rnPerfMetrics.entryPointLoadingFinished('rn_fusebox');

0 commit comments

Comments
 (0)