Merge pull request 'linux assetsDir support linux style installs' (#180) from assetsDir into trunk
continuous-integration/drone/push Build is passing Details

Reviewed-on: #180
This commit is contained in:
Sarah Jamie Lewis 2021-06-14 17:41:34 -07:00
commit 16f9928275
1 changed files with 44 additions and 0 deletions

View File

@ -1,5 +1,14 @@
#include "my_application.h"
// Added to check for location of assets folder
#include <sys/types.h>
#include <sys/stat.h>
// To get the home dir of the user
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
#include <flutter_linux/flutter_linux.h>
#ifdef GDK_WINDOWING_X11
#include <gdk/gdkx.h>
@ -12,6 +21,18 @@ struct _MyApplication {
char** dart_entrypoint_arguments;
};
// Redefining from flutter/engine::shell/platform/linux/fl_dart_project.cc
// struct def required here to enable compiler to allow access to variables
struct _FlDartProject {
GObject parent_instance;
gboolean enable_mirrors;
gchar* aot_library_path;
gchar* assets_path;
gchar* icu_data_path;
gchar** dart_entrypoint_args;
};
G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION)
// Implements GApplication::activate.
@ -53,6 +74,29 @@ static void my_application_activate(GApplication* application) {
gtk_widget_show(GTK_WIDGET(window));
g_autoptr(FlDartProject) project = fl_dart_project_new();
// Check if assets folder is relative to the executable or if we can use a system copy
struct stat info;
if (stat(fl_dart_project_get_assets_path(project), &info ) != 0 ) {
if( stat("/usr/share/cwtch/data/flutter_assets", &info ) != 0 ) {
struct passwd *pw = getpwuid(getuid());
const char *homedir = pw->pw_dir;
// /home/$USER/.local/share/cwtch/data/flutter_assets
project->assets_path = g_build_filename(homedir, ".local", "share", "cwtch", "data", "flutter_assets", nullptr);
// /home/$USER/bin/cwtch/lib
project->aot_library_path = g_build_filename(homedir, "bin", "cwtch", "lib", nullptr);
// /home/$USER/.local/share/cwtch/data
project->icu_data_path = g_build_filename(homedir, ".local", "share", "cwtch", "data", nullptr);
} else {
// /usr/share/cwtch/data/flutter_assets
project->assets_path = g_build_filename("usr", "share", "cwtch", "data", "flutter_assets", nullptr);
// /usr/lib/cwtch
project->aot_library_path = g_build_filename("usr", "lib", "cwtch", nullptr);
// /usr/share/cwtch/data
project->icu_data_path = g_build_filename("usr", "share", "cwtch", "data", nullptr);
}
}
fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments);
FlView* view = fl_view_new(project);