mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-04-21 11:26:15 +02:00
fix(dialog): using AsyncMessageDialog for non linux, closes tauri#7182 (#445)
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"dialog": "patch"
|
||||
---
|
||||
|
||||
On non-Linux system, use `AsyncMessageDialog` instead of `MessageDialog`. [(tauri#7182)](https://github.com/tauri-apps/tauri/issues/7182)
|
||||
@@ -23,6 +23,11 @@ type FileDialog = rfd::FileDialog;
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
type FileDialog = rfd::AsyncFileDialog;
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
type MessageDialog = rfd::MessageDialog;
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
type MessageDialog = rfd::AsyncMessageDialog;
|
||||
|
||||
pub fn init<R: Runtime, C: DeserializeOwned>(
|
||||
app: &AppHandle<R>,
|
||||
_api: PluginApi<R, C>,
|
||||
@@ -50,7 +55,7 @@ impl<R: Runtime> Dialog<R> {
|
||||
macro_rules! run_dialog {
|
||||
($e:expr, $h: ident) => {{
|
||||
std::thread::spawn(move || {
|
||||
let response = $e;
|
||||
let response = tauri::async_runtime::block_on($e);
|
||||
$h(response);
|
||||
});
|
||||
}};
|
||||
@@ -136,9 +141,9 @@ impl<R: Runtime> From<FileDialogBuilder<R>> for FileDialog {
|
||||
}
|
||||
}
|
||||
|
||||
impl<R: Runtime> From<MessageDialogBuilder<R>> for rfd::MessageDialog {
|
||||
impl<R: Runtime> From<MessageDialogBuilder<R>> for MessageDialog {
|
||||
fn from(d: MessageDialogBuilder<R>) -> Self {
|
||||
let mut dialog = rfd::MessageDialog::new()
|
||||
let mut dialog = MessageDialog::new()
|
||||
.set_title(&d.title)
|
||||
.set_description(&d.message)
|
||||
.set_level(d.kind.into());
|
||||
@@ -215,5 +220,5 @@ pub fn show_message_dialog<R: Runtime, F: FnOnce(bool) + Send + 'static>(
|
||||
dialog: MessageDialogBuilder<R>,
|
||||
f: F,
|
||||
) {
|
||||
run_dialog!(rfd::MessageDialog::from(dialog).show(), f);
|
||||
run_dialog!(MessageDialog::from(dialog).show(), f);
|
||||
}
|
||||
|
||||
@@ -209,7 +209,9 @@ impl<R: Runtime> MessageDialogBuilder<R> {
|
||||
show_message_dialog(self, f)
|
||||
}
|
||||
|
||||
//// Shows a message dialog.
|
||||
/// Shows a message dialog.
|
||||
/// This is a blocking operation,
|
||||
/// and should *NOT* be used when running on the main thread context.
|
||||
pub fn blocking_show(self) -> bool {
|
||||
blocking_fn!(self, show)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user