mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-06-06 13:53:54 +02:00
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 <legendmastertony@gmail.com>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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};
|
||||
@@ -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) })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
@@ -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
|
||||
|
||||
+26
-12
@@ -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.
|
||||
@@ -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
|
||||
}
|
||||
@@ -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)]
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user