Skip to content

Commit

Permalink
Only prompt preserve-log settings for Fusebox targets
Browse files Browse the repository at this point in the history
  • Loading branch information
EdmondChuiHW committed Oct 15, 2024
1 parent 6f29504 commit 4161fa2
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 38 deletions.
1 change: 1 addition & 0 deletions front_end/core/sdk/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ devtools_module("sdk") {
"EventBreakpointsModel.ts",
"FrameAssociated.ts",
"FrameManager.ts",
"FuseboxClientMetadataModel.ts",
"HeapProfilerModel.ts",
"HttpReasonPhraseStrings.ts",
"IOModel.ts",
Expand Down
27 changes: 27 additions & 0 deletions front_end/core/sdk/FuseboxClientMetadataModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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 Host from '../host/host.js';

import {SDKModel} from './SDKModel.js';
import {type Target} from './Target.js';

export class FuseboxClientMetadataModel extends SDKModel<void> {
constructor(target: Target) {
super(target);
Host.rnPerfMetrics.fuseboxSetClientMetadataStarted();
target.fuseboxClientAgent()
.invoke_setClientMetadata()
.then(result => {
const maybeError = result.getError();
const success = !maybeError;
Host.rnPerfMetrics.fuseboxSetClientMetadataFinished(success, maybeError);
})
.catch(reason => {
const success = false;
Host.rnPerfMetrics.fuseboxSetClientMetadataFinished(success, reason);
});
}
}
2 changes: 2 additions & 0 deletions front_end/core/sdk/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import * as EmulationModel from './EmulationModel.js';
import * as EventBreakpointsModel from './EventBreakpointsModel.js';
import * as FrameAssociated from './FrameAssociated.js';
import * as FrameManager from './FrameManager.js';
import * as FuseboxClientMetadataModel from './FuseboxClientMetadataModel.js';
import * as HeapProfilerModel from './HeapProfilerModel.js';
import * as IOModel from './IOModel.js';
import * as IsolateManager from './IsolateManager.js';
Expand Down Expand Up @@ -120,6 +121,7 @@ export {
EventBreakpointsModel,
FrameAssociated,
FrameManager,
FuseboxClientMetadataModel,
HeapProfilerModel,
IOModel,
IsolateManager,
Expand Down
42 changes: 12 additions & 30 deletions front_end/entrypoints/rn_fusebox/rn_fusebox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,37 +91,19 @@ document.addEventListener('visibilitychange', () => {
Host.rnPerfMetrics.browserVisibilityChanged(document.visibilityState);
});

class FuseboxClientMetadataModel extends SDK.SDKModel.SDKModel<void> {
constructor(target: SDK.Target.Target) {
super(target);
Host.rnPerfMetrics.fuseboxSetClientMetadataStarted();
target.fuseboxClientAgent()
.invoke_setClientMetadata()
.then(result => {
const maybeError = result.getError();
const success = !maybeError;
Host.rnPerfMetrics.fuseboxSetClientMetadataFinished(success, maybeError);
})
.catch(reason => {
const success = false;
Host.rnPerfMetrics.fuseboxSetClientMetadataFinished(success, reason);
});
}
}

SDK.SDKModel.SDKModel.register(
FuseboxClientMetadataModel,
{
capabilities: SDK.Target.Capability.None,
autostart: true,
// Ensure FuseboxClient.setClientMetadata is sent before most other CDP domains
// are initialised. This allows the backend to confidently detect non-Fusebox
// clients by the fact that they send e.g. Runtime.enable without sending any
// Fusebox-specific messages first.
// TODO: Explicitly depend on this model in RuntimeModel and LogModel, and
// remove the `early` and `autostart` flags.
early: true,
},
SDK.FuseboxClientMetadataModel.FuseboxClientMetadataModel,
{
capabilities: SDK.Target.Capability.None,
autostart: true,
// Ensure FuseboxClient.setClientMetadata is sent before most other CDP domains
// are initialised. This allows the backend to confidently detect non-Fusebox
// clients by the fact that they send e.g. Runtime.enable without sending any
// Fusebox-specific messages first.
// TODO: Explicitly depend on this model in RuntimeModel and LogModel, and
// remove the `early` and `autostart` flags.
early: true,
},
);

let loadedSourcesModule: (typeof Sources|undefined);
Expand Down
18 changes: 10 additions & 8 deletions front_end/panels/console/ConsoleView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -628,14 +628,16 @@ export class ConsoleView extends UI.Widget.VBox implements
if (!Common.Settings.Settings.instance().moduleSetting('preserve-console-log').get() &&
model.target().outermostTarget() === model.target()) {
this.consoleCleared();
this.addConsoleMessage(new SDK.ConsoleModel.ConsoleMessage(
model.target().model(SDK.RuntimeModel.RuntimeModel), Protocol.Log.LogEntrySource.Recommendation,
Protocol.Log.LogEntryLevel.Info,
'[React Native] Console messages are currently cleared upon DevTools disconnection. You can preserve logs in settings: ',
{
type: SDK.ConsoleModel.FrontendMessageType.System,
context: 'fusebox_preserve_log_rec',
}));
if (model.target().model(SDK.FuseboxClientMetadataModel.FuseboxClientMetadataModel)) {
this.addConsoleMessage(new SDK.ConsoleModel.ConsoleMessage(
model.target().model(SDK.RuntimeModel.RuntimeModel), Protocol.Log.LogEntrySource.Recommendation,
Protocol.Log.LogEntryLevel.Info,
'[React Native] Console messages are currently cleared upon DevTools disconnection. You can preserve logs in settings: ',
{
type: SDK.ConsoleModel.FrontendMessageType.System,
context: 'fusebox_preserve_log_rec',
}));
}
}
}

Expand Down
1 change: 1 addition & 0 deletions scripts/eslint_rules/lib/check_license_header.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const EXCLUDED_FILES = [
const META_CODE_PATHS = [
'core/host/RNPerfMetrics.ts',
'core/rn_experiments',
'core/sdk/FuseboxClientMetadataModel.ts',
'core/sdk/ReactNativeApplicationModel.ts',
'entrypoints/rn_fusebox',
'entrypoints/rn_inspector',
Expand Down

0 comments on commit 4161fa2

Please sign in to comment.