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

Commit 9fd9634

Browse files
committed
Update FlDartProject to new path format
1 parent 8ae5eaa commit 9fd9634

File tree

3 files changed

+75
-37
lines changed

3 files changed

+75
-37
lines changed

shell/platform/linux/fl_dart_project.cc

Lines changed: 63 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,38 @@
1616
struct _FlDartProject {
1717
GObject parent_instance;
1818

19-
gchar* assets_path;
20-
gchar* icu_data_path;
19+
gchar* path;
2120
};
2221

23-
enum { PROP_ASSETS_PATH = 1, PROP_ICU_DATA_PATH, PROP_LAST };
22+
enum { PROP_ASSETS_PATH = 1, PROP_ICU_DATA_PATH, PROP_PATH, PROP_LAST };
2423

2524
G_DEFINE_TYPE(FlDartProject, fl_dart_project, G_TYPE_OBJECT)
2625

26+
static void fl_dart_project_set_path(FlDartProject* self, const gchar* path) {
27+
g_free(self->path);
28+
29+
if (g_path_is_absolute(path))
30+
self->path = g_strdup(path);
31+
else {
32+
g_autoptr(GError) error = NULL;
33+
g_autofree gchar* exe_path = g_file_read_link("/proc/self/exe", &error);
34+
if (exe_path == NULL)
35+
g_critical("Failed to determine location of executable: %s",
36+
error->message);
37+
g_autofree gchar* dir = g_path_get_dirname(exe_path);
38+
self->path = g_build_filename(dir, path, NULL);
39+
}
40+
}
41+
2742
static void fl_dart_project_set_property(GObject* object,
2843
guint prop_id,
2944
const GValue* value,
3045
GParamSpec* pspec) {
3146
FlDartProject* self = FL_DART_PROJECT(object);
3247

3348
switch (prop_id) {
34-
case PROP_ASSETS_PATH:
35-
g_free(self->assets_path);
36-
self->assets_path = g_strdup(g_value_get_string(value));
37-
break;
38-
case PROP_ICU_DATA_PATH:
39-
g_free(self->icu_data_path);
40-
self->icu_data_path = g_strdup(g_value_get_string(value));
49+
case PROP_PATH:
50+
fl_dart_project_set_path(self, g_value_get_string(value));
4151
break;
4252
default:
4353
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
@@ -53,10 +63,13 @@ static void fl_dart_project_get_property(GObject* object,
5363

5464
switch (prop_id) {
5565
case PROP_ASSETS_PATH:
56-
g_value_set_string(value, self->assets_path);
66+
g_value_take_string(value, fl_dart_project_get_assets_path(self));
5767
break;
5868
case PROP_ICU_DATA_PATH:
59-
g_value_set_string(value, self->icu_data_path);
69+
g_value_take_string(value, fl_dart_project_get_icu_data_path(self));
70+
break;
71+
case PROP_PATH:
72+
g_value_set_string(value, self->path);
6073
break;
6174
default:
6275
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
@@ -67,8 +80,7 @@ static void fl_dart_project_get_property(GObject* object,
6780
static void fl_dart_project_dispose(GObject* object) {
6881
FlDartProject* self = FL_DART_PROJECT(object);
6982

70-
g_clear_pointer(&self->assets_path, g_free);
71-
g_clear_pointer(&self->icu_data_path, g_free);
83+
g_clear_pointer(&self->path, g_free);
7284

7385
G_OBJECT_CLASS(fl_dart_project_parent_class)->dispose(object);
7486
}
@@ -82,12 +94,16 @@ static void fl_dart_project_class_init(FlDartProjectClass* klass) {
8294
G_OBJECT_CLASS(klass), PROP_ASSETS_PATH,
8395
g_param_spec_string(
8496
"assets-path", "assets-path", "Path to Flutter assets", nullptr,
85-
static_cast<GParamFlags>(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
86-
G_PARAM_STATIC_STRINGS)));
97+
static_cast<GParamFlags>(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));
8798
g_object_class_install_property(
8899
G_OBJECT_CLASS(klass), PROP_ICU_DATA_PATH,
89100
g_param_spec_string(
90101
"icu-data-path", "icu-data-path", "Path to ICU data", nullptr,
102+
static_cast<GParamFlags>(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));
103+
g_object_class_install_property(
104+
G_OBJECT_CLASS(klass), PROP_PATH,
105+
g_param_spec_string(
106+
"path", "path", "Path to Flutter project", nullptr,
91107
static_cast<GParamFlags>(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
92108
G_PARAM_STATIC_STRINGS)));
93109
}
@@ -96,18 +112,34 @@ static void fl_dart_project_init(FlDartProject* self) {}
96112

97113
/**
98114
* fl_dart_project_new:
99-
* @assets_path: a file path, e.g. "build/assets"
100-
* @icu_data_path: a file path, e.g. "build/icudtl.dat"
115+
* @path: a file path, e.g. "my_dart_project"
116+
*
117+
* Create a Flutter project. The project path should contain the following
118+
* top-level items:
119+
* - icudtl.dat (provided as a resource by the Flutter tool)
120+
* - flutter_assets (as built by the Flutter tool)
101121
*
102-
* Create a Flutter project.
122+
* The path can either be absolute, or relative to the directory containing the
123+
* running executable.
103124
*
104125
* Returns: a new #FlDartProject
105126
*/
106-
G_MODULE_EXPORT FlDartProject* fl_dart_project_new(const gchar* assets_path,
107-
const gchar* icu_data_path) {
127+
G_MODULE_EXPORT FlDartProject* fl_dart_project_new(const gchar* path) {
108128
return static_cast<FlDartProject*>(
109-
g_object_new(fl_dart_project_get_type(), "assets-path", assets_path,
110-
"icu-data-path", icu_data_path, nullptr));
129+
g_object_new(fl_dart_project_get_type(), "path", path, nullptr));
130+
}
131+
132+
/**
133+
* fl_dart_project_get_path:
134+
* @view: a #FlDartProject
135+
*
136+
* Get the path to the directory containing the Flutter application.
137+
*
138+
* Returns: (type filename): a file path, e.g. "my_dart_project"
139+
*/
140+
G_MODULE_EXPORT const gchar* fl_dart_project_get_path(FlDartProject* self) {
141+
g_return_val_if_fail(FL_IS_DART_PROJECT(self), nullptr);
142+
return self->path;
111143
}
112144

113145
/**
@@ -117,12 +149,12 @@ G_MODULE_EXPORT FlDartProject* fl_dart_project_new(const gchar* assets_path,
117149
* Get the path to the directory containing the assets used in the Flutter
118150
* application.
119151
*
120-
* Returns: a file path, e.g. "build/assets"
152+
* Returns: (type filename): a file path, e.g.
153+
* "/projects/my_dart_project/assets"
121154
*/
122-
G_MODULE_EXPORT const gchar* fl_dart_project_get_assets_path(
123-
FlDartProject* self) {
155+
G_MODULE_EXPORT gchar* fl_dart_project_get_assets_path(FlDartProject* self) {
124156
g_return_val_if_fail(FL_IS_DART_PROJECT(self), nullptr);
125-
return self->assets_path;
157+
return g_build_filename(self->path, "flutter_assets", NULL);
126158
}
127159

128160
/**
@@ -131,10 +163,10 @@ G_MODULE_EXPORT const gchar* fl_dart_project_get_assets_path(
131163
*
132164
* Get the path to the ICU data file in the Flutter application.
133165
*
134-
* Returns: a file path, e.g. "build/icudtl.dat"
166+
* Returns: (type filename): a file path, e.g.
167+
* "/projects/my_dart_project/icudtl.dat"
135168
*/
136-
G_MODULE_EXPORT const gchar* fl_dart_project_get_icu_data_path(
137-
FlDartProject* self) {
169+
G_MODULE_EXPORT gchar* fl_dart_project_get_icu_data_path(FlDartProject* self) {
138170
g_return_val_if_fail(FL_IS_DART_PROJECT(self), nullptr);
139-
return self->icu_data_path;
171+
return g_build_filename(self->path, "icudtl.dat", NULL);
140172
}

shell/platform/linux/fl_view.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,15 @@ static gboolean run_flutter_engine(FlView* self) {
136136
config.open_gl.fbo_callback = fl_view_gl_fbo_callback;
137137
config.open_gl.present = fl_view_gl_present;
138138

139+
g_autofree gchar* assets_path =
140+
fl_dart_project_get_assets_path(self->flutter_project);
141+
g_autofree gchar* icu_data_path =
142+
fl_dart_project_get_icu_data_path(self->flutter_project);
143+
139144
FlutterProjectArgs args = {};
140145
args.struct_size = sizeof(FlutterProjectArgs);
141-
args.assets_path = fl_dart_project_get_assets_path(self->flutter_project);
142-
args.icu_data_path = fl_dart_project_get_icu_data_path(self->flutter_project);
146+
args.assets_path = assets_path;
147+
args.icu_data_path = icu_data_path;
143148

144149
FlutterEngineResult result = FlutterEngineInitialize(
145150
FLUTTER_ENGINE_VERSION, &config, &args, self, &self->flutter_engine);

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ G_BEGIN_DECLS
1515

1616
G_DECLARE_FINAL_TYPE(FlDartProject, fl_dart_project, FL, DART_PROJECT, GObject)
1717

18-
FlDartProject* fl_dart_project_new(const gchar* assets_path,
19-
const gchar* icu_data_path);
18+
FlDartProject* fl_dart_project_new(const gchar* path);
2019

21-
const gchar* fl_dart_project_get_assets_path(FlDartProject* project);
20+
const gchar* fl_dart_project_get_path(FlDartProject* project);
2221

23-
const gchar* fl_dart_project_get_icu_data_path(FlDartProject* project);
22+
gchar* fl_dart_project_get_assets_path(FlDartProject* project);
23+
24+
gchar* fl_dart_project_get_icu_data_path(FlDartProject* project);
2425

2526
G_END_DECLS
2627

0 commit comments

Comments
 (0)