Skip to content

Commit a33fdd2

Browse files
committed
Add support for registerJavaScriptMessageHandler on Linux
1 parent 17a099a commit a33fdd2

File tree

7 files changed

+717
-574
lines changed

7 files changed

+717
-574
lines changed

packages/desktop_webview_window/CHANGELOG.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.2.5
2+
3+
* Add support for `registerJavaScriptMessageHandler` and `unregisterJavaScriptMessageHandler` on
4+
Linux. Use `window.webkit.messageHandlers.<handlerName>.postMessage(<message>)` in js
5+
16
## 0.2.4
27

38
* Add backward compatibility with webkit2gtk-4.0 on Linux
@@ -9,16 +14,22 @@
914
## 0.2.2
1015

1116
* fix memory leak on macOS after close webview window.
12-
* Show and Hide Webview window by [@Iri-Hor](https://github.com/Iri-Hor) in [#268](https://github.com/MixinNetwork/flutter-plugins/pull/268)
17+
* Show and Hide Webview window by [@Iri-Hor](https://github.com/Iri-Hor)
18+
in [#268](https://github.com/MixinNetwork/flutter-plugins/pull/268)
1319

1420
## 0.2.1
1521

1622
* add Windows attentions to readme.
1723
* fix linux close sub window cause app exited.
1824
* fix linux webview title bar expanded unexpected.
19-
* More control over webview position and size under windows. [#206](https://github.com/MixinNetwork/flutter-plugins/pull/206) by [Lukas Heinze](https://github.com/Iri-Hor)
20-
* fix zone mismatch [#250](https://github.com/MixinNetwork/flutter-plugins/pull/250) by [CD](https://github.com/459217974)
21-
* fix linux webkit2gtk deprecated error [#246](https://github.com/MixinNetwork/flutter-plugins/pull/246) by [Zhiqiang Zhang](https://github.com/zhangzqs)
25+
* More control over webview position and size under
26+
windows. [#206](https://github.com/MixinNetwork/flutter-plugins/pull/206)
27+
by [Lukas Heinze](https://github.com/Iri-Hor)
28+
* fix zone mismatch [#250](https://github.com/MixinNetwork/flutter-plugins/pull/250)
29+
by [CD](https://github.com/459217974)
30+
* fix linux webkit2gtk deprecated
31+
error [#246](https://github.com/MixinNetwork/flutter-plugins/pull/246)
32+
by [Zhiqiang Zhang](https://github.com/zhangzqs)
2233

2334
## 0.2.0
2435

@@ -63,7 +74,8 @@ NOTE: contains break change. more details see readme.
6374

6475
## 0.0.6
6576

66-
fix swift definition conflict on macOS. [flutter-plugins#17](https://github.com/MixinNetwork/flutter-plugins/issues/17)
77+
fix swift definition conflict on
78+
macOS. [flutter-plugins#17](https://github.com/MixinNetwork/flutter-plugins/issues/17)
6779

6880
## 0.0.5
6981

packages/desktop_webview_window/lib/src/webview_impl.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class WebviewImpl extends Webview {
2525

2626
final ValueNotifier<bool> _isNavigating = ValueNotifier<bool>(false);
2727

28-
OnUrlRequestCallback? _onUrlRequestCallback = null;
28+
OnUrlRequestCallback? _onUrlRequestCallback;
2929

3030
final Set<OnWebMessageReceivedCallback> _onWebMessageReceivedCallbacks = {};
3131

@@ -85,7 +85,7 @@ class WebviewImpl extends Webview {
8585
@override
8686
void registerJavaScriptMessageHandler(
8787
String name, JavaScriptMessageHandler handler) {
88-
if (!Platform.isMacOS) {
88+
if (!(Platform.isMacOS || Platform.isLinux)) {
8989
return;
9090
}
9191
assert(!_closed);
@@ -103,7 +103,7 @@ class WebviewImpl extends Webview {
103103

104104
@override
105105
void unregisterJavaScriptMessageHandler(String name) {
106-
if (!Platform.isMacOS) {
106+
if (!(Platform.isMacOS || Platform.isLinux)) {
107107
return;
108108
}
109109
if (_closed) {
Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,73 @@
1+
# The Flutter tooling requires that developers have CMake 3.10 or later
2+
# installed. You should not increase this version, as doing so will cause
3+
# the plugin to fail to compile for some customers of the plugin.
14
cmake_minimum_required(VERSION 3.10)
5+
6+
# Project-level configuration.
27
set(PROJECT_NAME "desktop_webview_window")
38
project(${PROJECT_NAME} LANGUAGES CXX)
49

510
# This value is used when generating builds using this plugin, so it must
6-
# not be changed
11+
# not be changed.
712
set(PLUGIN_NAME "desktop_webview_window_plugin")
813

14+
15+
# === WebKit and libsoup dependencies ===
916
find_package(PkgConfig REQUIRED)
10-
pkg_check_modules(WebKit IMPORTED_TARGET webkit2gtk-4.1)
17+
18+
# Try webkit2gtk-4.1 first, then fallback to 4.0
19+
pkg_check_modules(WebKit IMPORTED_TARGET webkit2gtk-4.1)
1120
if (NOT WebKit_FOUND)
12-
pkg_check_modules(WebKit REQUIRED IMPORTED_TARGET webkit2gtk-4.0) # for backward compatibility
21+
pkg_check_modules(WebKit REQUIRED IMPORTED_TARGET webkit2gtk-4.0)
1322
endif ()
1423

24+
# Try libsoup-3.0, fallback to libsoup-2.4
1525
pkg_check_modules(LibSoup REQUIRED IMPORTED_TARGET libsoup-3.0)
1626
if (NOT LibSoup_FOUND)
17-
pkg_check_modules(LibSoup REQUIRED IMPORTED_TARGET libsoup-2.4)
18-
endif()
27+
pkg_check_modules(LibSoup REQUIRED IMPORTED_TARGET libsoup-2.4)
28+
endif ()
1929

30+
# Any new source files that you add to the plugin should be added here.
31+
list(APPEND PLUGIN_SOURCES
32+
"desktop_webview_window_plugin.cc"
33+
"webview_window.cc"
34+
"webview_window.h"
35+
"message_channel_plugin.h"
36+
"message_channel_plugin.cc"
37+
)
2038

39+
# Define the plugin library target. Its name must not be changed (see comment
40+
# on PLUGIN_NAME above).
2141
add_library(${PLUGIN_NAME} SHARED
22-
"desktop_webview_window_plugin.cc"
23-
webview_window.cc
24-
webview_window.h
25-
message_channel_plugin.h
26-
message_channel_plugin.cc
27-
)
42+
${PLUGIN_SOURCES}
43+
)
44+
45+
# Apply a standard set of build settings that are configured in the
46+
# application-level CMakeLists.txt. This can be removed for plugins that want
47+
# full control over build settings.
2848
apply_standard_settings(${PLUGIN_NAME})
49+
50+
# Symbols are hidden by default to reduce the chance of accidental conflicts
51+
# between plugins. This should not be removed; any symbols that should be
52+
# exported should be explicitly exported with the FLUTTER_PLUGIN_EXPORT macro.
2953
set_target_properties(${PLUGIN_NAME} PROPERTIES
3054
CXX_VISIBILITY_PRESET hidden)
3155
target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL)
56+
57+
# Source include directories and library dependencies. Add any plugin-spec ific
58+
# dependencies here.
3259
target_include_directories(${PLUGIN_NAME} INTERFACE
3360
"${CMAKE_CURRENT_SOURCE_DIR}/include")
3461
target_link_libraries(${PLUGIN_NAME} PRIVATE flutter)
3562
target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::GTK)
3663
target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::WebKit)
64+
target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::LibSoup)
65+
3766

38-
# List of absolute paths to libraries that should be bundled with the plugin
67+
# List of absolute paths to libraries that should be bundled with the plugin.
68+
# This list could contain prebuilt libraries, or libraries created by an
69+
# external build triggered from this build file.
3970
set(desktop_webview_window_bundled_libraries
4071
""
4172
PARENT_SCOPE
42-
)
73+
)

0 commit comments

Comments
 (0)