Skip to content

Commit a686e6b

Browse files
committed
Recreate windows files
1 parent 0c00c46 commit a686e6b

File tree

9 files changed

+46
-138
lines changed

9 files changed

+46
-138
lines changed

sudoku/windows/CMakeLists.txt

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
cmake_minimum_required(VERSION 3.15)
1+
# Project-level configuration.
2+
cmake_minimum_required(VERSION 3.14)
23
project(sudoku 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 "sudoku")
58

9+
# Explicitly opt in to modern CMake behaviors to avoid warnings with recent
10+
# versions of CMake.
611
cmake_policy(SET CMP0063 NEW)
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,12 +45,11 @@ 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

4955
# Generated plugin build rules, which manage building the plugins and adding

sudoku/windows/flutter/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
cmake_minimum_required(VERSION 3.15)
1+
# This file controls Flutter-level build steps. It should not be edited.
2+
cmake_minimum_required(VERSION 3.14)
23

34
set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral")
45

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,32 @@
1-
cmake_minimum_required(VERSION 3.15)
1+
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"
7-
"run_loop.cpp"
812
"utils.cpp"
913
"win32_window.cpp"
1014
"${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
1115
"Runner.rc"
1216
"runner.exe.manifest"
1317
)
18+
19+
# Apply the standard set of build settings. This can be removed for applications
20+
# that need different build settings.
1421
apply_standard_settings(${BINARY_NAME})
22+
23+
# Disable Windows macros that collide with C++ standard library functions.
1524
target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX")
25+
26+
# Add dependency libraries and include directories. Add any application-specific
27+
# dependencies here.
1628
target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app)
1729
target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}")
30+
31+
# Run the Flutter tool portions of the build. This must not be removed.
1832
add_dependencies(${BINARY_NAME} flutter_assemble)

sudoku/windows/runner/flutter_window.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44

55
#include "flutter/generated_plugin_registrant.h"
66

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

1110
FlutterWindow::~FlutterWindow() {}
1211

@@ -26,14 +25,12 @@ bool FlutterWindow::OnCreate() {
2625
return false;
2726
}
2827
RegisterPlugins(flutter_controller_->engine());
29-
run_loop_->RegisterFlutterInstance(flutter_controller_->engine());
3028
SetChildContent(flutter_controller_->view()->GetNativeWindow());
3129
return true;
3230
}
3331

3432
void FlutterWindow::OnDestroy() {
3533
if (flutter_controller_) {
36-
run_loop_->UnregisterFlutterInstance(flutter_controller_->engine());
3734
flutter_controller_ = nullptr;
3835
}
3936

sudoku/windows/runner/flutter_window.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,13 @@
66

77
#include <memory>
88

9-
#include "run_loop.h"
109
#include "win32_window.h"
1110

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:
@@ -26,9 +23,6 @@ class FlutterWindow : public Win32Window {
2623
LPARAM const lparam) noexcept override;
2724

2825
private:
29-
// The run loop driving events for this window.
30-
RunLoop* run_loop_;
31-
3226
// The project to run.
3327
flutter::DartProject project_;
3428

sudoku/windows/runner/main.cpp

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

55
#include "flutter_window.h"
6-
#include "run_loop.h"
76
#include "utils.h"
87

98
#include <bitsdojo_window_windows/bitsdojo_window_plugin.h>
109
auto bdw = bitsdojo_window_configure(BDW_CUSTOM_FRAME);
1110

11+
1212
int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
1313
_In_ wchar_t *command_line, _In_ int show_command) {
1414
// Attach to console when present (e.g., 'flutter run') or create a
@@ -21,24 +21,26 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
2121
// plugins.
2222
::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
2323

24-
RunLoop run_loop;
25-
2624
flutter::DartProject project(L"data");
2725

2826
std::vector<std::string> command_line_arguments =
2927
GetCommandLineArguments();
3028

3129
project.set_dart_entrypoint_arguments(std::move(command_line_arguments));
3230

33-
FlutterWindow window(&run_loop, project);
31+
FlutterWindow window(project);
3432
Win32Window::Point origin(10, 10);
3533
Win32Window::Size size(800, 800);
3634
if (!window.CreateAndShow(L"Sudoku", origin, size)) {
3735
return EXIT_FAILURE;
3836
}
3937
window.SetQuitOnClose(true);
4038

41-
run_loop.Run();
39+
::MSG msg;
40+
while (::GetMessage(&msg, nullptr, 0, 0)) {
41+
::TranslateMessage(&msg);
42+
::DispatchMessage(&msg);
43+
}
4244

4345
::CoUninitialize();
4446
return EXIT_SUCCESS;

sudoku/windows/runner/run_loop.cpp

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

sudoku/windows/runner/run_loop.h

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

sudoku/windows/runner/utils.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ std::string Utf8FromUtf16(const wchar_t* utf16_string) {
4848
int target_length = ::WideCharToMultiByte(
4949
CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string,
5050
-1, nullptr, 0, nullptr, nullptr);
51-
if (target_length == 0) {
52-
return std::string();
53-
}
5451
std::string utf8_string;
52+
if (target_length == 0 || target_length > utf8_string.max_size()) {
53+
return utf8_string;
54+
}
5555
utf8_string.resize(target_length);
5656
int converted_length = ::WideCharToMultiByte(
5757
CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string,

0 commit comments

Comments
 (0)