mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Massage the JS interop around didCreateEngineInitializer (flutter/engine#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.
This commit is contained in:
parent
de39291cb7
commit
4b6f0c837b
@ -79,19 +79,15 @@ Future<void> webOnlyWarmupEngine({
|
||||
},
|
||||
);
|
||||
|
||||
// Should the app "autoStart"?
|
||||
bool autoStart = true;
|
||||
if (engine.flutter != null && engine.loader != null) {
|
||||
autoStart = engine.didCreateEngineInitializer == null;
|
||||
}
|
||||
if (autoStart) {
|
||||
final engine.FlutterLoader? loader = engine.flutter?.loader;
|
||||
if (loader == null || loader.isAutoStart) {
|
||||
// The user does not want control of the app, bootstrap immediately.
|
||||
engine.domWindow.console.debug('Flutter Web Bootstrap: Auto.');
|
||||
await bootstrap.autoStart();
|
||||
} else {
|
||||
// Yield control of the bootstrap procedure to the user.
|
||||
engine.domWindow.console.debug('Flutter Web Bootstrap: Programmatic.');
|
||||
engine.didCreateEngineInitializer!(bootstrap.prepareEngineInitializer());
|
||||
loader.didCreateEngineInitializer(bootstrap.prepareEngineInitializer());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -6,25 +6,32 @@
|
||||
library js_loader;
|
||||
|
||||
import 'package:js/js.dart';
|
||||
import 'package:js/js_util.dart' as js_util;
|
||||
|
||||
import '../configuration.dart';
|
||||
import 'js_promise.dart';
|
||||
|
||||
/// Typedef for the function that notifies JS that the main entrypoint is up and running.
|
||||
/// As a parameter, a [FlutterEngineInitializer] instance is passed to JS, so the
|
||||
/// programmer can control the initialization sequence.
|
||||
typedef DidCreateEngineInitializerFn = void Function(FlutterEngineInitializer);
|
||||
@JS()
|
||||
@staticInterop
|
||||
class FlutterJS {}
|
||||
|
||||
extension FlutterJSExtension on FlutterJS {
|
||||
external FlutterLoader? get loader;
|
||||
}
|
||||
|
||||
// Both `flutter`, `loader`(_flutter.loader), must be checked for null before
|
||||
// `didCreateEngineInitializer` can be safely accessed.
|
||||
@JS('_flutter')
|
||||
external Object? get flutter;
|
||||
external FlutterJS? get flutter;
|
||||
|
||||
@JS('_flutter.loader')
|
||||
external Object? get loader;
|
||||
@JS()
|
||||
@staticInterop
|
||||
class FlutterLoader {}
|
||||
|
||||
@JS('_flutter.loader.didCreateEngineInitializer')
|
||||
external DidCreateEngineInitializerFn? get didCreateEngineInitializer;
|
||||
extension FlutterLoaderExtension on FlutterLoader {
|
||||
external void didCreateEngineInitializer(FlutterEngineInitializer initializer);
|
||||
bool get isAutoStart => !js_util.hasProperty(this, 'didCreateEngineInitializer');
|
||||
}
|
||||
|
||||
// FlutterEngineInitializer
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user