diff --git a/flutter_inappwebview/lib/src/in_app_webview/in_app_webview_controller.dart b/flutter_inappwebview/lib/src/in_app_webview/in_app_webview_controller.dart index ef61cc4d04..d551c8183f 100644 --- a/flutter_inappwebview/lib/src/in_app_webview/in_app_webview_controller.dart +++ b/flutter_inappwebview/lib/src/in_app_webview/in_app_webview_controller.dart @@ -500,6 +500,8 @@ class InAppWebViewController { ///{@macro flutter_inappwebview_platform_interface.PlatformInAppWebViewController.openDevTools} Future openDevTools() => platform.openDevTools(); + Future setThemeMode(String theme) => platform.setThemeMode(theme); + ///{@macro flutter_inappwebview_platform_interface.PlatformInAppWebViewController.callDevToolsProtocolMethod} Future callDevToolsProtocolMethod( {required String methodName, Map? parameters}) => diff --git a/flutter_inappwebview_platform_interface/lib/src/in_app_webview/platform_inappwebview_controller.dart b/flutter_inappwebview_platform_interface/lib/src/in_app_webview/platform_inappwebview_controller.dart index f009573548..389f8f0435 100644 --- a/flutter_inappwebview_platform_interface/lib/src/in_app_webview/platform_inappwebview_controller.dart +++ b/flutter_inappwebview_platform_interface/lib/src/in_app_webview/platform_inappwebview_controller.dart @@ -2140,6 +2140,11 @@ abstract class PlatformInAppWebViewController extends PlatformInterface 'openDevTools is not implemented on the current platform'); } + Future setThemeMode(String theme) { + throw UnimplementedError( + 'setThemeMode is not implemented on the current platform'); + } + ///{@template flutter_inappwebview_platform_interface.PlatformInAppWebViewController.callDevToolsProtocolMethod} ///Runs an asynchronous `DevToolsProtocol` method. /// diff --git a/flutter_inappwebview_windows/lib/src/in_app_webview/custom_platform_view.dart b/flutter_inappwebview_windows/lib/src/in_app_webview/custom_platform_view.dart index dbffdd7f31..c234cbd2dd 100644 --- a/flutter_inappwebview_windows/lib/src/in_app_webview/custom_platform_view.dart +++ b/flutter_inappwebview_windows/lib/src/in_app_webview/custom_platform_view.dart @@ -431,8 +431,10 @@ class _CustomPlatformViewState extends State } }, onPointerPanZoomUpdate: (ev) { - _controller._setScrollDelta( - ev.panDelta.dx, ev.panDelta.dy); + // _controller._setScrollDelta(ev.panDelta.dx, ev.panDelta.dy); + // Workaround: fix scroll not working using TouchPad + // https://github.com/pichillilorenzo/flutter_inappwebview/issues/2503 + _controller._setScrollDelta(0, ev.panDelta.dy); }, child: MouseRegion( cursor: _cursor, diff --git a/flutter_inappwebview_windows/lib/src/in_app_webview/in_app_webview_controller.dart b/flutter_inappwebview_windows/lib/src/in_app_webview/in_app_webview_controller.dart index 03e5dc0407..ae82590389 100644 --- a/flutter_inappwebview_windows/lib/src/in_app_webview/in_app_webview_controller.dart +++ b/flutter_inappwebview_windows/lib/src/in_app_webview/in_app_webview_controller.dart @@ -2727,6 +2727,13 @@ class WindowsInAppWebViewController extends PlatformInAppWebViewController await channel?.invokeMethod('openDevTools', args); } + @override + Future setThemeMode(String theme) async { + Map args = {}; + args.putIfAbsent('theme', () => theme); + await channel?.invokeMethod('setThemeMode', args); + } + @override Future callDevToolsProtocolMethod( {required String methodName, Map? parameters}) async { diff --git a/flutter_inappwebview_windows/windows/custom_platform_view/texture_bridge_gpu.cc b/flutter_inappwebview_windows/windows/custom_platform_view/texture_bridge_gpu.cc index c3bdee2665..7f9fb51bf7 100644 --- a/flutter_inappwebview_windows/windows/custom_platform_view/texture_bridge_gpu.cc +++ b/flutter_inappwebview_windows/windows/custom_platform_view/texture_bridge_gpu.cc @@ -19,6 +19,13 @@ namespace flutter_inappwebview_plugin void TextureBridgeGpu::ProcessFrame( winrt::com_ptr src_texture) { + if (!graphics_context_) { + return; + } + auto device_context = graphics_context_->d3d_device_context(); + if (!device_context) { + return; + } D3D11_TEXTURE2D_DESC desc; src_texture->GetDesc(&desc); @@ -27,8 +34,6 @@ namespace flutter_inappwebview_plugin EnsureSurface(width, height); - auto device_context = graphics_context_->d3d_device_context(); - device_context->CopyResource(surface_.get(), src_texture.get()); device_context->Flush(); } diff --git a/flutter_inappwebview_windows/windows/in_app_webview/in_app_webview.cpp b/flutter_inappwebview_windows/windows/in_app_webview/in_app_webview.cpp index 950d245c99..9cd43b6e2f 100644 --- a/flutter_inappwebview_windows/windows/in_app_webview/in_app_webview.cpp +++ b/flutter_inappwebview_windows/windows/in_app_webview/in_app_webview.cpp @@ -26,6 +26,7 @@ #include "in_app_webview.h" #include "in_app_webview_manager.h" + namespace flutter_inappwebview_plugin { using namespace Microsoft::WRL; @@ -1995,6 +1996,26 @@ namespace flutter_inappwebview_plugin failedLog(webView->OpenDevToolsWindow()); } + void InAppWebView::setThemeMode(const std::string& theme) const + { + if (!webView) { + return; + } + ComPtr coreWebView2_13; + if (SUCCEEDED(webView->QueryInterface(IID_ICoreWebView2_13, &coreWebView2_13))) { + ComPtr profile; + if (SUCCEEDED(coreWebView2_13->get_Profile(&profile))) { + if (profile) { + if (theme == "dark") { + profile->put_PreferredColorScheme(COREWEBVIEW2_PREFERRED_COLOR_SCHEME_DARK); + } else if (theme == "light") { + profile->put_PreferredColorScheme(COREWEBVIEW2_PREFERRED_COLOR_SCHEME_LIGHT); + } + } + } + } + } + void InAppWebView::callDevToolsProtocolMethod(const std::string& methodName, const std::optional& parametersAsJson, const std::function&)> completionHandler) const { if (!webView) { diff --git a/flutter_inappwebview_windows/windows/in_app_webview/in_app_webview.h b/flutter_inappwebview_windows/windows/in_app_webview/in_app_webview.h index b7b27861c1..c709f056e9 100644 --- a/flutter_inappwebview_windows/windows/in_app_webview/in_app_webview.h +++ b/flutter_inappwebview_windows/windows/in_app_webview/in_app_webview.h @@ -171,6 +171,7 @@ namespace flutter_inappwebview_plugin void setSettings(const std::shared_ptr newSettings, const flutter::EncodableMap& newSettingsMap); flutter::EncodableValue getSettings() const; void openDevTools() const; + void setThemeMode(const std::string& theme) const; void callDevToolsProtocolMethod(const std::string& methodName, const std::optional& parametersAsJson, const std::function&)> completionHandler) const; void addDevToolsProtocolEventListener(const std::string& eventName); void removeDevToolsProtocolEventListener(const std::string& eventName); diff --git a/flutter_inappwebview_windows/windows/in_app_webview/in_app_webview_manager.cpp b/flutter_inappwebview_windows/windows/in_app_webview/in_app_webview_manager.cpp index 8a03dbd330..d546d75826 100644 --- a/flutter_inappwebview_windows/windows/in_app_webview/in_app_webview_manager.cpp +++ b/flutter_inappwebview_windows/windows/in_app_webview/in_app_webview_manager.cpp @@ -255,6 +255,19 @@ namespace flutter_inappwebview_plugin webViews.clear(); keepAliveWebViews.clear(); windowWebViews.clear(); + if (compositor_) { + compositor_->Release(); + compositor_ = nullptr; + } + if (graphics_context_) { + graphics_context_.reset(); + } + if (dispatcher_queue_controller_) { + dispatcher_queue_controller_ = nullptr; + } + if (rohelper_) { + rohelper_ = nullptr; + } UnregisterClass(windowClass_.lpszClassName, nullptr); plugin = nullptr; } diff --git a/flutter_inappwebview_windows/windows/in_app_webview/webview_channel_delegate.cpp b/flutter_inappwebview_windows/windows/in_app_webview/webview_channel_delegate.cpp index c09a23689c..c357aae840 100644 --- a/flutter_inappwebview_windows/windows/in_app_webview/webview_channel_delegate.cpp +++ b/flutter_inappwebview_windows/windows/in_app_webview/webview_channel_delegate.cpp @@ -262,6 +262,11 @@ namespace flutter_inappwebview_plugin webView->openDevTools(); result->Success(true); } + else if (string_equals(methodName, "setThemeMode")) { + auto theme = get_fl_map_value(arguments, "theme"); + webView->setThemeMode(theme); + result->Success(true); + } else if (string_equals(methodName, "callDevToolsProtocolMethod")) { auto result_ = std::shared_ptr>(std::move(result)); auto cdpMethodName = get_fl_map_value(arguments, "methodName");