Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,8 @@ class InAppWebViewController {
///{@macro flutter_inappwebview_platform_interface.PlatformInAppWebViewController.openDevTools}
Future<void> openDevTools() => platform.openDevTools();

Future<void> setThemeMode(String theme) => platform.setThemeMode(theme);

///{@macro flutter_inappwebview_platform_interface.PlatformInAppWebViewController.callDevToolsProtocolMethod}
Future<dynamic> callDevToolsProtocolMethod(
{required String methodName, Map<String, dynamic>? parameters}) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2140,6 +2140,11 @@ abstract class PlatformInAppWebViewController extends PlatformInterface
'openDevTools is not implemented on the current platform');
}

Future<void> 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.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,10 @@ class _CustomPlatformViewState extends State<CustomPlatformView>
}
},
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2727,6 +2727,13 @@ class WindowsInAppWebViewController extends PlatformInAppWebViewController
await channel?.invokeMethod('openDevTools', args);
}

@override
Future<void> setThemeMode(String theme) async {
Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('theme', () => theme);
await channel?.invokeMethod('setThemeMode', args);
}

@override
Future<dynamic> callDevToolsProtocolMethod(
{required String methodName, Map<String, dynamic>? parameters}) async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ namespace flutter_inappwebview_plugin
void TextureBridgeGpu::ProcessFrame(
winrt::com_ptr<ID3D11Texture2D> 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);

Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "in_app_webview.h"
#include "in_app_webview_manager.h"


namespace flutter_inappwebview_plugin
{
using namespace Microsoft::WRL;
Expand Down Expand Up @@ -1995,6 +1996,26 @@ namespace flutter_inappwebview_plugin
failedLog(webView->OpenDevToolsWindow());
}

void InAppWebView::setThemeMode(const std::string& theme) const
{
if (!webView) {
return;
}
ComPtr<ICoreWebView2_13> coreWebView2_13;
if (SUCCEEDED(webView->QueryInterface(IID_ICoreWebView2_13, &coreWebView2_13))) {
ComPtr<ICoreWebView2Profile> 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<std::string>& parametersAsJson, const std::function<void(const HRESULT& errorCode, const std::optional<std::string>&)> completionHandler) const
{
if (!webView) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ namespace flutter_inappwebview_plugin
void setSettings(const std::shared_ptr<InAppWebViewSettings> 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<std::string>& parametersAsJson, const std::function<void(const HRESULT& errorCode, const std::optional<std::string>&)> completionHandler) const;
void addDevToolsProtocolEventListener(const std::string& eventName);
void removeDevToolsProtocolEventListener(const std::string& eventName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>(arguments, "theme");
webView->setThemeMode(theme);
result->Success(true);
}
else if (string_equals(methodName, "callDevToolsProtocolMethod")) {
auto result_ = std::shared_ptr<flutter::MethodResult<flutter::EncodableValue>>(std::move(result));
auto cdpMethodName = get_fl_map_value<std::string>(arguments, "methodName");
Expand Down