Skip to content

Commit 141133a

Browse files
authored
feat(core): add WindowBuilder type (#3598)
1 parent da88243 commit 141133a

File tree

11 files changed

+314
-38
lines changed

11 files changed

+314
-38
lines changed

.changes/window-builder.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+
Added a `WindowBuilder` type.

core/tauri-runtime/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ infer = "0.4"
3535
[target."cfg(windows)".dependencies]
3636
webview2-com = "0.13.0"
3737

38-
[target."cfg(windows)".dependencies.windows]
39-
version = "0.30.0"
40-
features = [ "Win32_Foundation" ]
38+
[target."cfg(windows)".dependencies.windows]
39+
version = "0.30.0"
40+
features = [ "Win32_Foundation" ]
4141

4242
[target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies]
4343
gtk = { version = "0.15", features = [ "v3_20" ] }

core/tauri-runtime/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ pub trait Dispatch: Debug + Clone + Send + Sync + Sized + 'static {
361361
type Runtime: Runtime;
362362

363363
/// The winoow builder type.
364-
type WindowBuilder: WindowBuilder + Clone;
364+
type WindowBuilder: WindowBuilder;
365365

366366
/// Run a task on the main thread.
367367
fn run_on_main_thread<F: FnOnce() + Send + 'static>(&self, f: F) -> crate::Result<()>;

core/tauri-runtime/src/webview.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use windows::Win32::Foundation::HWND;
1414
use std::{fmt, path::PathBuf};
1515

1616
/// The attributes used to create an webview.
17-
#[derive(Debug)]
17+
#[derive(Debug, Clone)]
1818
pub struct WebviewAttributes {
1919
pub url: WindowUrl,
2020
pub initialization_scripts: Vec<String>,
@@ -70,7 +70,7 @@ impl WebviewAttributes {
7070
/// Do **NOT** implement this trait except for use in a custom [`Runtime`](crate::Runtime).
7171
///
7272
/// This trait is separate from [`WindowBuilder`] to prevent "accidental" implementation.
73-
pub trait WindowBuilderBase: fmt::Debug + Sized {}
73+
pub trait WindowBuilderBase: fmt::Debug + Clone + Sized {}
7474

7575
/// A builder for all attributes related to a single webview.
7676
///
@@ -97,7 +97,7 @@ pub trait WindowBuilder: WindowBuilderBase {
9797

9898
/// Window size.
9999
#[must_use]
100-
fn inner_size(self, min_width: f64, min_height: f64) -> Self;
100+
fn inner_size(self, width: f64, height: f64) -> Self;
101101

102102
/// Window min inner size.
103103
#[must_use]

core/tauri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ glib = "0.15"
9797
[target."cfg(target_os = \"macos\")".dependencies]
9898
embed_plist = "1.2"
9999

100-
[target."cfg(windows)".dev-dependencies.windows]
100+
[target."cfg(windows)".dependencies.windows]
101101
version = "0.30.0"
102102
features = [ "Win32_Foundation" ]
103103

core/tauri/src/app.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::{
1515
plugin::{Plugin, PluginStore},
1616
runtime::{
1717
http::{Request as HttpRequest, Response as HttpResponse},
18-
webview::{WebviewAttributes, WindowBuilder},
18+
webview::{WebviewAttributes, WindowBuilder as _},
1919
window::{PendingWindow, WindowEvent},
2020
Dispatch, ExitRequestedEventAction, RunEvent as RuntimeRunEvent, Runtime,
2121
},
@@ -359,6 +359,12 @@ macro_rules! shared_app_impl {
359359
/// Creates a new webview window.
360360
///
361361
/// Data URLs are only supported with the `window-data-url` feature flag.
362+
///
363+
/// See [`Self::window_builder`] for an API with extended functionality.
364+
#[deprecated(
365+
since = "1.0.0-rc.4",
366+
note = "The `window_builder` function offers an easier API with extended functionality"
367+
)]
362368
pub fn create_window<F>(
363369
&self,
364370
label: impl Into<String>,

core/tauri/src/endpoints/window.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,18 +152,12 @@ impl Cmd {
152152
context: InvokeContext<R>,
153153
options: Box<WindowConfig>,
154154
) -> super::Result<()> {
155-
let mut window = context.window;
156155
let label = options.label.clone();
157156
let url = options.url.clone();
158157

159-
window
160-
.create_window(label, url, |_, webview_attributes| {
161-
(
162-
<<R::Dispatcher as Dispatch>::WindowBuilder>::with_config(*options),
163-
webview_attributes,
164-
)
165-
})
166-
.map_err(crate::error::into_anyhow)?;
158+
let mut builder = context.window.builder(label, url);
159+
builder.window_builder = <<R::Dispatcher as Dispatch>::WindowBuilder>::with_config(*options);
160+
builder.build().map_err(crate::error::into_anyhow)?;
167161

168162
Ok(())
169163
}

0 commit comments

Comments
 (0)