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

Massage the JS interop around didCreateEngineInitializer #38147

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions lib/web_ui/lib/initialization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ Future<void> webOnlyWarmupEngine({

// Should the app "autoStart"?
bool autoStart = true;
if (engine.flutter != null && engine.loader != null) {
autoStart = engine.didCreateEngineInitializer == null;
if (engine.flutter != null && engine.flutter!.loader != null) {
autoStart = engine.flutter!.loader!.isAutostart;
}
if (autoStart) {
// The user does not want control of the app, bootstrap immediately.
Expand All @@ -91,7 +91,7 @@ Future<void> webOnlyWarmupEngine({
} else {
// Yield control of the bootstrap procedure to the user.
engine.domWindow.console.debug('Flutter Web Bootstrap: Programmatic.');
engine.didCreateEngineInitializer!(bootstrap.prepareEngineInitializer());
engine.flutter!.loader!.didCreateEngineInitializer(bootstrap.prepareEngineInitializer());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we refactor this to make the invariants a bit clearer and reduce the number of ! operators?

FlutterLoader? loader = engine.flutter?.loader;
if (loader == null || loader.isAutostart()) {
   ... autostart ...
} else {
  loader.didCreateEngineInitializer(...)
}

}
}

Expand Down
22 changes: 17 additions & 5 deletions lib/web_ui/lib/src/engine/js_interop/js_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
library js_loader;

import 'package:js/js.dart';
import 'package:js/js_util.dart' as js_util;

import '../configuration.dart';
import 'js_promise.dart';
Expand All @@ -15,16 +16,27 @@ import 'js_promise.dart';
/// programmer can control the initialization sequence.
typedef DidCreateEngineInitializerFn = void Function(FlutterEngineInitializer);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used for anything anymore?


@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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

autoStart? or rename the bool above to be autostart?

}

// FlutterEngineInitializer

Expand Down