Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class SettingsDialog extends StatelessWidget {
...dialogSubHeader(theme, 'Experimental features'),
Flexible(
child: CheckboxSetting(
title: 'Enable WebAssembly',
title: '[Recommended] Enable WebAssembly',
description:
'This will trigger a reload of the page to load DevTools '
'compiled with WebAssembly. This may yield better '
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,39 +545,6 @@ class WelcomeToNewInspectorMessage extends BannerInfo {
);
}

class WasmWelcomeMessage extends BannerInfo {
WasmWelcomeMessage()
: super(
key: const Key('WasmWelcomeMessage'),
screenId: universalScreenId,
dismissOnConnectionChanges: true,
buildTextSpans: (context) => [
const TextSpan(
text:
'🚀 A faster and more performant DevTools is now available on WebAssembly! Click ',
),
const TextSpan(
text: 'Enable',
style: TextStyle(fontWeight: FontWeight.bold),
),
const TextSpan(text: ' to try it out now.'),
const TextSpan(
text: ' Please note that this will trigger a reload of DevTools.',
style: TextStyle(fontStyle: FontStyle.italic),
),
],
buildActions: (context) => [
DevToolsButton(
label: 'Enable',
onPressed: () async {
await preferences.enableWasmInStorage();
webReload();
},
),
],
);
}

void maybePushDebugModePerformanceMessage(String screenId) {
if (offlineDataController.showingOfflineData.value) return;
if (serviceConnection.serviceManager.connectedApp?.isDebugFlutterAppNow ??
Expand Down Expand Up @@ -610,10 +577,6 @@ void pushWelcomeToNewInspectorMessage(String screenId) {
bannerMessages.addMessage(WelcomeToNewInspectorMessage(screenId: screenId));
}

void pushWasmWelcomeMessage() {
bannerMessages.addMessage(WasmWelcomeMessage());
}

extension BannerMessageThemeExtension on ThemeData {
TextStyle get warningMessageLinkStyle => regularTextStyle.copyWith(
decoration: TextDecoration.underline,
Expand Down
48 changes: 11 additions & 37 deletions packages/devtools_app/lib/src/shared/preferences/preferences.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import '../constants.dart';
import '../diagnostics/inspector_service.dart';
import '../feature_flags.dart';
import '../globals.dart';
import '../managers/banner_messages.dart';
import '../primitives/query_parameters.dart';
import '../server/server.dart';
import '../utils/utils.dart';
Expand All @@ -38,7 +37,11 @@ const _thirdPartyPathSegment = 'third_party';

/// DevTools preferences for experimental features.
enum _ExperimentPreferences {
wasm;
/// Deprecated, we ignore this key in favor of [wasmOptOut].
wasm,

/// Whether a user has opted out of the dart2wasm experiment.
wasmOptOut;

String get storageKey => '$storagePrefix.$name';

Expand Down Expand Up @@ -66,8 +69,6 @@ enum _GeneralPreferences { verboseLogging }
/// A controller for global application preferences.
class PreferencesController extends DisposableController
with AutoDisposeControllerMixin {
static const _welcomeShownStorageId = 'wasmWelcomeShown';

/// Whether the user preference for DevTools theme is set to dark mode.
///
/// To check whether DevTools is using a light or dark theme, other parts of
Expand Down Expand Up @@ -191,25 +192,13 @@ class PreferencesController extends DisposableController
);
}

// Maybe show the WASM welcome message on app connection if this is the
// first time the user is loading DevTools after the WASM experiment was
// enabled.
addAutoDisposeListener(
serviceConnection.serviceManager.connectedState,
() async {
if (serviceConnection.serviceManager.connectedState.value.connected) {
await _maybeShowWasmWelcomeMessage();
}
},
);

addAutoDisposeListener(wasmEnabled, () async {
final enabled = wasmEnabled.value;
_log.fine('preference update (wasmEnabled = $enabled)');

await storage.setValue(
_ExperimentPreferences.wasm.storageKey,
'$enabled',
_ExperimentPreferences.wasmOptOut.storageKey,
'${!enabled}',
);

// Update the wasm mode query parameter if it does not match the value of
Expand All @@ -227,10 +216,12 @@ class PreferencesController extends DisposableController
}
});

final enabledFromStorage = await boolValueFromStorage(
_ExperimentPreferences.wasm.storageKey,
final optOutFromStorage = await boolValueFromStorage(
_ExperimentPreferences.wasmOptOut.storageKey,
defaultsTo: false,
);
final enabledFromStorage = !optOutFromStorage;

final queryParams = DevToolsQueryParams.load();
final enabledFromQueryParams = queryParams.useWasm;

Expand Down Expand Up @@ -269,23 +260,6 @@ class PreferencesController extends DisposableController
toggleWasmEnabled(shouldEnableWasm);
}

Future<void> _maybeShowWasmWelcomeMessage() async {
// If we have already shown the welcome message, don't show it again.
final welcomeAlreadyShown = await storage.getValue(_welcomeShownStorageId);
if (welcomeAlreadyShown == 'true') return;

// Show the welcome message if the WASM experiment is enabled but the user
// is not using the WASM build.
final connectedApp = serviceConnection.serviceManager.connectedApp;
if (connectedApp != null &&
FeatureFlags.wasmByDefault.isEnabled(connectedApp) &&
!kIsWasm) {
// Mark the welcome message as shown.
await storage.setValue(_welcomeShownStorageId, 'true');
pushWasmWelcomeMessage();
}
}

Future<void> _initVerboseLogging() async {
final verboseLoggingEnabledValue = await boolValueFromStorage(
_GeneralPreferences.verboseLogging.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ To learn more about DevTools, check out the

## General updates

TODO: Remove this section if there are not any general updates.
- Switched default compiler for DevTools to `dart2wasm`. - [#9530](https://github.com/flutter/devtools/pull/9530)

## Inspector updates

Expand Down
23 changes: 16 additions & 7 deletions packages/devtools_app/web/flutter_bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ function getSearchParam(searchParamKey) {
}

// Calls the DevTools server API to read the user's wasm preference.
async function getDevToolsWasmPreference() {
async function getDevToolsWasmOptOutPreference() {
// Note: when the DevTools server is running on a different port than the
// DevTools web app, this request path will be incorrect and the request
// will fail. This is okay because DevTools cannot be built with WASM when
// running from `flutter run` anyway.
const request = 'api/getPreferenceValue?key=experiment.wasm';
const request = 'api/getPreferenceValue?key=experiment.wasmOptOut';
try {
const response = await fetch(request);
if (!response.ok) {
Expand All @@ -47,10 +47,10 @@ async function getDevToolsWasmPreference() {
}

// The response text should be an encoded boolean value ("true" or "false").
const wasmEnabled = JSON.parse(await response.text());
return wasmEnabled === true || wasmEnabled === 'true';
const isOptedOut = JSON.parse(await response.text());
return isOptedOut === true || isOptedOut === 'true';
} catch (error) {
console.error('Error fetching experiment.wasm preference value:', error);
console.error('Error fetching experiment.wasmOptOut preference value:', error);
return false;
}
}
Expand All @@ -68,9 +68,18 @@ async function shouldUseSkwasm() {
if (forceUseJs()) {
return false;
}

const wasmEnabledFromQueryParameter = getSearchParam(compilerQueryParameterKey) === 'wasm';
const wasmEnabledFromDevToolsPreference = await getDevToolsWasmPreference();
return wasmEnabledFromQueryParameter === true || wasmEnabledFromDevToolsPreference === true;
if (wasmEnabledFromQueryParameter) {
return true;
}

const userHasOptedOut = await getDevToolsWasmOptOutPreference();
if (userHasOptedOut) {
return false;
}

return true;
}

// Sets or removes the 'wasm' query parameter based on whether DevTools should
Expand Down