Skip to content

Commit 0327830

Browse files
authored
Enable WASM experiment for Flutter beta branches (#9455)
1 parent 0400022 commit 0327830

File tree

5 files changed

+96
-1
lines changed

5 files changed

+96
-1
lines changed

packages/devtools_app/lib/src/shared/feature_flags.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,16 @@ extension FeatureFlags on Never {
110110
enabled: true,
111111
);
112112

113+
/// Flag to enable refactors in the Flutter Property Editor sidebar.
114+
///
115+
/// https://github.com/flutter/devtools/issues/9214
116+
static const wasmByDefault = FlutterChannelFeatureFlag(
117+
name: 'wasmByDefault',
118+
flutterChannel: FlutterChannel.beta,
119+
enabledForDartApps: false,
120+
enabledForFlutterAppsFallback: false,
121+
);
122+
113123
/// A set of all the boolean feature flags for debugging purposes.
114124
///
115125
/// When adding a new boolean flag, you are responsible for adding it to this
@@ -130,7 +140,7 @@ extension FeatureFlags on Never {
130140
/// When adding a new Flutter channel flag, you are responsible for adding it
131141
/// to this map as well.
132142
static final _flutterChannelFlags = <FlutterChannelFeatureFlag>{
133-
// TODO(https://github.com/flutter/devtools/issues/9438): Add wasm flag.
143+
wasmByDefault,
134144
};
135145

136146
/// A helper to print the status of all the feature flags.

packages/devtools_app/lib/src/shared/managers/banner_messages.dart

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,39 @@ class WelcomeToNewInspectorMessage extends BannerInfo {
545545
);
546546
}
547547

548+
class WasmWelcomeMessage extends BannerInfo {
549+
WasmWelcomeMessage()
550+
: super(
551+
key: const Key('WasmWelcomeMessage'),
552+
screenId: universalScreenId,
553+
dismissOnConnectionChanges: true,
554+
buildTextSpans: (context) => [
555+
const TextSpan(
556+
text:
557+
'🚀 A faster and more performant DevTools is now available on WebAssembly! Click ',
558+
),
559+
const TextSpan(
560+
text: 'Enable',
561+
style: TextStyle(fontWeight: FontWeight.bold),
562+
),
563+
const TextSpan(text: ' to try it out now.'),
564+
const TextSpan(
565+
text: ' Please note that this will trigger a reload of DevTools.',
566+
style: TextStyle(fontStyle: FontStyle.italic),
567+
),
568+
],
569+
buildActions: (context) => [
570+
DevToolsButton(
571+
label: 'Enable',
572+
onPressed: () async {
573+
await preferences.enableWasmInStorage();
574+
webReload();
575+
},
576+
),
577+
],
578+
);
579+
}
580+
548581
void maybePushDebugModePerformanceMessage(String screenId) {
549582
if (offlineDataController.showingOfflineData.value) return;
550583
if (serviceConnection.serviceManager.connectedApp?.isDebugFlutterAppNow ??
@@ -577,6 +610,10 @@ void pushWelcomeToNewInspectorMessage(String screenId) {
577610
bannerMessages.addMessage(WelcomeToNewInspectorMessage(screenId: screenId));
578611
}
579612

613+
void pushWasmWelcomeMessage() {
614+
bannerMessages.addMessage(WasmWelcomeMessage());
615+
}
616+
580617
extension BannerMessageThemeExtension on ThemeData {
581618
TextStyle get warningMessageLinkStyle => regularTextStyle.copyWith(
582619
decoration: TextDecoration.underline,

packages/devtools_app/lib/src/shared/preferences/preferences.dart

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import '../constants.dart';
1919
import '../diagnostics/inspector_service.dart';
2020
import '../feature_flags.dart';
2121
import '../globals.dart';
22+
import '../managers/banner_messages.dart';
2223
import '../primitives/query_parameters.dart';
2324
import '../server/server.dart';
2425
import '../utils/utils.dart';
@@ -65,6 +66,8 @@ enum _GeneralPreferences { verboseLogging }
6566
/// A controller for global application preferences.
6667
class PreferencesController extends DisposableController
6768
with AutoDisposeControllerMixin {
69+
static const _welcomeShownStorageId = 'wasmWelcomeShown';
70+
6871
/// Whether the user preference for DevTools theme is set to dark mode.
6972
///
7073
/// To check whether DevTools is using a light or dark theme, other parts of
@@ -134,6 +137,13 @@ class PreferencesController extends DisposableController
134137
setGlobal(PreferencesController, this);
135138
}
136139

140+
/// Enables the wasm experiment in storage.
141+
///
142+
/// This is used to persist the preference across reloads.
143+
Future<void> enableWasmInStorage() async {
144+
await storage.setValue(_ExperimentPreferences.wasm.storageKey, 'true');
145+
}
146+
137147
Future<void> _initDarkMode() async {
138148
final darkModeValue = await storage.getValue(
139149
_UiPreferences.darkMode.storageKey,
@@ -181,6 +191,18 @@ class PreferencesController extends DisposableController
181191
);
182192
}
183193

194+
// Maybe show the WASM welcome message on app connection if this is the
195+
// first time the user is loading DevTools after the WASM experiment was
196+
// enabled.
197+
addAutoDisposeListener(
198+
serviceConnection.serviceManager.connectedState,
199+
() async {
200+
if (serviceConnection.serviceManager.connectedState.value.connected) {
201+
await _maybeShowWasmWelcomeMessage();
202+
}
203+
},
204+
);
205+
184206
addAutoDisposeListener(wasmEnabled, () async {
185207
final enabled = wasmEnabled.value;
186208
_log.fine('preference update (wasmEnabled = $enabled)');
@@ -247,6 +269,23 @@ class PreferencesController extends DisposableController
247269
toggleWasmEnabled(shouldEnableWasm);
248270
}
249271

272+
Future<void> _maybeShowWasmWelcomeMessage() async {
273+
// If we have already shown the welcome message, don't show it again.
274+
final welcomeAlreadyShown = await storage.getValue(_welcomeShownStorageId);
275+
if (welcomeAlreadyShown == 'true') return;
276+
277+
// Show the welcome message if the WASM experiment is enabled but the user
278+
// is not using the WASM build.
279+
final connectedApp = serviceConnection.serviceManager.connectedApp;
280+
if (connectedApp != null &&
281+
FeatureFlags.wasmByDefault.isEnabled(connectedApp) &&
282+
!kIsWasm) {
283+
// Mark the welcome message as shown.
284+
await storage.setValue(_welcomeShownStorageId, 'true');
285+
pushWasmWelcomeMessage();
286+
}
287+
}
288+
250289
Future<void> _initVerboseLogging() async {
251290
final verboseLoggingEnabledValue = await boolValueFromStorage(
252291
_GeneralPreferences.verboseLogging.name,

packages/devtools_app_shared/lib/src/utils/url/_url_stub.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ String? getWebUrl() => null;
1717
// Unused parameter lint doesn't make sense for stub files.
1818
void webRedirect(String url) {}
1919

20+
/// Performs a web reload using window.location.reload().
21+
///
22+
/// No-op for non-web platforms.
23+
void webReload() {}
24+
2025
/// Updates the query parameter with [key] to the new [value], and optionally
2126
/// reloads the page when [reload] is true.
2227
///

packages/devtools_app_shared/lib/src/utils/url/_url_web.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ void webRedirect(String url) {
1616
window.location.replace(url);
1717
}
1818

19+
void webReload() {
20+
window.location.reload();
21+
}
22+
1923
void updateQueryParameter(String key, String? value, {bool reload = false}) {
2024
final newQueryParams = Map.of(loadQueryParams());
2125
if (value == null) {

0 commit comments

Comments
 (0)