-
Notifications
You must be signed in to change notification settings - Fork 6k
Make FlutterEngineGroup support initialRoute #28884
Make FlutterEngineGroup support initialRoute #28884
Conversation
The way initial route typically works is through the navigation platform channel: https://github.com/gaaclarke/engine/blob/0e76836ea8409e87b553341bcb16f98028faba90/shell/common/engine.cc#L361:L361 Why are creating c++ plumbing to handle initial route instead of using the navigation platform channel? |
Because I want to make sure that the Line 515 in 20ec34e
|
The initialization and running of the heavyweight engine are separate. So after it is initialized and before running, you have the opportunity to set up the initialRoute through the navigation platform channel. However, the initialization and running of the lightweight engine are all done in |
Ahh I see. Here is where the message is sent: The flow for typical usage is:
Because spawn is create+launch together you had to insert the ability to specify it in spawn to sandwich it between create and launch. I think that sounds good, I'll look at this again. |
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.
This looks good, another great contribution @ColdPaleLight, thanks. I just have a few nitpicks.
shell/common/engine.cc
Outdated
@@ -133,6 +134,7 @@ std::unique_ptr<Engine> Engine::Spawn( | |||
settings_.isolate_shutdown_callback, // isolate shutdown callback | |||
settings_.persistent_isolate_data // persistent isolate data | |||
); | |||
result->initial_route_ = std::move(initial_route); |
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.
I don't think you want an std::move here. This has to initiate a copy anyways, I think it is just needlessly invalidating the reference.
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.
Done
shell/common/shell.cc
Outdated
@@ -488,7 +489,8 @@ std::unique_ptr<Shell> Shell::Spawn( | |||
PlatformData{}, task_runners_, rasterizer_->GetRasterThreadMerger(), | |||
GetSettings(), vm_, vm_->GetVMData()->GetIsolateSnapshot(), | |||
on_create_platform_view, on_create_rasterizer, | |||
[engine = this->engine_.get()]( | |||
[engine = this->engine_.get(), | |||
initial_route = std::move(initial_route)]( |
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.
Same here for std::move. Since this is executing on a separate thread, just explicitly make a copy.
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.
Done
shell/common/shell.cc
Outdated
@@ -501,7 +503,8 @@ std::unique_ptr<Shell> Shell::Spawn( | |||
return engine->Spawn(/*delegate=*/delegate, | |||
/*dispatcher_maker=*/dispatcher_maker, | |||
/*settings=*/settings, | |||
/*animator=*/std::move(animator)); | |||
/*animator=*/std::move(animator), | |||
/*initial_route*/ initial_route); |
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.
s/initial_route/initial_route=
I wish the linter worked for that, doesn't seem to be.
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.
Done
shell/common/shell_unittests.cc
Outdated
@@ -2740,6 +2743,7 @@ TEST_F(ShellTest, Spawn) { | |||
// Check second shell ran the second entrypoint. | |||
ASSERT_EQ("testCanLaunchSecondaryIsolate", | |||
spawn->GetEngine()->GetLastEntrypoint()); | |||
ASSERT_EQ("/foo", spawn->GetEngine()->InitialRoute()); |
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.
s/"/foo"/initial_route
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.
Done
@@ -1027,8 +1028,13 @@ - (FlutterEngine*)spawnWithEntrypoint:(/*nullable*/ NSString*)entrypoint | |||
flutter::Shell::CreateCallback<flutter::Rasterizer> on_create_rasterizer = | |||
[](flutter::Shell& shell) { return std::make_unique<flutter::Rasterizer>(shell); }; | |||
|
|||
std::unique_ptr<flutter::Shell> shell = | |||
_shell->Spawn(std::move(configuration), on_create_platform_view, on_create_rasterizer); | |||
std::string initial_route; |
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.
The naming convention for objc is camel case. It's confusing having initialRoute
and initial_route
in the same context. I'm not sure if we have an established convention for this but how about initialRoute
and cppInitialRoute
?
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.
Done
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.
LGTM, thanks!
This pull request is not suitable for automatic merging in its current state. |
fixes: flutter/flutter#78931
Pre-launch Checklist
writing and running engine tests.
///
).