Skip to content

Commit 4176195

Browse files
committed
test: Rebuild windows example directory
1 parent 625d44d commit 4176195

File tree

12 files changed

+186
-36
lines changed

12 files changed

+186
-36
lines changed

packages/window_manager/example/windows/CMakeLists.txt

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1+
# Project-level configuration.
12
cmake_minimum_required(VERSION 3.14)
23
project(window_manager_example LANGUAGES CXX)
34

5+
# The name of the executable created for the application. Change this to change
6+
# the on-disk name of your application.
47
set(BINARY_NAME "window_manager_example")
58

6-
cmake_policy(SET CMP0063 NEW)
9+
# Explicitly opt in to modern CMake behaviors to avoid warnings with recent
10+
# versions of CMake.
11+
cmake_policy(VERSION 3.14...3.25)
712

8-
set(CMAKE_INSTALL_RPATH "$ORIGIN/lib")
9-
10-
# Configure build options.
13+
# Define build configuration option.
1114
get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
1215
if(IS_MULTICONFIG)
1316
set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release"
@@ -20,7 +23,7 @@ else()
2023
"Debug" "Profile" "Release")
2124
endif()
2225
endif()
23-
26+
# Define settings for the Profile build mode.
2427
set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
2528
set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}")
2629
set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}")
@@ -30,6 +33,10 @@ set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}")
3033
add_definitions(-DUNICODE -D_UNICODE)
3134

3235
# Compilation settings that should be applied to most targets.
36+
#
37+
# Be cautious about adding new options here, as plugins use this function by
38+
# default. In most cases, you should add new options to specific targets instead
39+
# of modifying this function.
3340
function(APPLY_STANDARD_SETTINGS TARGET)
3441
target_compile_features(${TARGET} PUBLIC cxx_std_17)
3542
target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100")
@@ -38,14 +45,14 @@ function(APPLY_STANDARD_SETTINGS TARGET)
3845
target_compile_definitions(${TARGET} PRIVATE "$<$<CONFIG:Debug>:_DEBUG>")
3946
endfunction()
4047

41-
set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
42-
4348
# Flutter library and tool build rules.
49+
set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
4450
add_subdirectory(${FLUTTER_MANAGED_DIR})
4551

46-
# Application build
52+
# Application build; see runner/CMakeLists.txt.
4753
add_subdirectory("runner")
4854

55+
4956
# Generated plugin build rules, which manage building the plugins and adding
5057
# them to the application.
5158
include(flutter/generated_plugins.cmake)
@@ -80,6 +87,12 @@ if(PLUGIN_BUNDLED_LIBRARIES)
8087
COMPONENT Runtime)
8188
endif()
8289

90+
# Copy the native assets provided by the build.dart from all packages.
91+
set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/windows/")
92+
install(DIRECTORY "${NATIVE_ASSETS_DIR}"
93+
DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
94+
COMPONENT Runtime)
95+
8396
# Fully re-copy the assets directory on each build to avoid having stale files
8497
# from a previous install.
8598
set(FLUTTER_ASSET_DIR_NAME "flutter_assets")

packages/window_manager/example/windows/flutter/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# This file controls Flutter-level build steps. It should not be edited.
12
cmake_minimum_required(VERSION 3.14)
23

34
set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral")
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// Generated file. Do not edit.
3+
//
4+
5+
// clang-format off
6+
7+
#include "generated_plugin_registrant.h"
8+
9+
#include <screen_retriever_windows/screen_retriever_windows_plugin_c_api.h>
10+
#include <tray_manager/tray_manager_plugin.h>
11+
#include <window_manager/window_manager_plugin.h>
12+
13+
void RegisterPlugins(flutter::PluginRegistry* registry) {
14+
ScreenRetrieverWindowsPluginCApiRegisterWithRegistrar(
15+
registry->GetRegistrarForPlugin("ScreenRetrieverWindowsPluginCApi"));
16+
TrayManagerPluginRegisterWithRegistrar(
17+
registry->GetRegistrarForPlugin("TrayManagerPlugin"));
18+
WindowManagerPluginRegisterWithRegistrar(
19+
registry->GetRegistrarForPlugin("WindowManagerPlugin"));
20+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// Generated file. Do not edit.
3+
//
4+
5+
// clang-format off
6+
7+
#ifndef GENERATED_PLUGIN_REGISTRANT_
8+
#define GENERATED_PLUGIN_REGISTRANT_
9+
10+
#include <flutter/plugin_registry.h>
11+
12+
// Registers Flutter plugins.
13+
void RegisterPlugins(flutter::PluginRegistry* registry);
14+
15+
#endif // GENERATED_PLUGIN_REGISTRANT_
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#
2+
# Generated file, do not edit.
3+
#
4+
5+
list(APPEND FLUTTER_PLUGIN_LIST
6+
screen_retriever_windows
7+
tray_manager
8+
window_manager
9+
)
10+
11+
list(APPEND FLUTTER_FFI_PLUGIN_LIST
12+
)
13+
14+
set(PLUGIN_BUNDLED_LIBRARIES)
15+
16+
foreach(plugin ${FLUTTER_PLUGIN_LIST})
17+
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin})
18+
target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin)
19+
list(APPEND PLUGIN_BUNDLED_LIBRARIES $<TARGET_FILE:${plugin}_plugin>)
20+
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
21+
endforeach(plugin)
22+
23+
foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
24+
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin})
25+
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
26+
endforeach(ffi_plugin)

packages/window_manager/example/windows/runner/CMakeLists.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
cmake_minimum_required(VERSION 3.14)
22
project(runner LANGUAGES CXX)
33

4+
# Define the application target. To change its name, change BINARY_NAME in the
5+
# top-level CMakeLists.txt, not the value here, or `flutter run` will no longer
6+
# work.
7+
#
8+
# Any new source files that you add to the application should be added here.
49
add_executable(${BINARY_NAME} WIN32
510
"flutter_window.cpp"
611
"main.cpp"
@@ -10,8 +15,26 @@ add_executable(${BINARY_NAME} WIN32
1015
"Runner.rc"
1116
"runner.exe.manifest"
1217
)
18+
19+
# Apply the standard set of build settings. This can be removed for applications
20+
# that need different build settings.
1321
apply_standard_settings(${BINARY_NAME})
22+
23+
# Add preprocessor definitions for the build version.
24+
target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"")
25+
target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}")
26+
target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}")
27+
target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}")
28+
target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}")
29+
30+
# Disable Windows macros that collide with C++ standard library functions.
1431
target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX")
32+
33+
# Add dependency libraries and include directories. Add any application-specific
34+
# dependencies here.
1535
target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app)
36+
target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib")
1637
target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}")
38+
39+
# Run the Flutter tool portions of the build. This must not be removed.
1740
add_dependencies(${BINARY_NAME} flutter_assemble)

packages/window_manager/example/windows/runner/flutter_window.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ bool FlutterWindow::OnCreate() {
2626
}
2727
RegisterPlugins(flutter_controller_->engine());
2828
SetChildContent(flutter_controller_->view()->GetNativeWindow());
29+
30+
flutter_controller_->engine()->SetNextFrameCallback([&]() {
31+
this->Show();
32+
});
33+
34+
// Flutter can complete the first frame before the "show window" callback is
35+
// registered. The following call ensures a frame is pending to ensure the
36+
// window is shown. It is a no-op if the first frame hasn't completed yet.
37+
flutter_controller_->ForceRedraw();
38+
2939
return true;
3040
}
3141

packages/window_manager/example/windows/runner/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
2727
FlutterWindow window(project);
2828
Win32Window::Point origin(10, 10);
2929
Win32Window::Size size(1280, 720);
30-
if (!window.CreateAndShow(L"window_manager_example", origin, size)) {
30+
if (!window.Create(L"window_manager_example", origin, size)) {
3131
return EXIT_FAILURE;
3232
}
3333
window.SetQuitOnClose(true);

packages/window_manager/example/windows/runner/runner.exe.manifest

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,8 @@
77
</application>
88
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
99
<application>
10-
<!-- Windows 10 -->
10+
<!-- Windows 10 and Windows 11 -->
1111
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
12-
<!-- Windows 8.1 -->
13-
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
14-
<!-- Windows 8 -->
15-
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
16-
<!-- Windows 7 -->
17-
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
1812
</application>
1913
</compatibility>
2014
</assembly>

packages/window_manager/example/windows/runner/utils.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,19 @@ std::string Utf8FromUtf16(const wchar_t* utf16_string) {
4545
if (utf16_string == nullptr) {
4646
return std::string();
4747
}
48-
int target_length = ::WideCharToMultiByte(
48+
unsigned int target_length = ::WideCharToMultiByte(
4949
CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string,
50-
-1, nullptr, 0, nullptr, nullptr);
51-
if (target_length == 0) {
52-
return std::string();
53-
}
50+
-1, nullptr, 0, nullptr, nullptr)
51+
-1; // remove the trailing null character
52+
int input_length = (int)wcslen(utf16_string);
5453
std::string utf8_string;
54+
if (target_length == 0 || target_length > utf8_string.max_size()) {
55+
return utf8_string;
56+
}
5557
utf8_string.resize(target_length);
5658
int converted_length = ::WideCharToMultiByte(
5759
CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string,
58-
-1, utf8_string.data(),
59-
target_length, nullptr, nullptr);
60+
input_length, utf8_string.data(), target_length, nullptr, nullptr);
6061
if (converted_length == 0) {
6162
return std::string();
6263
}

0 commit comments

Comments
 (0)