Skip to content

Commit 745a81a

Browse files
George Wrightchaselatta
authored andcommitted
Plumb through Dart entrypoint arguments on the Linux embedder (flutter-team-archive#21933)
1 parent 109047b commit 745a81a

3 files changed

Lines changed: 46 additions & 0 deletions

File tree

shell/platform/linux/fl_dart_project.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ struct _FlDartProject {
1919
gchar* aot_library_path;
2020
gchar* assets_path;
2121
gchar* icu_data_path;
22+
gchar** dart_entrypoint_args;
2223
};
2324

2425
G_DEFINE_TYPE(FlDartProject, fl_dart_project, G_TYPE_OBJECT)
@@ -42,6 +43,7 @@ static void fl_dart_project_dispose(GObject* object) {
4243
g_clear_pointer(&self->aot_library_path, g_free);
4344
g_clear_pointer(&self->assets_path, g_free);
4445
g_clear_pointer(&self->icu_data_path, g_free);
46+
g_clear_pointer(&self->dart_entrypoint_args, g_strfreev);
4547

4648
G_OBJECT_CLASS(fl_dart_project_parent_class)->dispose(object);
4749
}
@@ -98,6 +100,20 @@ G_MODULE_EXPORT const gchar* fl_dart_project_get_icu_data_path(
98100
return self->icu_data_path;
99101
}
100102

103+
G_MODULE_EXPORT gchar** fl_dart_project_get_dart_entrypoint_arguments(
104+
FlDartProject* self) {
105+
g_return_val_if_fail(FL_IS_DART_PROJECT(self), nullptr);
106+
return self->dart_entrypoint_args;
107+
}
108+
109+
G_MODULE_EXPORT void fl_dart_project_set_dart_entrypoint_arguments(
110+
FlDartProject* self,
111+
char** argv) {
112+
g_return_if_fail(FL_IS_DART_PROJECT(self));
113+
g_clear_pointer(&self->dart_entrypoint_args, g_strfreev);
114+
self->dart_entrypoint_args = g_strdupv(argv);
115+
}
116+
101117
GPtrArray* fl_dart_project_get_switches(FlDartProject* self) {
102118
GPtrArray* switches = g_ptr_array_new_with_free_func(g_free);
103119
std::vector<std::string> env_switches = flutter::GetSwitchesFromEnvironment();

shell/platform/linux/fl_engine.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,9 @@ gboolean fl_engine_start(FlEngine* self, GError** error) {
381381
// so that all switches are used.
382382
g_ptr_array_insert(command_line_args, 0, g_strdup("flutter"));
383383

384+
gchar** dart_entrypoint_args =
385+
fl_dart_project_get_dart_entrypoint_arguments(self->project);
386+
384387
FlutterProjectArgs args = {};
385388
args.struct_size = sizeof(FlutterProjectArgs);
386389
args.assets_path = fl_dart_project_get_assets_path(self->project);
@@ -391,6 +394,9 @@ gboolean fl_engine_start(FlEngine* self, GError** error) {
391394
args.platform_message_callback = fl_engine_platform_message_cb;
392395
args.custom_task_runners = &custom_task_runners;
393396
args.shutdown_dart_vm_when_done = true;
397+
args.dart_entrypoint_argc = g_strv_length(dart_entrypoint_args);
398+
args.dart_entrypoint_argv =
399+
reinterpret_cast<const char* const*>(dart_entrypoint_args);
394400

395401
if (FlutterEngineRunsAOTCompiledDartCode()) {
396402
FlutterEngineAOTDataSource source = {};

shell/platform/linux/public/flutter_linux/fl_dart_project.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,30 @@ const gchar* fl_dart_project_get_assets_path(FlDartProject* project);
9696
*/
9797
const gchar* fl_dart_project_get_icu_data_path(FlDartProject* project);
9898

99+
/**
100+
* fl_dart_project_set_dart_entrypoint_arguments:
101+
* @project: an #FlDartProject.
102+
* @argv: a pointer to a NULL-terminated array of C strings containing the
103+
* command line arguments.
104+
*
105+
* Sets the command line arguments to be passed through to the Dart
106+
* entrypoint function.
107+
*/
108+
void fl_dart_project_set_dart_entrypoint_arguments(FlDartProject* project,
109+
char** argv);
110+
111+
/**
112+
* fl_dart_project_get_dart_entrypoint_arguments:
113+
* @project: an #FlDartProject.
114+
*
115+
* Gets the command line arguments to be passed through to the Dart entrypoint
116+
* function.
117+
*
118+
* Returns: a NULL-terminated array of strings containing the command line
119+
* arguments to be passed to the Dart entrypoint.
120+
*/
121+
gchar** fl_dart_project_get_dart_entrypoint_arguments(FlDartProject* project);
122+
99123
G_END_DECLS
100124

101125
#endif // FLUTTER_SHELL_PLATFORM_LINUX_FL_DART_PROJECT_H_

0 commit comments

Comments
 (0)