Skip to content

Commit c31f097

Browse files
authored
refactor: update to wry 0.9 (#1630)
1 parent 929ebc2 commit c31f097

File tree

16 files changed

+686
-431
lines changed

16 files changed

+686
-431
lines changed

.changes/create-window-refactor.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch
3+
---
4+
5+
The `create_window` API callback now takes two arguments: the `WindowBuilder` and the `WebviewAttributes` and must return a tuple containing both values.

.changes/drag-window-api.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"api": patch
3+
---
4+
5+
Adds `startDragging` API on the window module.

.changes/window-attributes-rename.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch
3+
---
4+
5+
Rename `Attributes` to `WindowBuilder`.

.changes/wry-update.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch
3+
---
4+
5+
Update `wry` to v0.9.

core/tauri/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ thiserror = "1.0.24"
2424
once_cell = "1.7.2"
2525
tauri-macros = { version = "1.0.0-beta-rc.1", path = "../tauri-macros" }
2626
tauri-utils = { version = "1.0.0-beta-rc.1", path = "../tauri-utils" }
27-
wry = "0.8"
27+
wry = "0.9"
2828
rand = "0.8"
2929
reqwest = { version = "0.11", features = [ "json", "multipart" ] }
3030
tempfile = "3"
@@ -47,6 +47,7 @@ open = "1.7.0"
4747
shared_child = "0.3"
4848
os_pipe = "0.9"
4949
minisign-verify = "0.1.8"
50+
image = "0.23"
5051

5152
[build-dependencies]
5253
cfg_aliases = "0.1.1"

core/tauri/scripts/core.js

+12
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,18 @@ if (!String.prototype.startsWith) {
187187
);
188188
}
189189

190+
// drag region
191+
document.addEventListener('mousedown', (e) => {
192+
if (e.target.classList.contains('drag-region') && e.buttons === 1) {
193+
window.__TAURI__.invoke('tauri', {
194+
__tauriModule: "Window",
195+
message: {
196+
cmd: "startDragging",
197+
}
198+
})
199+
}
200+
})
201+
190202
window.__TAURI__.invoke('tauri', {
191203
__tauriModule: "Event",
192204
message: {

core/tauri/src/endpoints/window.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ pub enum Cmd {
8989
SetIcon {
9090
icon: IconDto,
9191
},
92+
StartDragging,
9293
}
9394

9495
#[cfg(window_create)]
@@ -122,9 +123,11 @@ impl Cmd {
122123
});
123124

124125
let url = options.url.clone();
125-
let pending =
126-
crate::runtime::window::PendingWindow::with_config(options, label.clone(), url);
127-
126+
let pending = crate::runtime::window::PendingWindow::with_config(
127+
options,
128+
crate::runtime::webview::WebviewAttributes::new(url),
129+
label.clone(),
130+
);
128131
window.create_window(pending)?.emit_others(
129132
&crate::runtime::manager::tauri_event::<P::Event>("tauri://window-created"),
130133
Some(WindowCreatedEvent {
@@ -160,6 +163,7 @@ impl Cmd {
160163
Self::SetPosition { x, y } => window.set_position(x, y)?,
161164
Self::SetFullscreen { fullscreen } => window.set_fullscreen(fullscreen)?,
162165
Self::SetIcon { icon } => window.set_icon(icon.into())?,
166+
Self::StartDragging => window.start_dragging()?,
163167
}
164168
Ok(().into())
165169
}

core/tauri/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub use {
5252
hooks::{InvokeHandler, InvokeMessage, OnPageLoad, PageLoadPayload, SetupHook},
5353
runtime::app::{App, Builder},
5454
runtime::flavors::wry::Wry,
55-
runtime::webview::Attributes,
55+
runtime::webview::{WebviewAttributes, WindowBuilder},
5656
runtime::window::export::Window,
5757
};
5858

@@ -92,6 +92,7 @@ macro_rules! tauri_build_context {
9292
}
9393

9494
/// A icon definition.
95+
#[derive(Debug, Clone)]
9596
pub enum Icon {
9697
/// Icon from file path.
9798
File(PathBuf),

core/tauri/src/runtime/app.rs

+22-9
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010
flavors::wry::Wry,
1111
manager::{Args, WindowManager},
1212
tag::Tag,
13-
webview::{Attributes, CustomProtocol},
13+
webview::{CustomProtocol, WebviewAttributes, WindowBuilder},
1414
window::PendingWindow,
1515
Dispatch, Runtime,
1616
},
@@ -183,12 +183,23 @@ where
183183
/// Creates a new webview.
184184
pub fn create_window<F>(mut self, label: L, url: WindowUrl, setup: F) -> Self
185185
where
186-
F: FnOnce(<R::Dispatcher as Dispatch>::Attributes) -> <R::Dispatcher as Dispatch>::Attributes,
186+
F: FnOnce(
187+
<R::Dispatcher as Dispatch>::WindowBuilder,
188+
WebviewAttributes,
189+
) -> (
190+
<R::Dispatcher as Dispatch>::WindowBuilder,
191+
WebviewAttributes,
192+
),
187193
{
188-
let attributes = setup(<R::Dispatcher as Dispatch>::Attributes::new());
189-
self
190-
.pending_windows
191-
.push(PendingWindow::new(attributes, label, url));
194+
let (window_attributes, webview_attributes) = setup(
195+
<R::Dispatcher as Dispatch>::WindowBuilder::new(),
196+
WebviewAttributes::new(url),
197+
);
198+
self.pending_windows.push(PendingWindow::new(
199+
window_attributes,
200+
webview_attributes,
201+
label,
202+
));
192203
self
193204
}
194205

@@ -236,9 +247,11 @@ where
236247
.parse()
237248
.unwrap_or_else(|_| panic!("bad label found in config: {}", config.label));
238249

239-
self
240-
.pending_windows
241-
.push(PendingWindow::with_config(config, label, url));
250+
self.pending_windows.push(PendingWindow::with_config(
251+
config,
252+
WebviewAttributes::new(url),
253+
label,
254+
));
242255
}
243256

244257
manager.initialize_plugins()?;

0 commit comments

Comments
 (0)