linux hack my_application.cc so that it does directory exist checks on assets folder and can override to alt paths on the system

This commit is contained in:
Dan Ballard 2021-06-04 22:38:34 -07:00
parent 22eb994c52
commit 403eb04124
1 changed files with 38 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.
@ -52,7 +73,24 @@ static void my_application_activate(GApplication* application) {
gtk_window_set_default_size(window, 1280, 720);
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....
project->assets_path = g_build_filename(homedir, ".local", "share", "cwtch", "data", "flutter_assets", nullptr);
} else {
project->assets_path = g_build_filename("usr", "share", "cwtch", "data", "flutter_assets", nullptr);
}
}
// TODO override icu_data_path
fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments);
FlView* view = fl_view_new(project);