From dd22a8819c89daa588a7f244bd1cdb61589e115e Mon Sep 17 00:00:00 2001 From: amrbashir Date: Thu, 17 Apr 2025 05:37:24 +0200 Subject: [PATCH] From --- plugins/dialog/src/commands.rs | 15 +++++---------- plugins/dialog/src/mobile.rs | 2 +- plugins/dialog/src/models.rs | 20 ++++++++------------ 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/plugins/dialog/src/commands.rs b/plugins/dialog/src/commands.rs index e6054ca5..5298de9d 100644 --- a/plugins/dialog/src/commands.rs +++ b/plugins/dialog/src/commands.rs @@ -279,18 +279,13 @@ pub(crate) async fn message( ok_button_label: Option, buttons: Option, ) -> Result { - let buttons = buttons.unwrap_or_else(|| { - if let Some(ok_button_label) = ok_button_label { - MessageDialogButtons::OkCustom(ok_button_label) - } else { - MessageDialogButtons::Ok - } + let buttons = buttons.unwrap_or(if let Some(ok_button_label) = ok_button_label { + MessageDialogButtons::OkCustom(ok_button_label) + } else { + MessageDialogButtons::Ok }); - Ok(dbg!(message_dialog( - window, dialog, title, message, kind, buttons - ) - .blocking_show_with_result())) + Ok(message_dialog(window, dialog, title, message, kind, buttons).blocking_show_with_result()) } #[command] diff --git a/plugins/dialog/src/mobile.rs b/plugins/dialog/src/mobile.rs index d82738d2..46ea3a27 100644 --- a/plugins/dialog/src/mobile.rs +++ b/plugins/dialog/src/mobile.rs @@ -121,7 +121,7 @@ pub fn show_message_dialog("showMessageDialog", dialog.payload()); - let res = res.map(|res| res.value.parse::().unwrap_or_default()); + let res = res.map(|res| res.value.into()); f(res.unwrap_or_default()) }); } diff --git a/plugins/dialog/src/models.rs b/plugins/dialog/src/models.rs index 148f39ed..ea583f7a 100644 --- a/plugins/dialog/src/models.rs +++ b/plugins/dialog/src/models.rs @@ -2,8 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT -use std::str::FromStr; - use serde::{Deserialize, Deserializer, Serialize, Serializer}; /// Types of message, ask and confirm dialogs. @@ -95,16 +93,14 @@ impl From for MessageDialogResult { } } -impl FromStr for MessageDialogResult { - type Err = std::convert::Infallible; - - fn from_str(s: &str) -> Result { - match s { - "Yes" => Ok(Self::Yes), - "No" => Ok(Self::No), - "Ok" => Ok(Self::Ok), - "Cancel" => Ok(Self::Cancel), - _ => Ok(Self::Custom(s.to_string())), +impl From for MessageDialogResult { + fn from(value: String) -> Self { + match value.as_str() { + "Yes" => Self::Yes, + "No" => Self::No, + "Ok" => Self::Ok, + "Cancel" => Self::Cancel, + _ => Self::Custom(value), } } }