Skip to content

Commit ff5e4db

Browse files
fix(core): populate webview_attrs from config, closes #6794 (#6797)
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
1 parent df89ccc commit ff5e4db

File tree

6 files changed

+62
-41
lines changed

6 files changed

+62
-41
lines changed

.changes/core-window-config.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'tauri': 'patch'
3+
---
4+
5+
Fix some configurations not applied when creating the window through Javascript.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'tauri-runtime': 'patch'
3+
---
4+
5+
impl `From<&WindowConfig>` for `WebviewAttributes`.

core/tauri-runtime/src/webview.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@ pub struct WebviewAttributes {
3131
pub additional_browser_args: Option<String>,
3232
}
3333

34+
impl From<&WindowConfig> for WebviewAttributes {
35+
fn from(config: &WindowConfig) -> Self {
36+
let mut builder = Self::new(config.url.clone());
37+
builder = builder.accept_first_mouse(config.accept_first_mouse);
38+
if !config.file_drop_enabled {
39+
builder = builder.disable_file_drop_handler();
40+
}
41+
if let Some(user_agent) = &config.user_agent {
42+
builder = builder.user_agent(user_agent);
43+
}
44+
if let Some(additional_browser_args) = &config.additional_browser_args {
45+
builder = builder.additional_browser_args(additional_browser_args);
46+
}
47+
builder
48+
}
49+
}
50+
3451
impl WebviewAttributes {
3552
/// Initializes the default attributes for a webview.
3653
pub fn new(url: WindowUrl) -> Self {

core/tauri/src/app.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,20 +1565,8 @@ impl<R: Runtime> Builder<R> {
15651565

15661566
// set up all the windows defined in the config
15671567
for config in manager.config().tauri.windows.clone() {
1568-
let url = config.url.clone();
15691568
let label = config.label.clone();
1570-
1571-
let mut webview_attributes =
1572-
WebviewAttributes::new(url).accept_first_mouse(config.accept_first_mouse);
1573-
if let Some(ua) = &config.user_agent {
1574-
webview_attributes = webview_attributes.user_agent(ua);
1575-
}
1576-
if let Some(args) = &config.additional_browser_args {
1577-
webview_attributes = webview_attributes.additional_browser_args(args);
1578-
}
1579-
if !config.file_drop_enabled {
1580-
webview_attributes = webview_attributes.disable_file_drop_handler();
1581-
}
1569+
let webview_attributes = WebviewAttributes::from(&config);
15821570

15831571
self.pending_windows.push(PendingWindow::with_config(
15841572
config,

core/tauri/src/window.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -212,27 +212,19 @@ impl<'a, R: Runtime> WindowBuilder<'a, R> {
212212
///
213213
/// [the Webview2 issue]: https://github.com/tauri-apps/wry/issues/583
214214
pub fn from_config<M: Manager<R>>(manager: &'a M, config: WindowConfig) -> Self {
215-
let runtime = manager.runtime();
216-
let app_handle = manager.app_handle();
217-
let url = config.url.clone();
218-
let file_drop_enabled = config.file_drop_enabled;
219-
let mut builder = Self {
215+
let builder = Self {
220216
manager: manager.manager().clone(),
221-
runtime,
222-
app_handle,
217+
runtime: manager.runtime(),
218+
app_handle: manager.app_handle(),
223219
label: config.label.clone(),
220+
webview_attributes: WebviewAttributes::from(&config),
224221
window_builder: <R::Dispatcher as Dispatch<EventLoopMessage>>::WindowBuilder::with_config(
225222
config,
226223
),
227-
webview_attributes: WebviewAttributes::new(url),
228224
web_resource_request_handler: None,
229225
navigation_handler: None,
230226
};
231227

232-
if !file_drop_enabled {
233-
builder = builder.disable_file_drop_handler();
234-
}
235-
236228
builder
237229
}
238230

examples/api/src-tauri/Cargo.lock

Lines changed: 30 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)