forked from ChromeDevTools/devtools-frontend
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update window title for profiling builds (#141)
- Loading branch information
Showing
6 changed files
with
94 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
front_end/entrypoints/rn_fusebox/FuseboxAppMetadataObserver.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) Meta Platforms, Inc. and affiliates. | ||
// Copyright 2024 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import * as Common from '../../core/common/common.js'; | ||
import * as Protocol from '../../generated/protocol.js'; | ||
import * as SDK from '../../core/sdk/sdk.js'; | ||
import FuseboxWindowTitleManager from './FuseboxWindowTitleManager.js'; | ||
|
||
/** | ||
* Model observer which updates the DevTools window title based on the connected | ||
* React Native app metadata. | ||
*/ | ||
export default class FuseboxAppMetadataObserver implements | ||
SDK.TargetManager.SDKModelObserver<SDK.ReactNativeApplicationModel.ReactNativeApplicationModel> { | ||
constructor(targetManager: SDK.TargetManager.TargetManager) { | ||
targetManager.observeModels(SDK.ReactNativeApplicationModel.ReactNativeApplicationModel, this); | ||
} | ||
|
||
modelAdded(model: SDK.ReactNativeApplicationModel.ReactNativeApplicationModel): void { | ||
model.ensureEnabled(); | ||
model.addEventListener(SDK.ReactNativeApplicationModel.Events.MetadataUpdated, this.#handleMetadataUpdated, this); | ||
} | ||
|
||
modelRemoved(model: SDK.ReactNativeApplicationModel.ReactNativeApplicationModel): void { | ||
model.removeEventListener( | ||
SDK.ReactNativeApplicationModel.Events.MetadataUpdated, this.#handleMetadataUpdated, this); | ||
} | ||
|
||
#handleMetadataUpdated( | ||
event: Common.EventTarget.EventTargetEvent<Protocol.ReactNativeApplication.MetadataUpdatedEvent>): void { | ||
const {appDisplayName, deviceName} = event.data; | ||
|
||
// Update window title | ||
FuseboxWindowTitleManager.instance().setAppInfo(appDisplayName, deviceName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
front_end/entrypoints/rn_fusebox/FuseboxWindowTitleManager.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright (c) Meta Platforms, Inc. and affiliates. | ||
// Copyright 2024 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
export default class FuseboxWindowTitleManager { | ||
static #instance: FuseboxWindowTitleManager; | ||
#appDisplayName?: string; | ||
#deviceName?: string; | ||
#suffix?: string; | ||
|
||
private constructor() {} | ||
|
||
static instance(): FuseboxWindowTitleManager { | ||
if (!this.#instance) { | ||
this.#instance = new FuseboxWindowTitleManager(); | ||
} | ||
return this.#instance; | ||
} | ||
|
||
setAppInfo(appDisplayName: string | undefined, deviceName: string | undefined): void { | ||
this.#appDisplayName = appDisplayName; | ||
this.#deviceName = deviceName; | ||
this.#updateTitle(); | ||
} | ||
|
||
setSuffix(suffix: string): void { | ||
this.#suffix = suffix; | ||
this.#updateTitle(); | ||
} | ||
|
||
#updateTitle(): void { | ||
const parts: string[] = []; | ||
|
||
if (this.#appDisplayName) { | ||
parts.push(this.#appDisplayName); | ||
} | ||
if (this.#deviceName) { | ||
parts.push(`(${this.#deviceName})`); | ||
} | ||
if (this.#suffix) { | ||
parts.push(this.#suffix); | ||
} | ||
parts.push('- React Native DevTools'); | ||
|
||
document.title = parts.join(' '); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters