Skip to content

Commit dd22a88

Browse files
committed
From<String>
1 parent 1202183 commit dd22a88

File tree

3 files changed

+14
-23
lines changed

3 files changed

+14
-23
lines changed

plugins/dialog/src/commands.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -279,18 +279,13 @@ pub(crate) async fn message<R: Runtime>(
279279
ok_button_label: Option<String>,
280280
buttons: Option<MessageDialogButtons>,
281281
) -> Result<MessageDialogResult> {
282-
let buttons = buttons.unwrap_or_else(|| {
283-
if let Some(ok_button_label) = ok_button_label {
284-
MessageDialogButtons::OkCustom(ok_button_label)
285-
} else {
286-
MessageDialogButtons::Ok
287-
}
282+
let buttons = buttons.unwrap_or(if let Some(ok_button_label) = ok_button_label {
283+
MessageDialogButtons::OkCustom(ok_button_label)
284+
} else {
285+
MessageDialogButtons::Ok
288286
});
289287

290-
Ok(dbg!(message_dialog(
291-
window, dialog, title, message, kind, buttons
292-
)
293-
.blocking_show_with_result()))
288+
Ok(message_dialog(window, dialog, title, message, kind, buttons).blocking_show_with_result())
294289
}
295290

296291
#[command]

plugins/dialog/src/mobile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ pub fn show_message_dialog<R: Runtime, F: FnOnce(MessageDialogResult) + Send + '
121121
.0
122122
.run_mobile_plugin::<ShowMessageDialogResponse>("showMessageDialog", dialog.payload());
123123

124-
let res = res.map(|res| res.value.parse::<MessageDialogResult>().unwrap_or_default());
124+
let res = res.map(|res| res.value.into());
125125
f(res.unwrap_or_default())
126126
});
127127
}

plugins/dialog/src/models.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// SPDX-License-Identifier: Apache-2.0
33
// SPDX-License-Identifier: MIT
44

5-
use std::str::FromStr;
6-
75
use serde::{Deserialize, Deserializer, Serialize, Serializer};
86

97
/// Types of message, ask and confirm dialogs.
@@ -95,16 +93,14 @@ impl From<rfd::MessageDialogResult> for MessageDialogResult {
9593
}
9694
}
9795

98-
impl FromStr for MessageDialogResult {
99-
type Err = std::convert::Infallible;
100-
101-
fn from_str(s: &str) -> Result<Self, Self::Err> {
102-
match s {
103-
"Yes" => Ok(Self::Yes),
104-
"No" => Ok(Self::No),
105-
"Ok" => Ok(Self::Ok),
106-
"Cancel" => Ok(Self::Cancel),
107-
_ => Ok(Self::Custom(s.to_string())),
96+
impl From<String> for MessageDialogResult {
97+
fn from(value: String) -> Self {
98+
match value.as_str() {
99+
"Yes" => Self::Yes,
100+
"No" => Self::No,
101+
"Ok" => Self::Ok,
102+
"Cancel" => Self::Cancel,
103+
_ => Self::Custom(value),
108104
}
109105
}
110106
}

0 commit comments

Comments
 (0)