fix(dialog): using AsyncMessageDialog for non linux, closes tauri#7182 (#445)

pull/539/head
Jason Tsai 2 years ago committed by GitHub
parent 7d9df7297a
commit be591d2feb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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"))] #[cfg(not(target_os = "linux"))]
type FileDialog = rfd::AsyncFileDialog; 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>( pub fn init<R: Runtime, C: DeserializeOwned>(
app: &AppHandle<R>, app: &AppHandle<R>,
_api: PluginApi<R, C>, _api: PluginApi<R, C>,
@ -50,7 +55,7 @@ impl<R: Runtime> Dialog<R> {
macro_rules! run_dialog { macro_rules! run_dialog {
($e:expr, $h: ident) => {{ ($e:expr, $h: ident) => {{
std::thread::spawn(move || { std::thread::spawn(move || {
let response = $e; let response = tauri::async_runtime::block_on($e);
$h(response); $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 { fn from(d: MessageDialogBuilder<R>) -> Self {
let mut dialog = rfd::MessageDialog::new() let mut dialog = MessageDialog::new()
.set_title(&d.title) .set_title(&d.title)
.set_description(&d.message) .set_description(&d.message)
.set_level(d.kind.into()); .set_level(d.kind.into());
@ -215,5 +220,5 @@ pub fn show_message_dialog<R: Runtime, F: FnOnce(bool) + Send + 'static>(
dialog: MessageDialogBuilder<R>, dialog: MessageDialogBuilder<R>,
f: F, 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) 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 { pub fn blocking_show(self) -> bool {
blocking_fn!(self, show) blocking_fn!(self, show)
} }

Loading…
Cancel
Save