Skip to content

Commit 91c9676

Browse files
Legend-Mastergezihuzi
authored andcommitted
fix(dialog): ask and confirm not using system button texts (tauri-apps#1910)
* Fix `ask`'s button texts being ok and cancel * Update change file
1 parent 3367fb5 commit 91c9676

File tree

7 files changed

+40
-26
lines changed

7 files changed

+40
-26
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"dialog": "patch"
3+
"dialog-js": "patch"
4+
---
5+
6+
Fix `ask` and `confirm` not using system button texts

plugins/dialog/api-iife.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/dialog/guest-js/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ async function ask(
257257
message: message.toString(),
258258
title: opts?.title?.toString(),
259259
kind: opts?.kind,
260-
okButtonLabel: opts?.okLabel?.toString() ?? 'Yes',
261-
cancelButtonLabel: opts?.cancelLabel?.toString() ?? 'No'
260+
yesButtonLabel: opts?.okLabel?.toString(),
261+
noButtonLabel: opts?.cancelLabel?.toString()
262262
})
263263
}
264264

@@ -287,8 +287,8 @@ async function confirm(
287287
message: message.toString(),
288288
title: opts?.title?.toString(),
289289
kind: opts?.kind,
290-
okButtonLabel: opts?.okLabel?.toString() ?? 'Ok',
291-
cancelButtonLabel: opts?.cancelLabel?.toString() ?? 'Cancel'
290+
okButtonLabel: opts?.okLabel?.toString(),
291+
cancelButtonLabel: opts?.cancelLabel?.toString()
292292
})
293293
}
294294

plugins/dialog/src/commands.rs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use tauri_plugin_fs::FsExt;
1010

1111
use crate::{
1212
Dialog, FileDialogBuilder, FilePath, MessageDialogButtons, MessageDialogKind, Result, CANCEL,
13-
OK,
13+
NO, OK, YES,
1414
};
1515

1616
#[derive(Serialize)]
@@ -299,16 +299,25 @@ pub(crate) async fn ask<R: Runtime>(
299299
title: Option<String>,
300300
message: String,
301301
kind: Option<MessageDialogKind>,
302-
ok_button_label: Option<String>,
303-
cancel_button_label: Option<String>,
302+
yes_button_label: Option<String>,
303+
no_button_label: Option<String>,
304304
) -> Result<bool> {
305305
Ok(message_dialog(
306306
window,
307307
dialog,
308308
title,
309309
message,
310310
kind,
311-
get_ok_cancel_type(ok_button_label, cancel_button_label),
311+
if let Some(yes_button_label) = yes_button_label {
312+
MessageDialogButtons::OkCancelCustom(
313+
yes_button_label,
314+
no_button_label.unwrap_or(NO.to_string()),
315+
)
316+
} else if let Some(no_button_label) = no_button_label {
317+
MessageDialogButtons::OkCancelCustom(YES.to_string(), no_button_label)
318+
} else {
319+
MessageDialogButtons::YesNo
320+
},
312321
))
313322
}
314323

@@ -328,22 +337,15 @@ pub(crate) async fn confirm<R: Runtime>(
328337
title,
329338
message,
330339
kind,
331-
get_ok_cancel_type(ok_button_label, cancel_button_label),
340+
if let Some(ok_button_label) = ok_button_label {
341+
MessageDialogButtons::OkCancelCustom(
342+
ok_button_label,
343+
cancel_button_label.unwrap_or(CANCEL.to_string()),
344+
)
345+
} else if let Some(cancel_button_label) = cancel_button_label {
346+
MessageDialogButtons::OkCancelCustom(OK.to_string(), cancel_button_label)
347+
} else {
348+
MessageDialogButtons::OkCancel
349+
},
332350
))
333351
}
334-
335-
fn get_ok_cancel_type(
336-
ok_button_label: Option<String>,
337-
cancel_button_label: Option<String>,
338-
) -> MessageDialogButtons {
339-
if let Some(ok_button_label) = ok_button_label {
340-
MessageDialogButtons::OkCancelCustom(
341-
ok_button_label,
342-
cancel_button_label.unwrap_or(CANCEL.to_string()),
343-
)
344-
} else if let Some(cancel_button_label) = cancel_button_label {
345-
MessageDialogButtons::OkCancelCustom(OK.to_string(), cancel_button_label)
346-
} else {
347-
MessageDialogButtons::OkCancel
348-
}
349-
}

plugins/dialog/src/desktop.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ impl From<MessageDialogButtons> for rfd::MessageButtons {
112112
match value {
113113
MessageDialogButtons::Ok => Self::Ok,
114114
MessageDialogButtons::OkCancel => Self::OkCancel,
115+
MessageDialogButtons::YesNo => Self::YesNo,
115116
MessageDialogButtons::OkCustom(ok) => Self::OkCustom(ok),
116117
MessageDialogButtons::OkCancelCustom(ok, cancel) => Self::OkCancelCustom(ok, cancel),
117118
}

plugins/dialog/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ use mobile::*;
4343

4444
pub(crate) const OK: &str = "Ok";
4545
pub(crate) const CANCEL: &str = "Cancel";
46+
pub(crate) const YES: &str = "Yes";
47+
pub(crate) const NO: &str = "No";
4648

4749
macro_rules! blocking_fn {
4850
($self:ident, $fn:ident) => {{
@@ -236,6 +238,7 @@ impl<R: Runtime> MessageDialogBuilder<R> {
236238
let (ok_button_label, cancel_button_label) = match &self.buttons {
237239
MessageDialogButtons::Ok => (Some(OK), None),
238240
MessageDialogButtons::OkCancel => (Some(OK), Some(CANCEL)),
241+
MessageDialogButtons::YesNo => (Some(YES), Some(NO)),
239242
MessageDialogButtons::OkCustom(ok) => (Some(ok.as_str()), Some(CANCEL)),
240243
MessageDialogButtons::OkCancelCustom(ok, cancel) => {
241244
(Some(ok.as_str()), Some(cancel.as_str()))

plugins/dialog/src/models.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ pub enum MessageDialogButtons {
5959
Ok,
6060
/// 2 buttons `Ok` and `Cancel` with OS default dialog texts
6161
OkCancel,
62+
/// 2 buttons `Yes` and `No` with OS default dialog texts
63+
YesNo,
6264
/// A single `Ok` button with custom text
6365
OkCustom(String),
6466
/// 2 buttons `Ok` and `Cancel` with custom texts

0 commit comments

Comments
 (0)