Skip to content

Commit 6bf1bd8

Browse files
fix(deps): update rust crate rfd to 0.15 (v2) (#1805)
* fix(deps): update rust crate rfd to 0.15 * Fix compilation * Add change file * Remove platform specific note --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Tony <[email protected]>
1 parent 41fe905 commit 6bf1bd8

File tree

6 files changed

+157
-29
lines changed

6 files changed

+157
-29
lines changed

.changes/dialog-rfd-015.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"dialog": patch
3+
---
4+
5+
Update rfd to 0.15

Cargo.lock

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

plugins/dialog/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ tauri-plugin-fs = { path = "../fs", version = "2.0.0-rc.5" }
3333
tauri = { workspace = true, features = ["wry"] }
3434

3535
[target."cfg(any(target_os = \"macos\", windows, target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies]
36-
rfd = { version = "0.14", default-features = false, features = [
36+
rfd = { version = "0.15", default-features = false, features = [
3737
"tokio",
3838
"gtk3",
3939
"common-controls-v6",

plugins/dialog/src/commands.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ pub(crate) async fn save<R: Runtime>(
205205
options: SaveDialogOptions,
206206
) -> Result<Option<FilePath>> {
207207
let mut dialog_builder = dialog.file();
208-
#[cfg(any(windows, target_os = "macos"))]
208+
#[cfg(desktop)]
209209
{
210210
dialog_builder = dialog_builder.set_parent(&window);
211211
}
@@ -253,7 +253,7 @@ fn message_dialog<R: Runtime>(
253253
builder = builder.title(title);
254254
}
255255

256-
#[cfg(any(windows, target_os = "macos"))]
256+
#[cfg(desktop)]
257257
{
258258
builder = builder.parent(&window);
259259
}

plugins/dialog/src/desktop.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//! to give results back. This is particularly useful when running dialogs from the main thread.
99
//! When using on asynchronous contexts such as async commands, the [`blocking`] APIs are recommended.
1010
11-
use raw_window_handle::{HasWindowHandle, RawWindowHandle};
11+
use raw_window_handle::{HasDisplayHandle, HasWindowHandle, RawDisplayHandle, RawWindowHandle};
1212
use rfd::{AsyncFileDialog, AsyncMessageDialog};
1313
use serde::de::DeserializeOwned;
1414
use tauri::{plugin::PluginApi, AppHandle, Runtime};
@@ -50,13 +50,34 @@ impl From<MessageDialogKind> for rfd::MessageLevel {
5050
}
5151
}
5252

53-
struct WindowHandle(RawWindowHandle);
53+
#[derive(Debug)]
54+
pub(crate) struct WindowHandle {
55+
window_handle: RawWindowHandle,
56+
display_handle: RawDisplayHandle,
57+
}
58+
59+
impl WindowHandle {
60+
pub(crate) fn new(window_handle: RawWindowHandle, display_handle: RawDisplayHandle) -> Self {
61+
Self {
62+
window_handle,
63+
display_handle,
64+
}
65+
}
66+
}
5467

5568
impl HasWindowHandle for WindowHandle {
5669
fn window_handle(
5770
&self,
5871
) -> Result<raw_window_handle::WindowHandle<'_>, raw_window_handle::HandleError> {
59-
Ok(unsafe { raw_window_handle::WindowHandle::borrow_raw(self.0) })
72+
Ok(unsafe { raw_window_handle::WindowHandle::borrow_raw(self.window_handle) })
73+
}
74+
}
75+
76+
impl HasDisplayHandle for WindowHandle {
77+
fn display_handle(
78+
&self,
79+
) -> Result<raw_window_handle::DisplayHandle<'_>, raw_window_handle::HandleError> {
80+
Ok(unsafe { raw_window_handle::DisplayHandle::borrow_raw(self.display_handle) })
6081
}
6182
}
6283

@@ -79,7 +100,7 @@ impl<R: Runtime> From<FileDialogBuilder<R>> for AsyncFileDialog {
79100
}
80101
#[cfg(desktop)]
81102
if let Some(parent) = d.parent {
82-
builder = builder.set_parent(&WindowHandle(parent));
103+
builder = builder.set_parent(&parent);
83104
}
84105

85106
builder = builder.set_can_create_directories(d.can_create_directories.unwrap_or(true));
@@ -106,7 +127,7 @@ impl<R: Runtime> From<MessageDialogBuilder<R>> for AsyncMessageDialog {
106127
}
107128

108129
if let Some(parent) = d.parent {
109-
dialog = dialog.set_parent(&WindowHandle(parent));
130+
dialog = dialog.set_parent(&parent);
110131
}
111132

112133
dialog

plugins/dialog/src/lib.rs

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ pub struct MessageDialogBuilder<R: Runtime> {
199199
pub(crate) ok_button_label: Option<String>,
200200
pub(crate) cancel_button_label: Option<String>,
201201
#[cfg(desktop)]
202-
pub(crate) parent: Option<raw_window_handle::RawWindowHandle>,
202+
pub(crate) parent: Option<crate::desktop::WindowHandle>,
203203
}
204204

205205
/// Payload for the message dialog mobile API.
@@ -250,14 +250,18 @@ impl<R: Runtime> MessageDialogBuilder<R> {
250250
}
251251

252252
/// Set parent windows explicitly (optional)
253-
///
254-
/// ## Platform-specific
255-
///
256-
/// - **Linux:** Unsupported.
257253
#[cfg(desktop)]
258-
pub fn parent<W: raw_window_handle::HasWindowHandle>(mut self, parent: &W) -> Self {
259-
if let Ok(h) = parent.window_handle() {
260-
self.parent.replace(h.as_raw());
254+
pub fn parent<W: raw_window_handle::HasWindowHandle + raw_window_handle::HasDisplayHandle>(
255+
mut self,
256+
parent: &W,
257+
) -> Self {
258+
if let (Ok(window_handle), Ok(display_handle)) =
259+
(parent.window_handle(), parent.display_handle())
260+
{
261+
self.parent.replace(crate::desktop::WindowHandle::new(
262+
window_handle.as_raw(),
263+
display_handle.as_raw(),
264+
));
261265
}
262266
self
263267
}
@@ -314,7 +318,7 @@ pub struct FileDialogBuilder<R: Runtime> {
314318
pub(crate) title: Option<String>,
315319
pub(crate) can_create_directories: Option<bool>,
316320
#[cfg(desktop)]
317-
pub(crate) parent: Option<raw_window_handle::RawWindowHandle>,
321+
pub(crate) parent: Option<crate::desktop::WindowHandle>,
318322
}
319323

320324
#[cfg(mobile)]
@@ -380,9 +384,19 @@ impl<R: Runtime> FileDialogBuilder<R> {
380384
/// Sets the parent window of the dialog.
381385
#[cfg(desktop)]
382386
#[must_use]
383-
pub fn set_parent<W: raw_window_handle::HasWindowHandle>(mut self, parent: &W) -> Self {
384-
if let Ok(h) = parent.window_handle() {
385-
self.parent.replace(h.as_raw());
387+
pub fn set_parent<
388+
W: raw_window_handle::HasWindowHandle + raw_window_handle::HasDisplayHandle,
389+
>(
390+
mut self,
391+
parent: &W,
392+
) -> Self {
393+
if let (Ok(window_handle), Ok(display_handle)) =
394+
(parent.window_handle(), parent.display_handle())
395+
{
396+
self.parent.replace(crate::desktop::WindowHandle::new(
397+
window_handle.as_raw(),
398+
display_handle.as_raw(),
399+
));
386400
}
387401
self
388402
}

0 commit comments

Comments
 (0)