Skip to content

Commit 4806024

Browse files
committed
recreate windows project template.
1 parent b41a14a commit 4806024

17 files changed

Lines changed: 213 additions & 209 deletions

example/macos/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ SPEC CHECKSUMS:
1919

2020
PODFILE CHECKSUM: 6eac6b3292e5142cfc23bdeb71848a40ec51c14c
2121

22-
COCOAPODS: 1.10.1
22+
COCOAPODS: 1.11.2

example/windows/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.15)
1+
cmake_minimum_required(VERSION 3.14)
22
project(example LANGUAGES CXX)
33

44
set(BINARY_NAME "example")

example/windows/flutter/.template_version

Lines changed: 0 additions & 1 deletion
This file was deleted.

example/windows/flutter/CMakeLists.txt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.15)
1+
cmake_minimum_required(VERSION 3.14)
22

33
set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral")
44

@@ -23,6 +23,7 @@ list(APPEND FLUTTER_LIBRARY_HEADERS
2323
"flutter_windows.h"
2424
"flutter_messenger.h"
2525
"flutter_plugin_registrar.h"
26+
"flutter_texture_registrar.h"
2627
)
2728
list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/")
2829
add_library(flutter INTERFACE)
@@ -34,15 +35,16 @@ add_dependencies(flutter flutter_assemble)
3435

3536
# === Wrapper ===
3637
list(APPEND CPP_WRAPPER_SOURCES_CORE
37-
"engine_method_result.cc"
38-
"standard_codec.cc"
38+
"core_implementations.cc"
39+
"standard_codec.cc"
3940
)
4041
list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/")
4142
list(APPEND CPP_WRAPPER_SOURCES_PLUGIN
4243
"plugin_registrar.cc"
4344
)
4445
list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/")
4546
list(APPEND CPP_WRAPPER_SOURCES_APP
47+
"flutter_engine.cc"
4648
"flutter_view_controller.cc"
4749
)
4850
list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/")
@@ -79,15 +81,18 @@ add_dependencies(flutter_wrapper_app flutter_assemble)
7981
# _phony_ is a non-existent file to force this command to run every time,
8082
# since currently there's no way to get a full input/output list from the
8183
# flutter tool.
84+
set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_")
85+
set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE)
8286
add_custom_command(
8387
OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS}
8488
${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN}
8589
${CPP_WRAPPER_SOURCES_APP}
86-
${CMAKE_CURRENT_BINARY_DIR}/_phony_
90+
${PHONY_OUTPUT}
8791
COMMAND ${CMAKE_COMMAND} -E env
8892
${FLUTTER_TOOL_ENVIRONMENT}
8993
"${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat"
9094
windows-x64 $<CONFIG>
95+
VERBATIM
9196
)
9297
add_custom_target(flutter_assemble DEPENDS
9398
"${FLUTTER_LIBRARY}"
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
cmake_minimum_required(VERSION 3.15)
1+
cmake_minimum_required(VERSION 3.14)
22
project(runner LANGUAGES CXX)
33

44
add_executable(${BINARY_NAME} WIN32
55
"flutter_window.cpp"
66
"main.cpp"
7-
"run_loop.cpp"
87
"utils.cpp"
98
"win32_window.cpp"
10-
"window_configuration.cpp"
119
"${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
1210
"Runner.rc"
1311
"runner.exe.manifest"
1412
)
1513
apply_standard_settings(${BINARY_NAME})
14+
target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX")
1615
target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app)
1716
target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}")
1817
add_dependencies(${BINARY_NAME} flutter_assemble)

example/windows/runner/Runner.rc

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,57 @@ END
5454
// remains consistent on all systems.
5555
IDI_APP_ICON ICON "resources\\app_icon.ico"
5656

57+
58+
/////////////////////////////////////////////////////////////////////////////
59+
//
60+
// Version
61+
//
62+
63+
#ifdef FLUTTER_BUILD_NUMBER
64+
#define VERSION_AS_NUMBER FLUTTER_BUILD_NUMBER
65+
#else
66+
#define VERSION_AS_NUMBER 1,0,0
67+
#endif
68+
69+
#ifdef FLUTTER_BUILD_NAME
70+
#define VERSION_AS_STRING #FLUTTER_BUILD_NAME
71+
#else
72+
#define VERSION_AS_STRING "1.0.0"
73+
#endif
74+
75+
VS_VERSION_INFO VERSIONINFO
76+
FILEVERSION VERSION_AS_NUMBER
77+
PRODUCTVERSION VERSION_AS_NUMBER
78+
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
79+
#ifdef _DEBUG
80+
FILEFLAGS VS_FF_DEBUG
81+
#else
82+
FILEFLAGS 0x0L
83+
#endif
84+
FILEOS VOS__WINDOWS32
85+
FILETYPE VFT_APP
86+
FILESUBTYPE 0x0L
87+
BEGIN
88+
BLOCK "StringFileInfo"
89+
BEGIN
90+
BLOCK "040904e4"
91+
BEGIN
92+
VALUE "CompanyName", "design.codeux" "\0"
93+
VALUE "FileDescription", "example" "\0"
94+
VALUE "FileVersion", VERSION_AS_STRING "\0"
95+
VALUE "InternalName", "example" "\0"
96+
VALUE "LegalCopyright", "Copyright (C) 2022 design.codeux. All rights reserved." "\0"
97+
VALUE "OriginalFilename", "example.exe" "\0"
98+
VALUE "ProductName", "example" "\0"
99+
VALUE "ProductVersion", VERSION_AS_STRING "\0"
100+
END
101+
END
102+
BLOCK "VarFileInfo"
103+
BEGIN
104+
VALUE "Translation", 0x409, 1252
105+
END
106+
END
107+
57108
#endif // English (United States) resources
58109
/////////////////////////////////////////////////////////////////////////////
59110

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,61 @@
11
#include "flutter_window.h"
22

3+
#include <optional>
4+
35
#include "flutter/generated_plugin_registrant.h"
46

5-
FlutterWindow::FlutterWindow(RunLoop* run_loop,
6-
const flutter::DartProject& project)
7-
: run_loop_(run_loop), project_(project) {}
7+
FlutterWindow::FlutterWindow(const flutter::DartProject& project)
8+
: project_(project) {}
89

910
FlutterWindow::~FlutterWindow() {}
1011

11-
void FlutterWindow::OnCreate() {
12-
Win32Window::OnCreate();
12+
bool FlutterWindow::OnCreate() {
13+
if (!Win32Window::OnCreate()) {
14+
return false;
15+
}
16+
17+
RECT frame = GetClientArea();
1318

14-
// The size here is arbitrary since SetChildContent will resize it.
15-
flutter_controller_ =
16-
std::make_unique<flutter::FlutterViewController>(100, 100, project_);
17-
RegisterPlugins(flutter_controller_.get());
18-
run_loop_->RegisterFlutterInstance(flutter_controller_.get());
19+
// The size here must match the window dimensions to avoid unnecessary surface
20+
// creation / destruction in the startup path.
21+
flutter_controller_ = std::make_unique<flutter::FlutterViewController>(
22+
frame.right - frame.left, frame.bottom - frame.top, project_);
23+
// Ensure that basic setup of the controller was successful.
24+
if (!flutter_controller_->engine() || !flutter_controller_->view()) {
25+
return false;
26+
}
27+
RegisterPlugins(flutter_controller_->engine());
1928
SetChildContent(flutter_controller_->view()->GetNativeWindow());
29+
return true;
2030
}
2131

2232
void FlutterWindow::OnDestroy() {
2333
if (flutter_controller_) {
24-
run_loop_->UnregisterFlutterInstance(flutter_controller_.get());
2534
flutter_controller_ = nullptr;
2635
}
2736

2837
Win32Window::OnDestroy();
2938
}
39+
40+
LRESULT
41+
FlutterWindow::MessageHandler(HWND hwnd, UINT const message,
42+
WPARAM const wparam,
43+
LPARAM const lparam) noexcept {
44+
// Give Flutter, including plugins, an opportunity to handle window messages.
45+
if (flutter_controller_) {
46+
std::optional<LRESULT> result =
47+
flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam,
48+
lparam);
49+
if (result) {
50+
return *result;
51+
}
52+
}
53+
54+
switch (message) {
55+
case WM_FONTCHANGE:
56+
flutter_controller_->engine()->ReloadSystemFonts();
57+
break;
58+
}
59+
60+
return Win32Window::MessageHandler(hwnd, message, wparam, lparam);
61+
}
Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,33 @@
1-
#ifndef FLUTTER_WINDOW_H_
2-
#define FLUTTER_WINDOW_H_
1+
#ifndef RUNNER_FLUTTER_WINDOW_H_
2+
#define RUNNER_FLUTTER_WINDOW_H_
33

44
#include <flutter/dart_project.h>
55
#include <flutter/flutter_view_controller.h>
66

7-
#include "run_loop.h"
8-
#include "win32_window.h"
9-
107
#include <memory>
118

9+
#include "win32_window.h"
10+
1211
// A window that does nothing but host a Flutter view.
1312
class FlutterWindow : public Win32Window {
1413
public:
15-
// Creates a new FlutterWindow driven by the |run_loop|, hosting a
16-
// Flutter view running |project|.
17-
explicit FlutterWindow(RunLoop* run_loop,
18-
const flutter::DartProject& project);
14+
// Creates a new FlutterWindow hosting a Flutter view running |project|.
15+
explicit FlutterWindow(const flutter::DartProject& project);
1916
virtual ~FlutterWindow();
2017

2118
protected:
2219
// Win32Window:
23-
void OnCreate() override;
20+
bool OnCreate() override;
2421
void OnDestroy() override;
22+
LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam,
23+
LPARAM const lparam) noexcept override;
2524

2625
private:
27-
// The run loop driving events for this window.
28-
RunLoop* run_loop_;
29-
3026
// The project to run.
3127
flutter::DartProject project_;
3228

3329
// The Flutter instance hosted by this window.
3430
std::unique_ptr<flutter::FlutterViewController> flutter_controller_;
3531
};
3632

37-
#endif // FLUTTER_WINDOW_H_
33+
#endif // RUNNER_FLUTTER_WINDOW_H_

example/windows/runner/main.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
#include <windows.h>
44

55
#include "flutter_window.h"
6-
#include "run_loop.h"
76
#include "utils.h"
8-
#include "window_configuration.h"
97

108
int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
119
_In_ wchar_t *command_line, _In_ int show_command) {
@@ -19,18 +17,26 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
1917
// plugins.
2018
::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
2119

22-
RunLoop run_loop;
23-
2420
flutter::DartProject project(L"data");
25-
FlutterWindow window(&run_loop, project);
26-
Win32Window::Point origin(kFlutterWindowOriginX, kFlutterWindowOriginY);
27-
Win32Window::Size size(kFlutterWindowWidth, kFlutterWindowHeight);
28-
if (!window.CreateAndShow(kFlutterWindowTitle, origin, size)) {
21+
22+
std::vector<std::string> command_line_arguments =
23+
GetCommandLineArguments();
24+
25+
project.set_dart_entrypoint_arguments(std::move(command_line_arguments));
26+
27+
FlutterWindow window(project);
28+
Win32Window::Point origin(10, 10);
29+
Win32Window::Size size(1280, 720);
30+
if (!window.CreateAndShow(L"example", origin, size)) {
2931
return EXIT_FAILURE;
3032
}
3133
window.SetQuitOnClose(true);
3234

33-
run_loop.Run();
35+
::MSG msg;
36+
while (::GetMessage(&msg, nullptr, 0, 0)) {
37+
::TranslateMessage(&msg);
38+
::DispatchMessage(&msg);
39+
}
3440

3541
::CoUninitialize();
3642
return EXIT_SUCCESS;

example/windows/runner/run_loop.cpp

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)