From<String>

pull/2641/head
amrbashir 2 months ago
parent 1202183987
commit dd22a8819c
No known key found for this signature in database

@ -279,18 +279,13 @@ pub(crate) async fn message<R: Runtime>(
ok_button_label: Option<String>,
buttons: Option<MessageDialogButtons>,
) -> Result<MessageDialogResult> {
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]

@ -121,7 +121,7 @@ pub fn show_message_dialog<R: Runtime, F: FnOnce(MessageDialogResult) + Send + '
.0
.run_mobile_plugin::<ShowMessageDialogResponse>("showMessageDialog", dialog.payload());
let res = res.map(|res| res.value.parse::<MessageDialogResult>().unwrap_or_default());
let res = res.map(|res| res.value.into());
f(res.unwrap_or_default())
});
}

@ -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<rfd::MessageDialogResult> for MessageDialogResult {
}
}
impl FromStr for MessageDialogResult {
type Err = std::convert::Infallible;
fn from_str(s: &str) -> Result<Self, Self::Err> {
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<String> 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),
}
}
}

Loading…
Cancel
Save