Skip to content

Commit bdab0b7

Browse files
committed
feat: update windows project by delete and create
1 parent f26dc52 commit bdab0b7

File tree

10 files changed

+44
-144
lines changed

10 files changed

+44
-144
lines changed

windows/CMakeLists.txt

Lines changed: 15 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(nsysu_ap 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 "nsysu_ap")
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,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)

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

windows/runner/Runner.rc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ BEGIN
9090
BLOCK "040904e4"
9191
BEGIN
9292
VALUE "CompanyName", "com.nsysu" "\0"
93-
VALUE "FileDescription", "A new Flutter project." "\0"
93+
VALUE "FileDescription", "nsysu_ap" "\0"
9494
VALUE "FileVersion", VERSION_AS_STRING "\0"
9595
VALUE "InternalName", "nsysu_ap" "\0"
96-
VALUE "LegalCopyright", "Copyright (C) 2021 com.nsysu. All rights reserved." "\0"
96+
VALUE "LegalCopyright", "Copyright (C) 2023 com.nsysu. All rights reserved." "\0"
9797
VALUE "OriginalFilename", "nsysu_ap.exe" "\0"
9898
VALUE "ProductName", "nsysu_ap" "\0"
9999
VALUE "ProductVersion", VERSION_AS_STRING "\0"

windows/runner/flutter_window.cpp

Lines changed: 8 additions & 6 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,17 @@ 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());
29+
30+
flutter_controller_->engine()->SetNextFrameCallback([&]() {
31+
this->Show();
32+
});
33+
3134
return true;
3235
}
3336

3437
void FlutterWindow::OnDestroy() {
3538
if (flutter_controller_) {
36-
run_loop_->UnregisterFlutterInstance(flutter_controller_->engine());
3739
flutter_controller_ = nullptr;
3840
}
3941

@@ -44,7 +46,7 @@ LRESULT
4446
FlutterWindow::MessageHandler(HWND hwnd, UINT const message,
4547
WPARAM const wparam,
4648
LPARAM const lparam) noexcept {
47-
// Give Flutter, including plugins, an opporutunity to handle window messages.
49+
// Give Flutter, including plugins, an opportunity to handle window messages.
4850
if (flutter_controller_) {
4951
std::optional<LRESULT> result =
5052
flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam,

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

windows/runner/main.cpp

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

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

98
int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
@@ -18,24 +17,26 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
1817
// plugins.
1918
::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
2019

21-
RunLoop run_loop;
22-
2320
flutter::DartProject project(L"data");
2421

2522
std::vector<std::string> command_line_arguments =
2623
GetCommandLineArguments();
2724

2825
project.set_dart_entrypoint_arguments(std::move(command_line_arguments));
2926

30-
FlutterWindow window(&run_loop, project);
27+
FlutterWindow window(project);
3128
Win32Window::Point origin(10, 10);
3229
Win32Window::Size size(1280, 720);
33-
if (!window.CreateAndShow(L"NSYSU AP", origin, size)) {
30+
if (!window.Create(L"nsysu_ap", origin, size)) {
3431
return EXIT_FAILURE;
3532
}
3633
window.SetQuitOnClose(true);
3734

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

4041
::CoUninitialize();
4142
return EXIT_SUCCESS;

windows/runner/run_loop.cpp

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

windows/runner/run_loop.h

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

windows/runner/runner.exe.manifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
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}"/>
1212
<!-- Windows 8.1 -->
1313
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>

windows/runner/utils.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,17 @@ std::string Utf8FromUtf16(const wchar_t* utf16_string) {
4747
}
4848
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)