Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only prompt preserve-log settings for Fusebox targets #128

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions front_end/entrypoints/rn_fusebox/rn_fusebox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import * as Root from '../../core/root/root.js';
import * as SDK from '../../core/sdk/sdk.js';
import * as UI from '../../ui/legacy/legacy.js';
import * as Main from '../main/main.js';
import * as Common from '../../core/common/common.js';
import * as Protocol from '../../generated/protocol.js';

import type * as Common from '../../core/common/common.js';
import type * as Platform from '../../core/platform/platform.js';
import type * as Protocol from '../../generated/protocol.js';
import type * as Sources from '../../panels/sources/sources.js';
import * as RNExperiments from '../../core/rn_experiments/rn_experiments.js';

Expand Down Expand Up @@ -195,18 +195,39 @@ class ConnectionStatusToolbarItemProvider extends SDK.TargetManager.Observer imp
SDK.TargetManager.TargetManager.instance().observeTargets(this, {scoped: true});
}

override targetAdded(_target: SDK.Target.Target): void {
this.#updateRootTarget();
override targetAdded(target: SDK.Target.Target): void {
this.#onTargetChanged(target);
}
override targetRemoved(_target: SDK.Target.Target): void {
this.#updateRootTarget();

override targetRemoved(target: SDK.Target.Target): void {
this.#onTargetChanged(target);
}

#updateRootTarget(): void {
#onTargetChanged(target: SDK.Target.Target): void {
const rootTarget = SDK.TargetManager.TargetManager.instance().rootTarget();
this.#button.setTitle(i18nLazyString(UIStrings.connectionStatusDisconnectedTooltip)());
this.#button.setText(i18nLazyString(UIStrings.connectionStatusDisconnectedLabel)());
this.#button.setVisible(!rootTarget);

if (!rootTarget) {
this.#printPreserveLogPrompt(target);
}
}

#printPreserveLogPrompt(target: SDK.Target.Target): void {
if (Common.Settings.Settings.instance().moduleSetting('preserve-console-log').get()) {
return;
}

target.model(SDK.ConsoleModel.ConsoleModel)
?.addMessage(new SDK.ConsoleModel.ConsoleMessage(
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',
}));
}

onClick(): void {
Expand Down
8 changes: 0 additions & 8 deletions front_end/panels/console/ConsoleView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -628,14 +628,6 @@ 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',
}));
}
}

Expand Down
Loading