mirror of
https://github.com/flutter/samples.git
synced 2025-11-11 07:18:15 +00:00
[Gallery] Fix directory structure (#312)
This commit is contained in:
70
gallery/linux/main.cc
Executable file
70
gallery/linux/main.cc
Executable file
@@ -0,0 +1,70 @@
|
||||
// Copyright 2019 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include <flutter/flutter_window_controller.h>
|
||||
#include <linux/limits.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "flutter/generated_plugin_registrant.h"
|
||||
|
||||
namespace {
|
||||
|
||||
// Returns the path of the directory containing this executable, or an empty
|
||||
// string if the directory cannot be found.
|
||||
std::string GetExecutableDirectory() {
|
||||
char buffer[PATH_MAX + 1];
|
||||
ssize_t length = readlink("/proc/self/exe", buffer, sizeof(buffer));
|
||||
if (length > PATH_MAX) {
|
||||
std::cerr << "Couldn't locate executable" << std::endl;
|
||||
return "";
|
||||
}
|
||||
std::string executable_path(buffer, length);
|
||||
size_t last_separator_position = executable_path.find_last_of('/');
|
||||
if (last_separator_position == std::string::npos) {
|
||||
std::cerr << "Unabled to find parent directory of " << executable_path
|
||||
<< std::endl;
|
||||
return "";
|
||||
}
|
||||
return executable_path.substr(0, last_separator_position);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
// Resources are located relative to the executable.
|
||||
std::string base_directory = GetExecutableDirectory();
|
||||
if (base_directory.empty()) {
|
||||
base_directory = ".";
|
||||
}
|
||||
std::string data_directory = base_directory + "/data";
|
||||
std::string assets_path = data_directory + "/flutter_assets";
|
||||
std::string icu_data_path = data_directory + "/icudtl.dat";
|
||||
|
||||
// Arguments for the Flutter Engine.
|
||||
std::vector<std::string> arguments;
|
||||
|
||||
flutter::FlutterWindowController flutter_controller(icu_data_path);
|
||||
flutter::WindowProperties window_properties = {};
|
||||
window_properties.title = "Flutter Gallery";
|
||||
window_properties.width = 800;
|
||||
window_properties.height = 600;
|
||||
|
||||
// Start the engine.
|
||||
if (!flutter_controller.CreateWindow(window_properties, assets_path,
|
||||
arguments)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
RegisterPlugins(&flutter_controller);
|
||||
|
||||
// Run until the window is closed.
|
||||
while (flutter_controller.RunEventLoopWithTimeout(
|
||||
std::chrono::milliseconds::max())) {
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Reference in New Issue
Block a user