Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 3aa3d2a

Browse files
Massage the JS interop around didCreateEngineInitializer (#38147)
* Massage the JS interop around `didCreateEngineInitializer` to make it work better with dart2wasm. * Make the whole type hierarchy more explicit. * Address Joshua's comments.
1 parent 799dc78 commit 3aa3d2a

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

lib/web_ui/lib/initialization.dart

+3-7
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,15 @@ Future<void> webOnlyWarmupEngine({
7979
},
8080
);
8181

82-
// Should the app "autoStart"?
83-
bool autoStart = true;
84-
if (engine.flutter != null && engine.loader != null) {
85-
autoStart = engine.didCreateEngineInitializer == null;
86-
}
87-
if (autoStart) {
82+
final engine.FlutterLoader? loader = engine.flutter?.loader;
83+
if (loader == null || loader.isAutoStart) {
8884
// The user does not want control of the app, bootstrap immediately.
8985
engine.domWindow.console.debug('Flutter Web Bootstrap: Auto.');
9086
await bootstrap.autoStart();
9187
} else {
9288
// Yield control of the bootstrap procedure to the user.
9389
engine.domWindow.console.debug('Flutter Web Bootstrap: Programmatic.');
94-
engine.didCreateEngineInitializer!(bootstrap.prepareEngineInitializer());
90+
loader.didCreateEngineInitializer(bootstrap.prepareEngineInitializer());
9591
}
9692
}
9793

lib/web_ui/lib/src/engine/js_interop/js_loader.dart

+16-9
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,32 @@
66
library js_loader;
77

88
import 'package:js/js.dart';
9+
import 'package:js/js_util.dart' as js_util;
910

1011
import '../configuration.dart';
1112
import 'js_promise.dart';
1213

13-
/// Typedef for the function that notifies JS that the main entrypoint is up and running.
14-
/// As a parameter, a [FlutterEngineInitializer] instance is passed to JS, so the
15-
/// programmer can control the initialization sequence.
16-
typedef DidCreateEngineInitializerFn = void Function(FlutterEngineInitializer);
14+
@JS()
15+
@staticInterop
16+
class FlutterJS {}
17+
18+
extension FlutterJSExtension on FlutterJS {
19+
external FlutterLoader? get loader;
20+
}
1721

1822
// Both `flutter`, `loader`(_flutter.loader), must be checked for null before
1923
// `didCreateEngineInitializer` can be safely accessed.
2024
@JS('_flutter')
21-
external Object? get flutter;
25+
external FlutterJS? get flutter;
2226

23-
@JS('_flutter.loader')
24-
external Object? get loader;
27+
@JS()
28+
@staticInterop
29+
class FlutterLoader {}
2530

26-
@JS('_flutter.loader.didCreateEngineInitializer')
27-
external DidCreateEngineInitializerFn? get didCreateEngineInitializer;
31+
extension FlutterLoaderExtension on FlutterLoader {
32+
external void didCreateEngineInitializer(FlutterEngineInitializer initializer);
33+
bool get isAutoStart => !js_util.hasProperty(this, 'didCreateEngineInitializer');
34+
}
2835

2936
// FlutterEngineInitializer
3037

0 commit comments

Comments
 (0)