diff --git a/linux/my_application.cc b/linux/my_application.cc index 4120e40..742330f 100644 --- a/linux/my_application.cc +++ b/linux/my_application.cc @@ -1,5 +1,14 @@ #include "my_application.h" +// Added to check for location of assets folder +#include +#include + +// To get the home dir of the user +#include +#include +#include + #include #ifdef GDK_WINDOWING_X11 #include @@ -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);