From 0838239bc205e5c8aa41f529d87e140cddce0975 Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Mon, 12 Jan 2026 16:44:45 -0800 Subject: [PATCH] Update Windows build and plugin registration Adds native asset copying to CMakeLists, improves compatibility with older Flutter tool versions, and updates plugin registration to include battery_plus, connectivity_plus, screen_brightness_windows, and share_plus. Also refactors main.cpp formatting, adjusts resource.h spacing, removes legacy OS support from runner.exe.manifest, and fixes a type and logic in utils.cpp. --- .../windows/CMakeLists.txt | 6 ++++++ .../windows/flutter/CMakeLists.txt | 7 ++++++- .../flutter/generated_plugin_registrant.cc | 18 ++++++++++++------ .../windows/flutter/generated_plugins.cmake | 6 ++++-- .../windows/runner/main.cpp | 12 ++++-------- .../windows/runner/resource.h | 10 +++++----- .../windows/runner/runner.exe.manifest | 6 ------ .../windows/runner/utils.cpp | 4 ++-- 8 files changed, 39 insertions(+), 30 deletions(-) diff --git a/{{cookiecutter.out_dir}}/windows/CMakeLists.txt b/{{cookiecutter.out_dir}}/windows/CMakeLists.txt index 720dbf0..e4fbce0 100644 --- a/{{cookiecutter.out_dir}}/windows/CMakeLists.txt +++ b/{{cookiecutter.out_dir}}/windows/CMakeLists.txt @@ -87,6 +87,12 @@ if(PLUGIN_BUNDLED_LIBRARIES) COMPONENT Runtime) endif() +# Copy the native assets provided by the build.dart from all packages. +set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/windows/") +install(DIRECTORY "${NATIVE_ASSETS_DIR}" + DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) + # Fully re-copy the assets directory on each build to avoid having stale files # from a previous install. set(FLUTTER_ASSET_DIR_NAME "flutter_assets") diff --git a/{{cookiecutter.out_dir}}/windows/flutter/CMakeLists.txt b/{{cookiecutter.out_dir}}/windows/flutter/CMakeLists.txt index 930d207..903f489 100644 --- a/{{cookiecutter.out_dir}}/windows/flutter/CMakeLists.txt +++ b/{{cookiecutter.out_dir}}/windows/flutter/CMakeLists.txt @@ -10,6 +10,11 @@ include(${EPHEMERAL_DIR}/generated_config.cmake) # https://github.com/flutter/flutter/issues/57146. set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") +# Set fallback configurations for older versions of the flutter tool. +if (NOT DEFINED FLUTTER_TARGET_PLATFORM) + set(FLUTTER_TARGET_PLATFORM "windows-x64") +endif() + # === Flutter Library === set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") @@ -92,7 +97,7 @@ add_custom_command( COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" - windows-x64 $ + ${FLUTTER_TARGET_PLATFORM} $ VERBATIM ) add_custom_target(flutter_assemble DEPENDS diff --git a/{{cookiecutter.out_dir}}/windows/flutter/generated_plugin_registrant.cc b/{{cookiecutter.out_dir}}/windows/flutter/generated_plugin_registrant.cc index d6856b9..7e706c9 100644 --- a/{{cookiecutter.out_dir}}/windows/flutter/generated_plugin_registrant.cc +++ b/{{cookiecutter.out_dir}}/windows/flutter/generated_plugin_registrant.cc @@ -6,24 +6,30 @@ #include "generated_plugin_registrant.h" -#include +#include +#include +#include #include #include +#include #include #include -#include void RegisterPlugins(flutter::PluginRegistry* registry) { - RecordWindowsPluginCApiRegisterWithRegistrar( - registry->GetRegistrarForPlugin("RecordWindowsPluginCApi")); + BatteryPlusWindowsPluginRegisterWithRegistrar( + registry->GetRegistrarForPlugin("BatteryPlusWindowsPlugin")); + ConnectivityPlusWindowsPluginRegisterWithRegistrar( + registry->GetRegistrarForPlugin("ConnectivityPlusWindowsPlugin")); + ScreenBrightnessWindowsPluginRegisterWithRegistrar( + registry->GetRegistrarForPlugin("ScreenBrightnessWindowsPlugin")); ScreenRetrieverWindowsPluginCApiRegisterWithRegistrar( registry->GetRegistrarForPlugin("ScreenRetrieverWindowsPluginCApi")); SeriousPythonWindowsPluginCApiRegisterWithRegistrar( registry->GetRegistrarForPlugin("SeriousPythonWindowsPluginCApi")); + SharePlusWindowsPluginCApiRegisterWithRegistrar( + registry->GetRegistrarForPlugin("SharePlusWindowsPluginCApi")); UrlLauncherWindowsRegisterWithRegistrar( registry->GetRegistrarForPlugin("UrlLauncherWindows")); WindowManagerPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("WindowManagerPlugin")); - WindowToFrontPluginRegisterWithRegistrar( - registry->GetRegistrarForPlugin("WindowToFrontPlugin")); } diff --git a/{{cookiecutter.out_dir}}/windows/flutter/generated_plugins.cmake b/{{cookiecutter.out_dir}}/windows/flutter/generated_plugins.cmake index a4707c1..da335d2 100644 --- a/{{cookiecutter.out_dir}}/windows/flutter/generated_plugins.cmake +++ b/{{cookiecutter.out_dir}}/windows/flutter/generated_plugins.cmake @@ -3,12 +3,14 @@ # list(APPEND FLUTTER_PLUGIN_LIST - record_windows + battery_plus + connectivity_plus + screen_brightness_windows screen_retriever_windows serious_python_windows + share_plus url_launcher_windows window_manager - window_to_front ) list(APPEND FLUTTER_FFI_PLUGIN_LIST diff --git a/{{cookiecutter.out_dir}}/windows/runner/main.cpp b/{{cookiecutter.out_dir}}/windows/runner/main.cpp index 853cdae..3ed2eba 100644 --- a/{{cookiecutter.out_dir}}/windows/runner/main.cpp +++ b/{{cookiecutter.out_dir}}/windows/runner/main.cpp @@ -6,12 +6,10 @@ #include "utils.h" int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, - _In_ wchar_t *command_line, _In_ int show_command) -{ + _In_ wchar_t *command_line, _In_ int show_command) { // Attach to console when present (e.g., 'flutter run') or create a // new console when running with a debugger. - if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) - { + if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) { CreateAndAttachConsole(); } @@ -29,15 +27,13 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, FlutterWindow window(project); Win32Window::Point origin(10, 10); Win32Window::Size size(1280, 720); - if (!window.Create(L"{{ cookiecutter.product_name }}", origin, size)) - { + if (!window.Create(L"{{ cookiecutter.project_name }}", origin, size)) { return EXIT_FAILURE; } window.SetQuitOnClose(true); ::MSG msg; - while (::GetMessage(&msg, nullptr, 0, 0)) - { + while (::GetMessage(&msg, nullptr, 0, 0)) { ::TranslateMessage(&msg); ::DispatchMessage(&msg); } diff --git a/{{cookiecutter.out_dir}}/windows/runner/resource.h b/{{cookiecutter.out_dir}}/windows/runner/resource.h index 389a85a..cb9fd87 100644 --- a/{{cookiecutter.out_dir}}/windows/runner/resource.h +++ b/{{cookiecutter.out_dir}}/windows/runner/resource.h @@ -2,15 +2,15 @@ // Microsoft Visual C++ generated include file. // Used by Runner.rc // -#define IDI_APP_ICON 101 +#define IDI_APP_ICON 101 // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 102 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1001 -#define _APS_NEXT_SYMED_VALUE 101 +#define _APS_NEXT_RESOURCE_VALUE 102 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1001 +#define _APS_NEXT_SYMED_VALUE 101 #endif #endif diff --git a/{{cookiecutter.out_dir}}/windows/runner/runner.exe.manifest b/{{cookiecutter.out_dir}}/windows/runner/runner.exe.manifest index a42ea76..153653e 100644 --- a/{{cookiecutter.out_dir}}/windows/runner/runner.exe.manifest +++ b/{{cookiecutter.out_dir}}/windows/runner/runner.exe.manifest @@ -9,12 +9,6 @@ - - - - - - diff --git a/{{cookiecutter.out_dir}}/windows/runner/utils.cpp b/{{cookiecutter.out_dir}}/windows/runner/utils.cpp index b2b0873..3a0b465 100644 --- a/{{cookiecutter.out_dir}}/windows/runner/utils.cpp +++ b/{{cookiecutter.out_dir}}/windows/runner/utils.cpp @@ -45,13 +45,13 @@ std::string Utf8FromUtf16(const wchar_t* utf16_string) { if (utf16_string == nullptr) { return std::string(); } - int target_length = ::WideCharToMultiByte( + unsigned int target_length = ::WideCharToMultiByte( CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, -1, nullptr, 0, nullptr, nullptr) -1; // remove the trailing null character int input_length = (int)wcslen(utf16_string); std::string utf8_string; - if (target_length <= 0 || target_length > utf8_string.max_size()) { + if (target_length == 0 || target_length > utf8_string.max_size()) { return utf8_string; } utf8_string.resize(target_length);