From 94500073a0cb01646c7c16d1eaa75c58e6f1ce44 Mon Sep 17 00:00:00 2001 From: stuartmorgan Date: Fri, 27 Mar 2020 16:36:15 -0700 Subject: [PATCH] Windows template update project (#53302) Updates the Windows app template to use the new DartProject API, significantly simplifying the template. Increments the template version, even though this isn't itself a breaking change, so that users will be prompted to update their projects rather than be broken later when the old API is removed. --- .../windows.tmpl/flutter/.template_version | 2 +- .../templates/app/windows.tmpl/main.cpp | 41 ++----------------- 2 files changed, 4 insertions(+), 39 deletions(-) diff --git a/packages/flutter_tools/templates/app/windows.tmpl/flutter/.template_version b/packages/flutter_tools/templates/app/windows.tmpl/flutter/.template_version index 56a6051ca2..0cfbf08886 100644 --- a/packages/flutter_tools/templates/app/windows.tmpl/flutter/.template_version +++ b/packages/flutter_tools/templates/app/windows.tmpl/flutter/.template_version @@ -1 +1 @@ -1 \ No newline at end of file +2 diff --git a/packages/flutter_tools/templates/app/windows.tmpl/main.cpp b/packages/flutter_tools/templates/app/windows.tmpl/main.cpp index f2e4301eaa..7e9627fe86 100644 --- a/packages/flutter_tools/templates/app/windows.tmpl/main.cpp +++ b/packages/flutter_tools/templates/app/windows.tmpl/main.cpp @@ -2,38 +2,13 @@ #include #include -#include #include -#include #include #include "flutter/generated_plugin_registrant.h" #include "win32_window.h" #include "window_configuration.h" -namespace { - -// Returns the path of the directory containing this executable, or an empty -// string if the directory cannot be found. -std::string GetExecutableDirectory() { - wchar_t buffer[MAX_PATH]; - if (GetModuleFileName(nullptr, buffer, MAX_PATH) == 0) { - std::cerr << "Couldn't locate executable" << std::endl; - return ""; - } - std::wstring_convert> wide_to_utf8; - std::string executable_path = wide_to_utf8.to_bytes(buffer); - 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 APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, _In_ wchar_t *command_line, _In_ int show_command) { // Attach to console when present (e.g., 'flutter run') or create a @@ -42,24 +17,14 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, ::AllocConsole(); } - // 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 arguments; + flutter::DartProject project(L"data"); // Top-level window frame. Win32Window::Point origin(kFlutterWindowOriginX, kFlutterWindowOriginY); Win32Window::Size size(kFlutterWindowWidth, kFlutterWindowHeight); - flutter::FlutterViewController flutter_controller( - icu_data_path, size.width, size.height, assets_path, arguments); + flutter::FlutterViewController flutter_controller(size.width, size.height, + project); RegisterPlugins(&flutter_controller); // Create a top-level win32 window to host the Flutter view.