diff --git a/.changes/core-window-config.md b/.changes/core-window-config.md new file mode 100644 index 000000000000..0ebdf36735ab --- /dev/null +++ b/.changes/core-window-config.md @@ -0,0 +1,5 @@ +--- +'tauri': 'patch' +--- + +Fix some configurations not applied when creating the window through Javascript. diff --git a/.changes/webview-attributes-from-window-config-impl.md b/.changes/webview-attributes-from-window-config-impl.md new file mode 100644 index 000000000000..3adaa2e92ca6 --- /dev/null +++ b/.changes/webview-attributes-from-window-config-impl.md @@ -0,0 +1,5 @@ +--- +'tauri-runtime': 'patch' +--- + +impl `From<&WindowConfig>` for `WebviewAttributes`. diff --git a/core/tauri-runtime/src/webview.rs b/core/tauri-runtime/src/webview.rs index 111ea2b7c4df..2cbaeb1d359e 100644 --- a/core/tauri-runtime/src/webview.rs +++ b/core/tauri-runtime/src/webview.rs @@ -31,6 +31,23 @@ pub struct WebviewAttributes { pub additional_browser_args: Option, } +impl From<&WindowConfig> for WebviewAttributes { + fn from(config: &WindowConfig) -> Self { + let mut builder = Self::new(config.url.clone()); + builder = builder.accept_first_mouse(config.accept_first_mouse); + if !config.file_drop_enabled { + builder = builder.disable_file_drop_handler(); + } + if let Some(user_agent) = &config.user_agent { + builder = builder.user_agent(user_agent); + } + if let Some(additional_browser_args) = &config.additional_browser_args { + builder = builder.additional_browser_args(additional_browser_args); + } + builder + } +} + impl WebviewAttributes { /// Initializes the default attributes for a webview. pub fn new(url: WindowUrl) -> Self { diff --git a/core/tauri/src/app.rs b/core/tauri/src/app.rs index f2db2494c184..42660a2f45eb 100644 --- a/core/tauri/src/app.rs +++ b/core/tauri/src/app.rs @@ -1565,20 +1565,8 @@ impl Builder { // set up all the windows defined in the config for config in manager.config().tauri.windows.clone() { - let url = config.url.clone(); let label = config.label.clone(); - - let mut webview_attributes = - WebviewAttributes::new(url).accept_first_mouse(config.accept_first_mouse); - if let Some(ua) = &config.user_agent { - webview_attributes = webview_attributes.user_agent(ua); - } - if let Some(args) = &config.additional_browser_args { - webview_attributes = webview_attributes.additional_browser_args(args); - } - if !config.file_drop_enabled { - webview_attributes = webview_attributes.disable_file_drop_handler(); - } + let webview_attributes = WebviewAttributes::from(&config); self.pending_windows.push(PendingWindow::with_config( config, diff --git a/core/tauri/src/window.rs b/core/tauri/src/window.rs index 37bc385962b3..e6e39a693a9f 100644 --- a/core/tauri/src/window.rs +++ b/core/tauri/src/window.rs @@ -212,27 +212,19 @@ impl<'a, R: Runtime> WindowBuilder<'a, R> { /// /// [the Webview2 issue]: https://github.com/tauri-apps/wry/issues/583 pub fn from_config>(manager: &'a M, config: WindowConfig) -> Self { - let runtime = manager.runtime(); - let app_handle = manager.app_handle(); - let url = config.url.clone(); - let file_drop_enabled = config.file_drop_enabled; - let mut builder = Self { + let builder = Self { manager: manager.manager().clone(), - runtime, - app_handle, + runtime: manager.runtime(), + app_handle: manager.app_handle(), label: config.label.clone(), + webview_attributes: WebviewAttributes::from(&config), window_builder: >::WindowBuilder::with_config( config, ), - webview_attributes: WebviewAttributes::new(url), web_resource_request_handler: None, navigation_handler: None, }; - if !file_drop_enabled { - builder = builder.disable_file_drop_handler(); - } - builder } diff --git a/examples/api/src-tauri/Cargo.lock b/examples/api/src-tauri/Cargo.lock index 774c25496218..a40855f4e597 100644 --- a/examples/api/src-tauri/Cargo.lock +++ b/examples/api/src-tauri/Cargo.lock @@ -434,9 +434,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.78" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" [[package]] name = "cesu8" @@ -791,9 +791,9 @@ dependencies = [ [[package]] name = "darling" -version = "0.14.4" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b750cb3417fd1b327431a470f388520309479ab0bf5e323505daf0290cd3850" +checksum = "0558d22a7b463ed0241e993f76f09f30b126687447751a8638587b864e4b3944" dependencies = [ "darling_core", "darling_macro", @@ -801,27 +801,27 @@ dependencies = [ [[package]] name = "darling_core" -version = "0.14.4" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "109c1ca6e6b7f82cc233a97004ea8ed7ca123a9af07a8230878fcfda9b158bf0" +checksum = "ab8bfa2e259f8ee1ce5e97824a3c55ec4404a0d772ca7fa96bf19f0752a046eb" dependencies = [ "fnv", "ident_case", "proc-macro2", "quote", "strsim", - "syn 1.0.107", + "syn 2.0.15", ] [[package]] name = "darling_macro" -version = "0.14.4" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e" +checksum = "29a358ff9f12ec09c3e61fef9b5a9902623a695a46a917b07f269bff1445611a" dependencies = [ "darling_core", "quote", - "syn 1.0.107", + "syn 2.0.15", ] [[package]] @@ -3235,11 +3235,11 @@ dependencies = [ [[package]] name = "serde_with" -version = "2.3.2" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "331bb8c3bf9b92457ab7abecf07078c13f7d270ba490103e84e8b014490cd0b0" +checksum = "9f02d8aa6e3c385bf084924f660ce2a3a6bd333ba55b35e8590b321f35d88513" dependencies = [ - "base64 0.13.1", + "base64 0.21.0", "chrono", "hex", "indexmap", @@ -3251,14 +3251,14 @@ dependencies = [ [[package]] name = "serde_with_macros" -version = "2.3.2" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "859011bddcc11f289f07f467cc1fe01c7a941daa4d8f6c40d4d1c92eb6d9319c" +checksum = "edc7d5d3932fb12ce722ee5e64dd38c504efba37567f0c402f6ca728c3b8b070" dependencies = [ "darling", "proc-macro2", "quote", - "syn 1.0.107", + "syn 2.0.15", ] [[package]] @@ -3495,6 +3495,19 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "sys-locale" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8a11bd9c338fdba09f7881ab41551932ad42e405f61d01e8406baea71c07aee" +dependencies = [ + "js-sys", + "libc", + "wasm-bindgen", + "web-sys", + "windows-sys 0.45.0", +] + [[package]] name = "system-deps" version = "5.0.0" @@ -3635,6 +3648,7 @@ dependencies = [ "serialize-to-javascript", "shared_child", "state", + "sys-locale", "tar", "tauri-macros", "tauri-runtime",