1 #include <flutter/flutter_window_controller.h>
2 #include <linux/limits.h>
10 #include "flutter/generated_plugin_registrant.h"
11 #include "window_configuration.h"
15 // Returns the path of the directory containing this executable, or an empty
16 // string if the directory cannot be found.
17 std::string GetExecutableDirectory() {
18 char buffer[PATH_MAX + 1];
19 ssize_t length = readlink("/proc/self/exe", buffer, sizeof(buffer));
20 if (length > PATH_MAX) {
21 std::cerr << "Couldn't locate executable" << std::endl;
24 std::string executable_path(buffer, length);
25 size_t last_separator_position = executable_path.find_last_of('/');
26 if (last_separator_position == std::string::npos) {
27 std::cerr << "Unabled to find parent directory of " << executable_path
31 return executable_path.substr(0, last_separator_position);
36 int main(int argc, char **argv) {
37 // Resources are located relative to the executable.
38 std::string base_directory = GetExecutableDirectory();
39 if (base_directory.empty()) {
42 std::string data_directory = base_directory + "/data";
43 std::string assets_path = data_directory + "/flutter_assets";
44 std::string icu_data_path = data_directory + "/icudtl.dat";
46 // Arguments for the Flutter Engine.
47 std::vector<std::string> arguments;
49 flutter::FlutterWindowController flutter_controller(icu_data_path);
50 flutter::WindowProperties window_properties = {};
51 window_properties.title = kFlutterWindowTitle;
52 window_properties.width = kFlutterWindowWidth;
53 window_properties.height = kFlutterWindowHeight;
56 if (!flutter_controller.CreateWindow(window_properties, assets_path,
60 RegisterPlugins(&flutter_controller);
62 // Run until the window is closed.
63 while (flutter_controller.RunEventLoopWithTimeout(
64 std::chrono::milliseconds::max())) {