Skip to content

Commit

Permalink
fix: disable WebView2 mini menu ("OOUI"), closes #535 (#559)
Browse files Browse the repository at this point in the history
* Disable WebView2 mini menu ("OOUI")

* Apply suggestions from code review

Co-authored-by: Amr Bashir <[email protected]>

* fmt and changelog

Co-authored-by: Amr Bashir <[email protected]>
  • Loading branch information
JensMertelmeyer and amrbashir authored Apr 29, 2022
1 parent b89398a commit ed0b223
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .changes/webview2-mini-menu.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wry": patch
---

Disable webview2 mini menu
42 changes: 22 additions & 20 deletions src/webview/webview2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,26 +94,28 @@ 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 =
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 = data_directory
.map(|s| pwstr_from_str(&s))
.unwrap_or_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?;
Expand Down

0 comments on commit ed0b223

Please sign in to comment.