Merge branch 'master' into master

This commit is contained in:
ekibun
2020-08-17 21:33:41 +08:00
committed by GitHub
24 changed files with 482 additions and 201 deletions

View File

@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.15)
project(flutter_qjs_example LANGUAGES CXX)
project(example LANGUAGES CXX)
set(BINARY_NAME "flutter_qjs_example")
set(BINARY_NAME "example")
cmake_policy(SET CMP0063 NEW)

View File

@@ -1 +1 @@
4
5

View File

@@ -43,6 +43,7 @@ list(APPEND CPP_WRAPPER_SOURCES_PLUGIN
)
list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/")
list(APPEND CPP_WRAPPER_SOURCES_APP
"flutter_engine.cc"
"flutter_view_controller.cc"
)
list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/")
@@ -79,11 +80,13 @@ add_dependencies(flutter_wrapper_app flutter_assemble)
# _phony_ is a non-existent file to force this command to run every time,
# since currently there's no way to get a full input/output list from the
# flutter tool.
set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_")
set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE)
add_custom_command(
OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS}
${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN}
${CPP_WRAPPER_SOURCES_APP}
${CMAKE_CURRENT_BINARY_DIR}/_phony_
${PHONY_OUTPUT}
COMMAND ${CMAKE_COMMAND} -E env
${FLUTTER_TOOL_ENVIRONMENT}
"${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat"

View File

@@ -8,15 +8,22 @@ FlutterWindow::FlutterWindow(RunLoop* run_loop,
FlutterWindow::~FlutterWindow() {}
void FlutterWindow::OnCreate() {
Win32Window::OnCreate();
bool FlutterWindow::OnCreate() {
if (!Win32Window::OnCreate()) {
return false;
}
// The size here is arbitrary since SetChildContent will resize it.
flutter_controller_ =
std::make_unique<flutter::FlutterViewController>(100, 100, project_);
// Ensure that basic setup of the controller was successful.
if (!flutter_controller_->engine() || !flutter_controller_->view()) {
return false;
}
RegisterPlugins(flutter_controller_.get());
run_loop_->RegisterFlutterInstance(flutter_controller_.get());
SetChildContent(flutter_controller_->view()->GetNativeWindow());
return true;
}
void FlutterWindow::OnDestroy() {

View File

@@ -20,7 +20,7 @@ class FlutterWindow : public Win32Window {
protected:
// Win32Window:
void OnCreate() override;
bool OnCreate() override;
void OnDestroy() override;
private:

View File

@@ -122,9 +122,11 @@ bool Win32Window::CreateAndShow(const std::wstring& title,
Scale(size.width, scale_factor), Scale(size.height, scale_factor),
nullptr, nullptr, GetModuleHandle(nullptr), this);
OnCreate();
if (!window) {
return false;
}
return window != nullptr;
return OnCreate();
}
// static
@@ -240,8 +242,9 @@ void Win32Window::SetQuitOnClose(bool quit_on_close) {
quit_on_close_ = quit_on_close;
}
void Win32Window::OnCreate() {
bool Win32Window::OnCreate() {
// No-op; provided for subclasses.
return true;
}
void Win32Window::OnDestroy() {

View File

@@ -62,8 +62,8 @@ class Win32Window {
LPARAM const lparam) noexcept;
// Called when CreateAndShow is called, allowing subclass window-related
// setup.
virtual void OnCreate();
// setup. Subclasses should return false if setup fails.
virtual bool OnCreate();
// Called when Destroy is called.
virtual void OnDestroy();

View File

@@ -1,6 +1,6 @@
#include "window_configuration.h"
const wchar_t* kFlutterWindowTitle = L"flutter_qjs_example";
const wchar_t* kFlutterWindowTitle = L"example";
const unsigned int kFlutterWindowOriginX = 10;
const unsigned int kFlutterWindowOriginY = 10;
const unsigned int kFlutterWindowWidth = 1280;