From 3a56f1c1515b784145312dc841ea1249a5dcf6d9 Mon Sep 17 00:00:00 2001 From: Jens Mertelmeyer Date: Mon, 25 Apr 2022 21:40:45 +0200 Subject: [PATCH] Disable WebView2 mini menu ("OOUI") --- src/webview/webview2/mod.rs | 44 ++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/src/webview/webview2/mod.rs b/src/webview/webview2/mod.rs index 79b3054ae..f760d48eb 100644 --- a/src/webview/webview2/mod.rs +++ b/src/webview/webview2/mod.rs @@ -94,26 +94,30 @@ impl InnerWebView { CreateCoreWebView2EnvironmentCompletedHandler::wait_for_async_operation( Box::new(move |environmentcreatedhandler| unsafe { - if let Some(data_directory) = data_directory { - // If we have a custom data_directory, we need to use a call to `CreateCoreWebView2EnvironmentWithOptions` - // instead of the much simpler `CreateCoreWebView2Environment`. - let options: ICoreWebView2EnvironmentOptions = - CoreWebView2EnvironmentOptions::default().into(); - let data_directory = pwstr_from_str(&data_directory); - let result = CreateCoreWebView2EnvironmentWithOptions( - PWSTR::default(), - data_directory, - options, - environmentcreatedhandler, - ) - .map_err(webview2_com::Error::WindowsError); - let _ = take_pwstr(data_directory); - - return result; - } - - CreateCoreWebView2Environment(environmentcreatedhandler) - .map_err(webview2_com::Error::WindowsError) + let options: ICoreWebView2EnvironmentOptions; + options = CoreWebView2EnvironmentOptions::default().into(); + + // remove "mini menu" - See https://github.com/tauri-apps/wry/issues/535 + let additional_arguments = pwstr_from_str("--disable-features=msWebOOUI,msPdfOOUI"); + let _ = options.SetAdditionalBrowserArguments(additional_arguments); + + // if data_directory is None, we set it to a null PWSTR + let data_directory: PWSTR = + match data_directory { + Some(s) => pwstr_from_str(&s), + None => PWSTR::default(), + }; + + let result = CreateCoreWebView2EnvironmentWithOptions( + PWSTR::default(), + data_directory, + options, + environmentcreatedhandler, + ) + .map_err(webview2_com::Error::WindowsError); + let _ = take_pwstr(data_directory); + + return result; }), Box::new(move |error_code, environment| { error_code?;