From 3dc38b150ea8c59c8ba67fd586f921016928f47c Mon Sep 17 00:00:00 2001 From: Noam Zaks Date: Wed, 14 Dec 2022 16:46:24 +0200 Subject: [PATCH] feat(core): expose additional_browser_args to window config (fix: #5757) (#5799) Co-authored-by: Amr Bashir Co-authored-by: Lucas Nogueira --- .changes/additional-args-api.md | 5 +++++ .changes/additional-args-config.md | 5 +++++ .changes/additional-args.md | 7 +++++++ core/config-schema/schema.json | 7 +++++++ core/tauri-runtime-wry/src/lib.rs | 8 ++++++++ core/tauri-runtime/src/webview.rs | 9 +++++++++ core/tauri-utils/src/config.rs | 9 ++++++++- core/tauri/src/app.rs | 3 +++ core/tauri/src/window.rs | 16 ++++++++++++++++ tooling/api/src/window.ts | 4 ++++ tooling/cli/schema.json | 7 +++++++ 11 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 .changes/additional-args-api.md create mode 100644 .changes/additional-args-config.md create mode 100644 .changes/additional-args.md diff --git a/.changes/additional-args-api.md b/.changes/additional-args-api.md new file mode 100644 index 000000000000..e5a257daf156 --- /dev/null +++ b/.changes/additional-args-api.md @@ -0,0 +1,5 @@ +--- +"api": minor +--- + +Added the `additionalBrowserArgs` option when creating a window. diff --git a/.changes/additional-args-config.md b/.changes/additional-args-config.md new file mode 100644 index 000000000000..bdb497ee331b --- /dev/null +++ b/.changes/additional-args-config.md @@ -0,0 +1,5 @@ +--- +"tauri-utils": minor +--- + +Added the `additional_browser_args` option to the window configuration. diff --git a/.changes/additional-args.md b/.changes/additional-args.md new file mode 100644 index 000000000000..a9cc187ad775 --- /dev/null +++ b/.changes/additional-args.md @@ -0,0 +1,7 @@ +--- +"tauri": minor +"tauri-runtime-wry": minor +"tauri-runtime": minor +--- + +Added the `additional_browser_args` option when creating a window. diff --git a/core/config-schema/schema.json b/core/config-schema/schema.json index e4f268aa36bf..7e9f4705dcc4 100644 --- a/core/config-schema/schema.json +++ b/core/config-schema/schema.json @@ -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 diff --git a/core/tauri-runtime-wry/src/lib.rs b/core/tauri-runtime-wry/src/lib.rs index 10941d9275e4..d8eb0ea27156 100644 --- a/core/tauri-runtime-wry/src/lib.rs +++ b/core/tauri-runtime-wry/src/lib.rs @@ -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( 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, diff --git a/core/tauri-runtime/src/webview.rs b/core/tauri-runtime/src/webview.rs index fee028f7c8d1..d3d06a4a6bcc 100644 --- a/core/tauri-runtime/src/webview.rs +++ b/core/tauri-runtime/src/webview.rs @@ -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, } 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). diff --git a/core/tauri-utils/src/config.rs b/core/tauri-utils/src/config.rs index f98c81afff2d..7d5b2c3fb7a1 100644 --- a/core/tauri-utils/src/config.rs +++ b/core/tauri-utils/src/config.rs @@ -884,6 +884,10 @@ pub struct WindowConfig { /// [tabbing identifier]: #[serde(default, alias = "tabbing-identifier")] pub tabbing_identifier: Option, + /// 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, } 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 ); } } diff --git a/core/tauri/src/app.rs b/core/tauri/src/app.rs index 955c660a6c57..f8a76323d228 100644 --- a/core/tauri/src/app.rs +++ b/core/tauri/src/app.rs @@ -1574,6 +1574,9 @@ impl Builder { 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(); } diff --git a/core/tauri/src/window.rs b/core/tauri/src/window.rs index 205e35130ba3..ec7111b8c756 100644 --- a/core/tauri/src/window.rs +++ b/core/tauri/src/window.rs @@ -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 { diff --git a/tooling/api/src/window.ts b/tooling/api/src/window.ts index fb8a335a5aaa..ca4694b1ac31 100644 --- a/tooling/api/src/window.ts +++ b/tooling/api/src/window.ts @@ -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 { diff --git a/tooling/cli/schema.json b/tooling/cli/schema.json index e4f268aa36bf..7e9f4705dcc4 100644 --- a/tooling/cli/schema.json +++ b/tooling/cli/schema.json @@ -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