Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions shell/platform/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ if (build_linux_shell) {
}

source_set("flutter_linux") {
public = _public_headers

sources = [
"fl_dart_project.cc",
"fl_view.cc",
Expand Down
96 changes: 65 additions & 31 deletions shell/platform/linux/fl_dart_project.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,38 @@
struct _FlDartProject {
GObject parent_instance;

gchar* assets_path;
gchar* icu_data_path;
gchar* path;
};

enum { PROP_ASSETS_PATH = 1, PROP_ICU_DATA_PATH, PROP_LAST };
enum { PROP_ASSETS_PATH = 1, PROP_ICU_DATA_PATH, PROP_PATH, PROP_LAST };

G_DEFINE_TYPE(FlDartProject, fl_dart_project, G_TYPE_OBJECT)

static void fl_dart_project_set_path(FlDartProject* self, const gchar* path) {
g_free(self->path);

if (g_path_is_absolute(path))
self->path = g_strdup(path);
else {
g_autoptr(GError) error = NULL;
g_autofree gchar* exe_path = g_file_read_link("/proc/self/exe", &error);
if (exe_path == NULL)
g_critical("Failed to determine location of executable: %s",
error->message);
g_autofree gchar* dir = g_path_get_dirname(exe_path);
self->path = g_build_filename(dir, path, NULL);
}
}

static void fl_dart_project_set_property(GObject* object,
guint prop_id,
const GValue* value,
GParamSpec* pspec) {
FlDartProject* self = FL_DART_PROJECT(object);

switch (prop_id) {
case PROP_ASSETS_PATH:
g_free(self->assets_path);
self->assets_path = g_strdup(g_value_get_string(value));
break;
case PROP_ICU_DATA_PATH:
g_free(self->icu_data_path);
self->icu_data_path = g_strdup(g_value_get_string(value));
case PROP_PATH:
fl_dart_project_set_path(self, g_value_get_string(value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
Expand All @@ -53,10 +63,13 @@ static void fl_dart_project_get_property(GObject* object,

switch (prop_id) {
case PROP_ASSETS_PATH:
g_value_set_string(value, self->assets_path);
g_value_take_string(value, fl_dart_project_get_assets_path(self));
break;
case PROP_ICU_DATA_PATH:
g_value_set_string(value, self->icu_data_path);
g_value_take_string(value, fl_dart_project_get_icu_data_path(self));
break;
case PROP_PATH:
g_value_set_string(value, self->path);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
Expand All @@ -67,8 +80,7 @@ static void fl_dart_project_get_property(GObject* object,
static void fl_dart_project_dispose(GObject* object) {
FlDartProject* self = FL_DART_PROJECT(object);

g_clear_pointer(&self->assets_path, g_free);
g_clear_pointer(&self->icu_data_path, g_free);
g_clear_pointer(&self->path, g_free);

G_OBJECT_CLASS(fl_dart_project_parent_class)->dispose(object);
}
Expand All @@ -82,12 +94,18 @@ static void fl_dart_project_class_init(FlDartProjectClass* klass) {
G_OBJECT_CLASS(klass), PROP_ASSETS_PATH,
g_param_spec_string(
"assets-path", "assets-path", "Path to Flutter assets", nullptr,
static_cast<GParamFlags>(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS)));
static_cast<GParamFlags>(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));

g_object_class_install_property(
G_OBJECT_CLASS(klass), PROP_ICU_DATA_PATH,
g_param_spec_string(
"icu-data-path", "icu-data-path", "Path to ICU data", nullptr,
static_cast<GParamFlags>(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));

g_object_class_install_property(
G_OBJECT_CLASS(klass), PROP_PATH,
g_param_spec_string(
"path", "path", "Path to Flutter project", nullptr,
static_cast<GParamFlags>(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS)));
}
Expand All @@ -96,18 +114,34 @@ static void fl_dart_project_init(FlDartProject* self) {}

/**
* fl_dart_project_new:
* @assets_path: a file path, e.g. "build/assets"
* @icu_data_path: a file path, e.g. "build/icudtl.dat"
* @path: a file path, e.g. "my_dart_project"
*
* Create a Flutter project. The project path should contain the following
* top-level items:
* - icudtl.dat (provided as a resource by the Flutter tool)
* - flutter_assets (as built by the Flutter tool)
*
* Create a Flutter project.
* The path can either be absolute, or relative to the directory containing the
* running executable.
*
* Returns: a new #FlDartProject
*/
G_MODULE_EXPORT FlDartProject* fl_dart_project_new(const gchar* assets_path,
const gchar* icu_data_path) {
G_MODULE_EXPORT FlDartProject* fl_dart_project_new(const gchar* path) {
return static_cast<FlDartProject*>(
g_object_new(fl_dart_project_get_type(), "assets-path", assets_path,
"icu-data-path", icu_data_path, nullptr));
g_object_new(fl_dart_project_get_type(), "path", path, nullptr));
}

/**
* fl_dart_project_get_path:
* @view: a #FlDartProject
*
* Get the path to the directory containing the Flutter application.
*
* Returns: (type filename): a file path, e.g. "/projects/my_dart_project"
*/
G_MODULE_EXPORT const gchar* fl_dart_project_get_path(FlDartProject* self) {
g_return_val_if_fail(FL_IS_DART_PROJECT(self), nullptr);
return self->path;
}

/**
Expand All @@ -117,12 +151,12 @@ G_MODULE_EXPORT FlDartProject* fl_dart_project_new(const gchar* assets_path,
* Get the path to the directory containing the assets used in the Flutter
* application.
*
* Returns: a file path, e.g. "build/assets"
* Returns: (type filename): a file path, e.g.
* "/projects/my_dart_project/assets"
*/
G_MODULE_EXPORT const gchar* fl_dart_project_get_assets_path(
FlDartProject* self) {
G_MODULE_EXPORT gchar* fl_dart_project_get_assets_path(FlDartProject* self) {
g_return_val_if_fail(FL_IS_DART_PROJECT(self), nullptr);
return self->assets_path;
return g_build_filename(self->path, "flutter_assets", NULL);
}

/**
Expand All @@ -131,10 +165,10 @@ G_MODULE_EXPORT const gchar* fl_dart_project_get_assets_path(
*
* Get the path to the ICU data file in the Flutter application.
*
* Returns: a file path, e.g. "build/icudtl.dat"
* Returns: (type filename): a file path, e.g.
* "/projects/my_dart_project/icudtl.dat"
*/
G_MODULE_EXPORT const gchar* fl_dart_project_get_icu_data_path(
FlDartProject* self) {
G_MODULE_EXPORT gchar* fl_dart_project_get_icu_data_path(FlDartProject* self) {
g_return_val_if_fail(FL_IS_DART_PROJECT(self), nullptr);
return self->icu_data_path;
return g_build_filename(self->path, "icudtl.dat", NULL);
}
9 changes: 7 additions & 2 deletions shell/platform/linux/fl_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,15 @@ static gboolean run_flutter_engine(FlView* self) {
config.open_gl.fbo_callback = fl_view_gl_fbo_callback;
config.open_gl.present = fl_view_gl_present;

g_autofree gchar* assets_path =
fl_dart_project_get_assets_path(self->flutter_project);
g_autofree gchar* icu_data_path =
fl_dart_project_get_icu_data_path(self->flutter_project);

FlutterProjectArgs args = {};
args.struct_size = sizeof(FlutterProjectArgs);
args.assets_path = fl_dart_project_get_assets_path(self->flutter_project);
args.icu_data_path = fl_dart_project_get_icu_data_path(self->flutter_project);
args.assets_path = assets_path;
args.icu_data_path = icu_data_path;

FlutterEngineResult result = FlutterEngineInitialize(
FLUTTER_ENGINE_VERSION, &config, &args, self, &self->flutter_engine);
Expand Down
9 changes: 5 additions & 4 deletions shell/platform/linux/public/flutter_linux/fl_dart_project.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ G_BEGIN_DECLS

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

FlDartProject* fl_dart_project_new(const gchar* assets_path,
const gchar* icu_data_path);
FlDartProject* fl_dart_project_new(const gchar* path);

const gchar* fl_dart_project_get_assets_path(FlDartProject* project);
const gchar* fl_dart_project_get_path(FlDartProject* project);

const gchar* fl_dart_project_get_icu_data_path(FlDartProject* project);
gchar* fl_dart_project_get_assets_path(FlDartProject* project);

gchar* fl_dart_project_get_icu_data_path(FlDartProject* project);

G_END_DECLS

Expand Down