Skip to content

Commit

Permalink
feat(core): expose additional_browser_args to window config (fix: #5757
Browse files Browse the repository at this point in the history
…) (#5799)

Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com>
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
  • Loading branch information
3 people authored Dec 14, 2022
1 parent 28133c5 commit 3dc38b1
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changes/additional-args-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"api": minor
---

Added the `additionalBrowserArgs` option when creating a window.
5 changes: 5 additions & 0 deletions .changes/additional-args-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-utils": minor
---

Added the `additional_browser_args` option to the window configuration.
7 changes: 7 additions & 0 deletions .changes/additional-args.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"tauri": minor
"tauri-runtime-wry": minor
"tauri-runtime": minor
---

Added the `additional_browser_args` option when creating a window.
7 changes: 7 additions & 0 deletions core/config-schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions core/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions core/tauri-runtime/src/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -41,6 +42,7 @@ impl WebviewAttributes {
file_drop_handler_enabled: true,
clipboard: false,
accept_first_mouse: false,
additional_browser_args: None,
}
}

Expand Down Expand Up @@ -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).
Expand Down
9 changes: 8 additions & 1 deletion core/tauri-utils/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -918,6 +922,7 @@ impl Default for WindowConfig {
hidden_title: false,
accept_first_mouse: false,
tabbing_identifier: None,
additional_browser_args: None,
}
}
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -3093,7 +3099,8 @@ mod build {
title_bar_style,
hidden_title,
accept_first_mouse,
tabbing_identifier
tabbing_identifier,
additional_browser_args
);
}
}
Expand Down
3 changes: 3 additions & 0 deletions core/tauri/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
16 changes: 16 additions & 0 deletions core/tauri/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions tooling/api/src/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions tooling/cli/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3dc38b1

Please sign in to comment.