forked from ChromeDevTools/devtools-frontend
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathFuseboxExperimentsObserver.ts
More file actions
102 lines (87 loc) · 4.12 KB
/
Copy pathFuseboxExperimentsObserver.ts
File metadata and controls
102 lines (87 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// 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 type * as Common from '../../core/common/common.js';
import * as i18n from '../../core/i18n/i18n.js';
import * as Root from '../../core/root/root.js';
import * as SDK from '../../core/sdk/sdk.js';
import type * as Protocol from '../../generated/protocol.js';
import * as UI from '../../ui/legacy/legacy.js';
import {FuseboxWindowTitleManager} from './FuseboxWindowTitleManager.js';
const UIStrings = {
/**
* @description Message for the "settings changed" banner shown when a reload is required for the Network panel.
*/
reloadRequiredForNetworkPanelMessage: 'The Network panel is now available for dogfooding. Please reload to access it.',
} as const;
const str_ = i18n.i18n.registerUIStrings('entrypoints/rn_fusebox/FuseboxExperimentsObserver.ts', UIStrings);
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
/**
* [Experimental] Model observer which configures available DevTools features
* based on the target's capabilities, e.g. when a profiling build is identified, or when network inspection is supported.
*/
export class FuseboxFeatureObserver 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.METADATA_UPDATED, this.#handleMetadataUpdated, this);
}
modelRemoved(model: SDK.ReactNativeApplicationModel.ReactNativeApplicationModel): void {
model.removeEventListener(
SDK.ReactNativeApplicationModel.Events.METADATA_UPDATED, this.#handleMetadataUpdated, this);
}
#handleMetadataUpdated(
event: Common.EventTarget.EventTargetEvent<Protocol.ReactNativeApplication.MetadataUpdatedEvent>): void {
// eslint-disable-next-line @typescript-eslint/naming-convention
const {unstable_isProfilingBuild, unstable_networkInspectionEnabled} = event.data;
if (unstable_isProfilingBuild) {
FuseboxWindowTitleManager.instance().setSuffix('[PROFILING]');
this.#hideUnsupportedFeaturesForProfilingBuilds();
}
if (unstable_networkInspectionEnabled) {
this.#ensureNetworkPanelEnabled();
}
}
#hideUnsupportedFeaturesForProfilingBuilds(): void {
UI.InspectorView.InspectorView.instance().closeDrawer();
const viewManager = UI.ViewManager.ViewManager.instance();
const panelLocationPromise = viewManager.resolveLocation(UI.ViewManager.ViewLocationValues.PANEL);
const drawerLocationPromise = viewManager.resolveLocation(UI.ViewManager.ViewLocationValues.DRAWER_VIEW);
void Promise.all([panelLocationPromise, drawerLocationPromise])
.then(([panelLocation, drawerLocation]) => {
UI.ViewManager.getRegisteredViewExtensions().forEach(view => {
if (view.location() === UI.ViewManager.ViewLocationValues.DRAWER_VIEW) {
drawerLocation?.removeView(view);
} else {
switch (view.viewId()) {
case 'console':
case 'heap-profiler':
case 'live-heap-profile':
case 'sources':
case 'network':
case 'react-devtools-components':
case 'react-devtools-profiler':
panelLocation?.removeView(view);
break;
}
}
});
});
}
#ensureNetworkPanelEnabled(): void {
if (Root.Runtime.experiments.isEnabled(Root.Runtime.ExperimentName.ENABLE_NETWORK_PANEL)) {
return;
}
Root.Runtime.experiments.setEnabled(
Root.Runtime.ExperimentName.ENABLE_NETWORK_PANEL,
true,
);
UI.InspectorView?.InspectorView?.instance()?.displayReloadRequiredWarning(
i18nString(UIStrings.reloadRequiredForNetworkPanelMessage),
);
}
}