Skip to content

Commit

Permalink
fix(core): populate webview_attrs from config, closes #6794 (#6797)
Browse files Browse the repository at this point in the history
Co-authored-by: Lucas Nogueira <[email protected]>
  • Loading branch information
amrbashir and lucasfernog authored May 24, 2023
1 parent df89ccc commit ff5e4db
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 41 deletions.
5 changes: 5 additions & 0 deletions .changes/core-window-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tauri': 'patch'
---

Fix some configurations not applied when creating the window through Javascript.
5 changes: 5 additions & 0 deletions .changes/webview-attributes-from-window-config-impl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tauri-runtime': 'patch'
---

impl `From<&WindowConfig>` for `WebviewAttributes`.
17 changes: 17 additions & 0 deletions core/tauri-runtime/src/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@ pub struct WebviewAttributes {
pub additional_browser_args: Option<String>,
}

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 {
Expand Down
14 changes: 1 addition & 13 deletions core/tauri/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1565,20 +1565,8 @@ impl<R: Runtime> Builder<R> {

// 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,
Expand Down
16 changes: 4 additions & 12 deletions core/tauri/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<M: Manager<R>>(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: <R::Dispatcher as Dispatch<EventLoopMessage>>::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
}

Expand Down
46 changes: 30 additions & 16 deletions examples/api/src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ff5e4db

Please sign in to comment.