-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[web] Move web-only initialization APIs to dart:ui_web
#43111
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0dd7dae
[web] Move web-only initialization APIs to `dart:ui_web`
mdebbar 8b8dd3d
bootstrapEngine
mdebbar d0e6712
remove ui_web.initializePlatform
mdebbar f7136ef
Merge branch 'main' into web_only_init
mdebbar 63b1b7c
remove duplicate typedef
mdebbar 9d1707d
typo
mdebbar 815f01b
Merge branch 'main' into web_only_init
mdebbar 155af4d
licenses
mdebbar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'package:ui/src/engine.dart'; | ||
import 'package:ui/ui.dart' as ui; | ||
|
||
/// Bootstraps the Flutter Web engine and app. | ||
/// | ||
/// If the app uses plugins, then the [registerPlugins] callback can be provided | ||
/// to register those plugins. This is done typically by calling | ||
/// `registerPlugins` from the auto-generated `web_plugin_registrant.dart` file. | ||
/// | ||
/// The [runApp] callback is invoked to run the app after the engine is fully | ||
/// initialized. | ||
/// | ||
/// For more information, see what the `flutter_tools` does in the entrypoint | ||
/// that it generates around the app's main method: | ||
/// | ||
/// * https://github.com/flutter/flutter/blob/95be76ab7e3dca2def54454313e97f94f4ac4582/packages/flutter_tools/lib/src/web/file_generators/main_dart.dart#L14-L43 | ||
/// | ||
/// By default, engine initialization and app startup occur immediately and back | ||
/// to back. They can be programmatically controlled by setting | ||
/// `FlutterLoader.didCreateEngineInitializer`. For more information, see how | ||
/// `flutter.js` does it: | ||
/// | ||
/// * https://github.com/flutter/flutter/blob/95be76ab7e3dca2def54454313e97f94f4ac4582/packages/flutter_tools/lib/src/web/file_generators/js/flutter.js | ||
Future<void> bootstrapEngine({ | ||
ui.VoidCallback? registerPlugins, | ||
ui.VoidCallback? runApp, | ||
}) async { | ||
// Create the object that knows how to bootstrap an app from JS and Dart. | ||
final AppBootstrap bootstrap = AppBootstrap( | ||
initializeEngine: ([JsFlutterConfiguration? configuration]) async { | ||
await initializeEngineServices(jsConfiguration: configuration); | ||
}, runApp: () async { | ||
if (registerPlugins != null) { | ||
registerPlugins(); | ||
} | ||
await initializeEngineUi(); | ||
if (runApp != null) { | ||
runApp(); | ||
} | ||
}, | ||
); | ||
|
||
final FlutterLoader? loader = flutter?.loader; | ||
if (loader == null || loader.isAutoStart) { | ||
// The user does not want control of the app, bootstrap immediately. | ||
domWindow.console.debug('Flutter Web Bootstrap: Auto.'); | ||
await bootstrap.autoStart(); | ||
} else { | ||
// Yield control of the bootstrap procedure to the user. | ||
domWindow.console.debug('Flutter Web Bootstrap: Programmatic.'); | ||
loader.didCreateEngineInitializer(bootstrap.prepareEngineInitializer()); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this something that is needed for end users, or is this only for our testing? If it's only for our engine testing, it probably should live within
engine
or similar, rather than be exposed toweb_ui
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Never mind, this is used all over the bootstrap and the framework!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, this could be hidden behind JS-interop, if we don't want it to show up in the public APIs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
debugEmulateFlutterTesterEnvironment
has effect on several things including the usage of Ahem font. If users want their tests to produce real text (e.g. for screenshots), they have to disabledebugEmulateFlutterTesterEnvironment
.