Skip to content

Commit

Permalink
fix(deps): update rust crate rfd to 0.15 (v2) (#1805)
Browse files Browse the repository at this point in the history
* 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 <legendmastertony@gmail.com>
  • Loading branch information
renovate[bot] and Legend-Master authored Sep 19, 2024
1 parent 41fe905 commit 6bf1bd8
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 29 deletions.
5 changes: 5 additions & 0 deletions .changes/dialog-rfd-015.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"dialog": patch
---

Update rfd to 0.15
106 changes: 97 additions & 9 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion plugins/dialog/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ tauri-plugin-fs = { path = "../fs", version = "2.0.0-rc.5" }
tauri = { workspace = true, features = ["wry"] }

[target."cfg(any(target_os = \"macos\", windows, target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies]
rfd = { version = "0.14", default-features = false, features = [
rfd = { version = "0.15", default-features = false, features = [
"tokio",
"gtk3",
"common-controls-v6",
Expand Down
4 changes: 2 additions & 2 deletions plugins/dialog/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ pub(crate) async fn save<R: Runtime>(
options: SaveDialogOptions,
) -> Result<Option<FilePath>> {
let mut dialog_builder = dialog.file();
#[cfg(any(windows, target_os = "macos"))]
#[cfg(desktop)]
{
dialog_builder = dialog_builder.set_parent(&window);
}
Expand Down Expand Up @@ -253,7 +253,7 @@ fn message_dialog<R: Runtime>(
builder = builder.title(title);
}

#[cfg(any(windows, target_os = "macos"))]
#[cfg(desktop)]
{
builder = builder.parent(&window);
}
Expand Down
31 changes: 26 additions & 5 deletions plugins/dialog/src/desktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//! to give results back. This is particularly useful when running dialogs from the main thread.
//! When using on asynchronous contexts such as async commands, the [`blocking`] APIs are recommended.

use raw_window_handle::{HasWindowHandle, RawWindowHandle};
use raw_window_handle::{HasDisplayHandle, HasWindowHandle, RawDisplayHandle, RawWindowHandle};
use rfd::{AsyncFileDialog, AsyncMessageDialog};
use serde::de::DeserializeOwned;
use tauri::{plugin::PluginApi, AppHandle, Runtime};
Expand Down Expand Up @@ -50,13 +50,34 @@ impl From<MessageDialogKind> for rfd::MessageLevel {
}
}

struct WindowHandle(RawWindowHandle);
#[derive(Debug)]
pub(crate) struct WindowHandle {
window_handle: RawWindowHandle,
display_handle: RawDisplayHandle,
}

impl WindowHandle {
pub(crate) fn new(window_handle: RawWindowHandle, display_handle: RawDisplayHandle) -> Self {
Self {
window_handle,
display_handle,
}
}
}

impl HasWindowHandle for WindowHandle {
fn window_handle(
&self,
) -> Result<raw_window_handle::WindowHandle<'_>, raw_window_handle::HandleError> {
Ok(unsafe { raw_window_handle::WindowHandle::borrow_raw(self.0) })
Ok(unsafe { raw_window_handle::WindowHandle::borrow_raw(self.window_handle) })
}
}

impl HasDisplayHandle for WindowHandle {
fn display_handle(
&self,
) -> Result<raw_window_handle::DisplayHandle<'_>, raw_window_handle::HandleError> {
Ok(unsafe { raw_window_handle::DisplayHandle::borrow_raw(self.display_handle) })
}
}

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

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

if let Some(parent) = d.parent {
dialog = dialog.set_parent(&WindowHandle(parent));
dialog = dialog.set_parent(&parent);
}

dialog
Expand Down
38 changes: 26 additions & 12 deletions plugins/dialog/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ pub struct MessageDialogBuilder<R: Runtime> {
pub(crate) ok_button_label: Option<String>,
pub(crate) cancel_button_label: Option<String>,
#[cfg(desktop)]
pub(crate) parent: Option<raw_window_handle::RawWindowHandle>,
pub(crate) parent: Option<crate::desktop::WindowHandle>,
}

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

/// Set parent windows explicitly (optional)
///
/// ## Platform-specific
///
/// - **Linux:** Unsupported.
#[cfg(desktop)]
pub fn parent<W: raw_window_handle::HasWindowHandle>(mut self, parent: &W) -> Self {
if let Ok(h) = parent.window_handle() {
self.parent.replace(h.as_raw());
pub fn parent<W: raw_window_handle::HasWindowHandle + raw_window_handle::HasDisplayHandle>(
mut self,
parent: &W,
) -> Self {
if let (Ok(window_handle), Ok(display_handle)) =
(parent.window_handle(), parent.display_handle())
{
self.parent.replace(crate::desktop::WindowHandle::new(
window_handle.as_raw(),
display_handle.as_raw(),
));
}
self
}
Expand Down Expand Up @@ -314,7 +318,7 @@ pub struct FileDialogBuilder<R: Runtime> {
pub(crate) title: Option<String>,
pub(crate) can_create_directories: Option<bool>,
#[cfg(desktop)]
pub(crate) parent: Option<raw_window_handle::RawWindowHandle>,
pub(crate) parent: Option<crate::desktop::WindowHandle>,
}

#[cfg(mobile)]
Expand Down Expand Up @@ -380,9 +384,19 @@ impl<R: Runtime> FileDialogBuilder<R> {
/// Sets the parent window of the dialog.
#[cfg(desktop)]
#[must_use]
pub fn set_parent<W: raw_window_handle::HasWindowHandle>(mut self, parent: &W) -> Self {
if let Ok(h) = parent.window_handle() {
self.parent.replace(h.as_raw());
pub fn set_parent<
W: raw_window_handle::HasWindowHandle + raw_window_handle::HasDisplayHandle,
>(
mut self,
parent: &W,
) -> Self {
if let (Ok(window_handle), Ok(display_handle)) =
(parent.window_handle(), parent.display_handle())
{
self.parent.replace(crate::desktop::WindowHandle::new(
window_handle.as_raw(),
display_handle.as_raw(),
));
}
self
}
Expand Down

0 comments on commit 6bf1bd8

Please sign in to comment.