feat(core): expose additional_browser_args to window config (fix: #5757) (#5799)

Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com>
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
This commit is contained in:
Noam Zaks 2022-12-14 16:46:24 +02:00 committed by GitHub
parent 28133c5155
commit 3dc38b150e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 79 additions and 1 deletions

View File

@ -0,0 +1,5 @@
---
"api": minor
---
Added the `additionalBrowserArgs` option when creating a window.

View File

@ -0,0 +1,5 @@
---
"tauri-utils": minor
---
Added the `additional_browser_args` option to the window configuration.

View File

@ -0,0 +1,7 @@
---
"tauri": minor
"tauri-runtime-wry": minor
"tauri-runtime": minor
---
Added the `additional_browser_args` option when creating a window.

View File

@ -689,6 +689,13 @@
"string",
"null"
]
},
"additionalBrowserArgs": {
"description": "Defines additional browser arguments on Windows. By default wry passes `--disable-features=msWebOOUI,msPdfOOUI,msSmartScreenProtection` so if you use this method, you also need to disable these components by yourself if you want.",
"type": [
"string",
"null"
]
}
},
"additionalProperties": false

View File

@ -33,6 +33,8 @@ use wry::application::platform::macos::WindowBuilderExtMacOS;
use wry::application::platform::unix::{WindowBuilderExtUnix, WindowExtUnix};
#[cfg(windows)]
use wry::application::platform::windows::{WindowBuilderExtWindows, WindowExtWindows};
#[cfg(windows)]
use wry::webview::WebViewBuilderExtWindows;
#[cfg(target_os = "macos")]
use tauri_utils::TitleBarStyle;
@ -3051,6 +3053,12 @@ fn create_webview<T: UserEvent>(
if let Some(user_agent) = webview_attributes.user_agent {
webview_builder = webview_builder.with_user_agent(&user_agent);
}
#[cfg(windows)]
if let Some(additional_browser_args) = webview_attributes.additional_browser_args {
webview_builder = webview_builder.with_additional_browser_args(&additional_browser_args);
}
if let Some(handler) = ipc_handler {
webview_builder = webview_builder.with_ipc_handler(create_ipc_handler(
context,

View File

@ -28,6 +28,7 @@ pub struct WebviewAttributes {
pub file_drop_handler_enabled: bool,
pub clipboard: bool,
pub accept_first_mouse: bool,
pub additional_browser_args: Option<String>,
}
impl WebviewAttributes {
@ -41,6 +42,7 @@ impl WebviewAttributes {
file_drop_handler_enabled: true,
clipboard: false,
accept_first_mouse: false,
additional_browser_args: None,
}
}
@ -88,6 +90,13 @@ impl WebviewAttributes {
self.accept_first_mouse = accept;
self
}
/// Sets additional browser arguments. **Windows Only**
#[must_use]
pub fn additional_browser_args(mut self, additional_args: &str) -> Self {
self.additional_browser_args = Some(additional_args.to_string());
self
}
}
/// Do **NOT** implement this trait except for use in a custom [`Runtime`](crate::Runtime).

View File

@ -884,6 +884,10 @@ pub struct WindowConfig {
/// [tabbing identifier]: <https://developer.apple.com/documentation/appkit/nswindow/1644704-tabbingidentifier>
#[serde(default, alias = "tabbing-identifier")]
pub tabbing_identifier: Option<String>,
/// Defines additional browser arguments on Windows. By default wry passes `--disable-features=msWebOOUI,msPdfOOUI,msSmartScreenProtection`
/// so if you use this method, you also need to disable these components by yourself if you want.
#[serde(default, alias = "additional-browser-args")]
pub additional_browser_args: Option<String>,
}
impl Default for WindowConfig {
@ -918,6 +922,7 @@ impl Default for WindowConfig {
hidden_title: false,
accept_first_mouse: false,
tabbing_identifier: None,
additional_browser_args: None,
}
}
}
@ -3061,6 +3066,7 @@ mod build {
let hidden_title = self.hidden_title;
let accept_first_mouse = self.accept_first_mouse;
let tabbing_identifier = opt_str_lit(self.tabbing_identifier.as_ref());
let additional_browser_args = opt_str_lit(self.additional_browser_args.as_ref());
literal_struct!(
tokens,
@ -3093,7 +3099,8 @@ mod build {
title_bar_style,
hidden_title,
accept_first_mouse,
tabbing_identifier
tabbing_identifier,
additional_browser_args
);
}
}

View File

@ -1574,6 +1574,9 @@ impl<R: Runtime> Builder<R> {
if let Some(ua) = &config.user_agent {
webview_attributes = webview_attributes.user_agent(&ua.to_string());
}
if let Some(args) = &config.additional_browser_args {
webview_attributes = webview_attributes.additional_browser_args(&args.to_string());
}
if !config.file_drop_enabled {
webview_attributes = webview_attributes.disable_file_drop_handler();
}

View File

@ -533,6 +533,22 @@ impl<'a, R: Runtime> WindowBuilder<'a, R> {
self
}
/// Set additional arguments for the webview.
///
/// ## Platform-specific
///
/// - **macOS / Linux / Android / iOS**: Unsupported.
///
/// ## Warning
///
/// By default wry passes `--disable-features=msWebOOUI,msPdfOOUI,msSmartScreenProtection`
/// so if you use this method, you also need to disable these components by yourself if you want.
#[must_use]
pub fn additional_browser_args(mut self, additional_args: &str) -> Self {
self.webview_attributes.additional_browser_args = Some(additional_args.to_string());
self
}
/// Data directory for the webview.
#[must_use]
pub fn data_directory(mut self, data_directory: PathBuf) -> Self {

View File

@ -2141,6 +2141,10 @@ interface WindowOptions {
* The user agent for the webview.
*/
userAgent?: string
/**
* Additional arguments for the webview. **Windows Only**
*/
additionalBrowserArguments?: string
}
function mapMonitor(m: Monitor | null): Monitor | null {

View File

@ -689,6 +689,13 @@
"string",
"null"
]
},
"additionalBrowserArgs": {
"description": "Defines additional browser arguments on Windows. By default wry passes `--disable-features=msWebOOUI,msPdfOOUI,msSmartScreenProtection` so if you use this method, you also need to disable these components by yourself if you want.",
"type": [
"string",
"null"
]
}
},
"additionalProperties": false