Skip to content

Commit 8ea2d84

Browse files
committed
[desktop_webview_window] Improve import on Windows
1 parent 28d6331 commit 8ea2d84

File tree

11 files changed

+16
-168
lines changed

11 files changed

+16
-168
lines changed

packages/desktop_webview_window/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.1.3 (2021/11/25)
2+
3+
Remove windows addition import requirements.
4+
15
## 0.1.2 (2021/11/24)
26

37
fix TitleBar reload do not work.

packages/desktop_webview_window/README.md

+1-16
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,7 @@ Show a webview window on your flutter deksktop application.
3030
3131
```
3232

33-
2. platform Windows.
34-
35-
* add this include to your `windows/runner/flutter_window.cpp`
36-
```cpp
37-
#include "desktop_webview_window/desktop_webview_window_plugin.h"
38-
```
39-
* append this statement to your `flutter_window.cpp` `FlutterWindow::OnCreate()` method
40-
```cpp
41-
bool FlutterWindow::OnCreate() {
42-
...
43-
// Add this line
44-
SetFlutterViewControllerFactory(std::make_unique<WebviewWindowAdapter>());
45-
}
46-
```
47-
48-
3. launch WebViewWindow
33+
2. launch WebViewWindow
4934

5035
```dart
5136
final webview = await WebviewWindow.create();

packages/desktop_webview_window/example/pubspec.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ packages:
5656
path: ".."
5757
relative: true
5858
source: path
59-
version: "0.1.0"
59+
version: "0.1.3"
6060
fake_async:
6161
dependency: transitive
6262
description:

packages/desktop_webview_window/example/windows/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ add_definitions(-DUNICODE -D_UNICODE)
3232
# Compilation settings that should be applied to most targets.
3333
function(APPLY_STANDARD_SETTINGS TARGET)
3434
target_compile_features(${TARGET} PUBLIC cxx_std_17)
35-
# target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100")
35+
target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100")
3636
target_compile_options(${TARGET} PRIVATE /EHsc)
3737
target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0")
3838
target_compile_definitions(${TARGET} PRIVATE "$<$<CONFIG:Debug>:_DEBUG>")

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

-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include <optional>
44

55
#include "flutter/generated_plugin_registrant.h"
6-
#include "desktop_webview_window/desktop_webview_window_plugin.h"
76

87
FlutterWindow::FlutterWindow(const flutter::DartProject &project)
98
: project_(project) {}
@@ -27,7 +26,6 @@ bool FlutterWindow::OnCreate() {
2726
}
2827
RegisterPlugins(flutter_controller_->engine());
2928
SetChildContent(flutter_controller_->view()->GetNativeWindow());
30-
SetFlutterViewControllerFactory(std::make_unique<WebviewWindowAdapter>());
3129
return true;
3230
}
3331

packages/desktop_webview_window/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: desktop_webview_window
22
description: Show a webview window on your flutter deksktop application.
3-
version: 0.1.2
3+
version: 0.1.3
44
homepage: https://github.com/MixinNetwork/flutter-plugins/tree/main/packages/desktop_webview_window
55

66
environment:

packages/desktop_webview_window/windows/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ set_target_properties(${PLUGIN_NAME} PROPERTIES
2929
target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL)
3030
target_include_directories(${PLUGIN_NAME} INTERFACE
3131
"${CMAKE_CURRENT_SOURCE_DIR}/include")
32-
target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin)
32+
target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin flutter_wrapper_app)
3333

3434
add_library(Webview2 SHARED IMPORTED GLOBAL)
3535
SET_PROPERTY(TARGET Webview2 PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/x64/Webview2Loader.dll)

packages/desktop_webview_window/windows/flutter_view.cc

+4-16
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,11 @@
55
#include <windows.h>
66
#include "flutter_view.h"
77

8-
#include <cassert>
98
#include <iostream>
109

11-
#include "include/desktop_webview_window/desktop_webview_window_plugin.h"
1210
#include "utils.h"
1311
#include "message_channel_plugin.h"
1412

15-
namespace {
16-
17-
std::unique_ptr<WebviewWindowAdapter> flutter_webview_window_adapter;
18-
19-
}
20-
2113
namespace webview_window {
2214

2315
FlutterView::FlutterView(std::vector<std::string> arguments) {
@@ -26,7 +18,7 @@ FlutterView::FlutterView(std::vector<std::string> arguments) {
2618
project.set_dart_entrypoint_arguments(std::move(arguments));
2719
// The size here must match the window dimensions to avoid unnecessary surface
2820
// creation / destruction in the startup path.
29-
flutter_controller_ = flutter_webview_window_adapter->CreateViewController(0, 0, project);
21+
flutter_controller_ = std::make_unique<flutter::FlutterViewController>(0, 0, project);
3022
// Ensure that basic setup of the controller was successful.
3123
if (!flutter_controller_->engine() || !flutter_controller_->view()) {
3224
std::cerr << "Failed to setup Flutter engine." << std::endl;
@@ -42,20 +34,16 @@ FlutterView::~FlutterView() {
4234
}
4335

4436
std::optional<LRESULT> FlutterView::HandleTopLevelWindowProc(HWND hwnd, UINT message, WPARAM w_param, LPARAM l_param) {
45-
return flutter_webview_window_adapter->HandleTopLevelWindowProc(flutter_controller_, hwnd, message, w_param, l_param);
37+
return flutter_controller_->HandleTopLevelWindowProc(hwnd, message, w_param, l_param);
4638
}
4739

4840
void FlutterView::ReloadSystemFonts() {
49-
flutter_webview_window_adapter->ReloadSystemFonts(flutter_controller_);
41+
flutter_controller_->engine()->ReloadSystemFonts();
5042
}
5143

5244
void FlutterView::ForceRedraw() {
53-
}
5445

5546
}
5647

57-
void SetFlutterViewControllerFactory(std::unique_ptr<WebviewWindowAdapter> adapter) {
58-
assert(adapter != nullptr);
59-
assert(flutter_webview_window_adapter == nullptr);
60-
flutter_webview_window_adapter = std::move(adapter);
6148
}
49+

packages/desktop_webview_window/windows/include/desktop_webview_window/desktop_webview_window_plugin.h

-28
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,4 @@ FLUTTER_PLUGIN_EXPORT void DesktopWebviewWindowPluginRegisterWithRegistrar(
2323
} // extern "C"
2424
#endif
2525

26-
class WebviewWindowAdapter {
27-
public:
28-
virtual std::unique_ptr<flutter::FlutterViewController> CreateViewController(
29-
int width,
30-
int height,
31-
const flutter::DartProject &project
32-
) {
33-
return std::make_unique<flutter::FlutterViewController>(width, height, project);
34-
}
35-
36-
virtual std::optional<LRESULT> HandleTopLevelWindowProc(
37-
const std::unique_ptr<flutter::FlutterViewController> &flutter_view_controller,
38-
HWND hwnd,
39-
UINT message,
40-
WPARAM wparam,
41-
LPARAM lparam
42-
) {
43-
return flutter_view_controller->HandleTopLevelWindowProc(hwnd, message, wparam, lparam);
44-
}
45-
46-
virtual void ReloadSystemFonts(const std::unique_ptr<flutter::FlutterViewController> &flutter_view_controller) {
47-
flutter_view_controller->engine()->ReloadSystemFonts();
48-
}
49-
50-
};
51-
52-
FLUTTER_PLUGIN_EXPORT void SetFlutterViewControllerFactory(std::unique_ptr<WebviewWindowAdapter> adapter);
53-
5426
#endif // FLUTTER_PLUGIN_WEBVIEW_WINDOW_PLUGIN_H_

packages/desktop_webview_window/windows/utils.cc

+2-101
Original file line numberDiff line numberDiff line change
@@ -9,83 +9,6 @@
99
#include <memory>
1010
#include <set>
1111

12-
namespace {
13-
14-
// https://github.com/alexmercerind/flutter_acrylic/blob/master/windows/flutter_acrylic_plugin.cpp
15-
// flutter_acrylic_plugin BEGIN
16-
17-
typedef enum _WINDOWCOMPOSITIONATTRIB {
18-
WCA_UNDEFINED = 0,
19-
WCA_NCRENDERING_ENABLED = 1,
20-
WCA_NCRENDERING_POLICY = 2,
21-
WCA_TRANSITIONS_FORCEDISABLED = 3,
22-
WCA_ALLOW_NCPAINT = 4,
23-
WCA_CAPTION_BUTTON_BOUNDS = 5,
24-
WCA_NONCLIENT_RTL_LAYOUT = 6,
25-
WCA_FORCE_ICONIC_REPRESENTATION = 7,
26-
WCA_EXTENDED_FRAME_BOUNDS = 8,
27-
WCA_HAS_ICONIC_BITMAP = 9,
28-
WCA_THEME_ATTRIBUTES = 10,
29-
WCA_NCRENDERING_EXILED = 11,
30-
WCA_NCADORNMENTINFO = 12,
31-
WCA_EXCLUDED_FROM_LIVEPREVIEW = 13,
32-
WCA_VIDEO_OVERLAY_ACTIVE = 14,
33-
WCA_FORCE_ACTIVEWINDOW_APPEARANCE = 15,
34-
WCA_DISALLOW_PEEK = 16,
35-
WCA_CLOAK = 17,
36-
WCA_CLOAKED = 18,
37-
WCA_ACCENT_POLICY = 19,
38-
WCA_FREEZE_REPRESENTATION = 20,
39-
WCA_EVER_UNCLOAKED = 21,
40-
WCA_VISUAL_OWNER = 22,
41-
WCA_HOLOGRAPHIC = 23,
42-
WCA_EXCLUDED_FROM_DDA = 24,
43-
WCA_PASSIVEUPDATEMODE = 25,
44-
WCA_USEDARKMODECOLORS = 26,
45-
WCA_LAST = 27
46-
} WINDOWCOMPOSITIONATTRIB;
47-
48-
typedef struct _WINDOWCOMPOSITIONATTRIBDATA {
49-
WINDOWCOMPOSITIONATTRIB Attrib;
50-
PVOID pvData;
51-
SIZE_T cbData;
52-
} WINDOWCOMPOSITIONATTRIBDATA;
53-
54-
typedef enum _ACCENT_STATE {
55-
ACCENT_DISABLED = 0,
56-
ACCENT_ENABLE_GRADIENT = 1,
57-
ACCENT_ENABLE_TRANSPARENTGRADIENT = 2,
58-
ACCENT_ENABLE_BLURBEHIND = 3,
59-
ACCENT_ENABLE_ACRYLICBLURBEHIND = 4,
60-
ACCENT_ENABLE_HOSTBACKDROP = 5,
61-
ACCENT_INVALID_STATE = 6
62-
} ACCENT_STATE;
63-
64-
typedef struct _ACCENT_POLICY {
65-
ACCENT_STATE AccentState;
66-
DWORD AccentFlags;
67-
DWORD GradientColor;
68-
DWORD AnimationId;
69-
} ACCENT_POLICY;
70-
71-
typedef BOOL(WINAPI *GetWindowCompositionAttribute)(
72-
HWND, WINDOWCOMPOSITIONATTRIBDATA *);
73-
typedef BOOL(WINAPI *SetWindowCompositionAttribute)(
74-
HWND, WINDOWCOMPOSITIONATTRIBDATA *);
75-
76-
typedef LONG NTSTATUS, *PNTSTATUS;
77-
#define STATUS_SUCCESS (0x00000000)
78-
79-
typedef NTSTATUS(WINAPI *RtlGetVersionPtr)(PRTL_OSVERSIONINFOW);
80-
81-
82-
// flutter_acrylic_plugin END
83-
84-
HMODULE user32 = nullptr;
85-
86-
SetWindowCompositionAttribute set_window_composition_attribute_ = nullptr;
87-
88-
}
8912

9013
namespace webview_window {
9114

@@ -136,30 +59,8 @@ void ClipOrCenterWindowToMonitor(HWND hwnd, UINT flags) {
13659
}
13760

13861
bool SetWindowBackgroundTransparent(HWND hwnd) {
139-
if (user32 == nullptr) {
140-
user32 = GetModuleHandleA("user32.dll");
141-
if (user32 == nullptr) {
142-
return false;
143-
}
144-
set_window_composition_attribute_ =
145-
reinterpret_cast<SetWindowCompositionAttribute>(
146-
::GetProcAddress(user32, "SetWindowCompositionAttribute"));
147-
if (!set_window_composition_attribute_) {
148-
return false;
149-
}
150-
}
151-
152-
ACCENT_POLICY accent = {
153-
ACCENT_ENABLE_TRANSPARENTGRADIENT, 2,
154-
0,
155-
0};
156-
WINDOWCOMPOSITIONATTRIBDATA data;
157-
data.Attrib = WCA_ACCENT_POLICY;
158-
data.pvData = &accent;
159-
data.cbData = sizeof(accent);
160-
set_window_composition_attribute_(hwnd, &data);
161-
162-
return true;
62+
// TODO
63+
return false;
16364
}
16465

16566
static std::unique_ptr<std::set<LPCWSTR>> class_registered_;

packages/desktop_webview_window/windows/web_view_window_plugin.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void WebviewWindowPlugin::HandleMethodCall(
5858

5959
auto window_id = next_window_id_;
6060
auto window = std::make_unique<WebviewWindow>(
61-
method_channel_, window_id, titleBarHeight,
61+
method_channel_, window_id, int(titleBarHeight),
6262
[this, window_id]() {
6363
windows_.erase(window_id);
6464
});

0 commit comments

Comments
 (0)