|
|
|
|
@@ -16,14 +16,29 @@
|
|
|
|
|
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,
|
|
|
|
|
@@ -31,13 +46,8 @@ static void fl_dart_project_set_property(GObject* object,
|
|
|
|
|
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);
|
|
|
|
|
@@ -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);
|
|
|
|
|
@@ -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);
|
|
|
|
|
}
|
|
|
|
|
@@ -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)));
|
|
|
|
|
}
|
|
|
|
|
@@ -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.
|
|
|
|
|
* 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)
|
|
|
|
|
*
|
|
|
|
|
* 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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -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);
|
|
|
|
|
}
|
|
|
|
|
|