3
3
#include < flutter_linux/flutter_linux.h>
4
4
#include < gtk/gtk.h>
5
5
#include < sys/utsname.h>
6
+ #include < glib.h>
6
7
7
8
#include < cstring>
8
9
@@ -53,6 +54,25 @@ static void method_call_cb(FlMethodChannel* channel, FlMethodCall* method_call,
53
54
flutter_js_plugin_handle_method_call (plugin, method_call);
54
55
}
55
56
57
+ // Gets the directory the current executable is in, borrowed from:
58
+ // https://github.com/flutter/engine/blob/master/shell/platform/linux/fl_dart_project.cc#L27
59
+ //
60
+ // Copyright 2013 The Flutter Authors. All rights reserved.
61
+ // Use of this source code is governed by a BSD-style license that can be
62
+ // found in https://github.com/flutter/engine/blob/master/LICENSE.
63
+ static gchar* get_executable_dir () {
64
+ g_autoptr (GError) error = nullptr ;
65
+ g_autofree gchar* exe_path = g_file_read_link (" /proc/self/exe" , &error);
66
+ if (exe_path == nullptr ) {
67
+ g_critical (" Failed to determine location of executable: %s" ,
68
+ error->message );
69
+ return nullptr ;
70
+ }
71
+
72
+ return g_path_get_dirname (exe_path);
73
+ }
74
+
75
+
56
76
void flutter_js_plugin_register_with_registrar (FlPluginRegistrar* registrar) {
57
77
FlutterJsPlugin* plugin = FLUTTER_JS_PLUGIN (
58
78
g_object_new (flutter_js_plugin_get_type (), nullptr ));
@@ -67,4 +87,10 @@ void flutter_js_plugin_register_with_registrar(FlPluginRegistrar* registrar) {
67
87
g_object_unref);
68
88
69
89
g_object_unref (plugin);
90
+
91
+ g_autofree gchar* executable_dir = get_executable_dir ();
92
+ g_autofree gchar* lib_path =
93
+ g_build_filename (executable_dir, " lib" , " libquickjs_c_bridge_plugin.so" , nullptr );
94
+ setenv (" LIBQUICKJSC_PATH" , lib_path, 0 );
70
95
}
96
+
0 commit comments