mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-04-21 11:26:15 +02:00
fix(dialog): ask and confirm not using system button texts (#1910)
* Fix `ask`'s button texts being ok and cancel * Update change file
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"dialog": "patch"
|
||||
"dialog-js": "patch"
|
||||
---
|
||||
|
||||
Fix `ask` and `confirm` not using system button texts
|
||||
@@ -1 +1 @@
|
||||
if("__TAURI__"in window){var __TAURI_PLUGIN_DIALOG__=function(t){"use strict";async function n(t,n={},e){return window.__TAURI_INTERNALS__.invoke(t,n,e)}return"function"==typeof SuppressedError&&SuppressedError,t.ask=async function(t,e){const i="string"==typeof e?{title:e}:e;return await n("plugin:dialog|ask",{message:t.toString(),title:i?.title?.toString(),kind:i?.kind,okButtonLabel:i?.okLabel?.toString()??"Yes",cancelButtonLabel:i?.cancelLabel?.toString()??"No"})},t.confirm=async function(t,e){const i="string"==typeof e?{title:e}:e;return await n("plugin:dialog|confirm",{message:t.toString(),title:i?.title?.toString(),kind:i?.kind,okButtonLabel:i?.okLabel?.toString()??"Ok",cancelButtonLabel:i?.cancelLabel?.toString()??"Cancel"})},t.message=async function(t,e){const i="string"==typeof e?{title:e}:e;await n("plugin:dialog|message",{message:t.toString(),title:i?.title?.toString(),kind:i?.kind,okButtonLabel:i?.okLabel?.toString()})},t.open=async function(t={}){return"object"==typeof t&&Object.freeze(t),await n("plugin:dialog|open",{options:t})},t.save=async function(t={}){return"object"==typeof t&&Object.freeze(t),await n("plugin:dialog|save",{options:t})},t}({});Object.defineProperty(window.__TAURI__,"dialog",{value:__TAURI_PLUGIN_DIALOG__})}
|
||||
if("__TAURI__"in window){var __TAURI_PLUGIN_DIALOG__=function(t){"use strict";async function n(t,n={},e){return window.__TAURI_INTERNALS__.invoke(t,n,e)}return"function"==typeof SuppressedError&&SuppressedError,t.ask=async function(t,e){const i="string"==typeof e?{title:e}:e;return await n("plugin:dialog|ask",{message:t.toString(),title:i?.title?.toString(),kind:i?.kind,yesButtonLabel:i?.okLabel?.toString(),noButtonLabel:i?.cancelLabel?.toString()})},t.confirm=async function(t,e){const i="string"==typeof e?{title:e}:e;return await n("plugin:dialog|confirm",{message:t.toString(),title:i?.title?.toString(),kind:i?.kind,okButtonLabel:i?.okLabel?.toString(),cancelButtonLabel:i?.cancelLabel?.toString()})},t.message=async function(t,e){const i="string"==typeof e?{title:e}:e;await n("plugin:dialog|message",{message:t.toString(),title:i?.title?.toString(),kind:i?.kind,okButtonLabel:i?.okLabel?.toString()})},t.open=async function(t={}){return"object"==typeof t&&Object.freeze(t),await n("plugin:dialog|open",{options:t})},t.save=async function(t={}){return"object"==typeof t&&Object.freeze(t),await n("plugin:dialog|save",{options:t})},t}({});Object.defineProperty(window.__TAURI__,"dialog",{value:__TAURI_PLUGIN_DIALOG__})}
|
||||
|
||||
@@ -257,8 +257,8 @@ async function ask(
|
||||
message: message.toString(),
|
||||
title: opts?.title?.toString(),
|
||||
kind: opts?.kind,
|
||||
okButtonLabel: opts?.okLabel?.toString() ?? 'Yes',
|
||||
cancelButtonLabel: opts?.cancelLabel?.toString() ?? 'No'
|
||||
yesButtonLabel: opts?.okLabel?.toString(),
|
||||
noButtonLabel: opts?.cancelLabel?.toString()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -287,8 +287,8 @@ async function confirm(
|
||||
message: message.toString(),
|
||||
title: opts?.title?.toString(),
|
||||
kind: opts?.kind,
|
||||
okButtonLabel: opts?.okLabel?.toString() ?? 'Ok',
|
||||
cancelButtonLabel: opts?.cancelLabel?.toString() ?? 'Cancel'
|
||||
okButtonLabel: opts?.okLabel?.toString(),
|
||||
cancelButtonLabel: opts?.cancelLabel?.toString()
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ use tauri_plugin_fs::FsExt;
|
||||
|
||||
use crate::{
|
||||
Dialog, FileDialogBuilder, FilePath, MessageDialogButtons, MessageDialogKind, Result, CANCEL,
|
||||
OK,
|
||||
NO, OK, YES,
|
||||
};
|
||||
|
||||
#[derive(Serialize)]
|
||||
@@ -299,8 +299,8 @@ pub(crate) async fn ask<R: Runtime>(
|
||||
title: Option<String>,
|
||||
message: String,
|
||||
kind: Option<MessageDialogKind>,
|
||||
ok_button_label: Option<String>,
|
||||
cancel_button_label: Option<String>,
|
||||
yes_button_label: Option<String>,
|
||||
no_button_label: Option<String>,
|
||||
) -> Result<bool> {
|
||||
Ok(message_dialog(
|
||||
window,
|
||||
@@ -308,7 +308,16 @@ pub(crate) async fn ask<R: Runtime>(
|
||||
title,
|
||||
message,
|
||||
kind,
|
||||
get_ok_cancel_type(ok_button_label, cancel_button_label),
|
||||
if let Some(yes_button_label) = yes_button_label {
|
||||
MessageDialogButtons::OkCancelCustom(
|
||||
yes_button_label,
|
||||
no_button_label.unwrap_or(NO.to_string()),
|
||||
)
|
||||
} else if let Some(no_button_label) = no_button_label {
|
||||
MessageDialogButtons::OkCancelCustom(YES.to_string(), no_button_label)
|
||||
} else {
|
||||
MessageDialogButtons::YesNo
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
@@ -328,22 +337,15 @@ pub(crate) async fn confirm<R: Runtime>(
|
||||
title,
|
||||
message,
|
||||
kind,
|
||||
get_ok_cancel_type(ok_button_label, cancel_button_label),
|
||||
if let Some(ok_button_label) = ok_button_label {
|
||||
MessageDialogButtons::OkCancelCustom(
|
||||
ok_button_label,
|
||||
cancel_button_label.unwrap_or(CANCEL.to_string()),
|
||||
)
|
||||
} else if let Some(cancel_button_label) = cancel_button_label {
|
||||
MessageDialogButtons::OkCancelCustom(OK.to_string(), cancel_button_label)
|
||||
} else {
|
||||
MessageDialogButtons::OkCancel
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
fn get_ok_cancel_type(
|
||||
ok_button_label: Option<String>,
|
||||
cancel_button_label: Option<String>,
|
||||
) -> MessageDialogButtons {
|
||||
if let Some(ok_button_label) = ok_button_label {
|
||||
MessageDialogButtons::OkCancelCustom(
|
||||
ok_button_label,
|
||||
cancel_button_label.unwrap_or(CANCEL.to_string()),
|
||||
)
|
||||
} else if let Some(cancel_button_label) = cancel_button_label {
|
||||
MessageDialogButtons::OkCancelCustom(OK.to_string(), cancel_button_label)
|
||||
} else {
|
||||
MessageDialogButtons::OkCancel
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,6 +112,7 @@ impl From<MessageDialogButtons> for rfd::MessageButtons {
|
||||
match value {
|
||||
MessageDialogButtons::Ok => Self::Ok,
|
||||
MessageDialogButtons::OkCancel => Self::OkCancel,
|
||||
MessageDialogButtons::YesNo => Self::YesNo,
|
||||
MessageDialogButtons::OkCustom(ok) => Self::OkCustom(ok),
|
||||
MessageDialogButtons::OkCancelCustom(ok, cancel) => Self::OkCancelCustom(ok, cancel),
|
||||
}
|
||||
|
||||
@@ -43,6 +43,8 @@ use mobile::*;
|
||||
|
||||
pub(crate) const OK: &str = "Ok";
|
||||
pub(crate) const CANCEL: &str = "Cancel";
|
||||
pub(crate) const YES: &str = "Yes";
|
||||
pub(crate) const NO: &str = "No";
|
||||
|
||||
macro_rules! blocking_fn {
|
||||
($self:ident, $fn:ident) => {{
|
||||
@@ -236,6 +238,7 @@ impl<R: Runtime> MessageDialogBuilder<R> {
|
||||
let (ok_button_label, cancel_button_label) = match &self.buttons {
|
||||
MessageDialogButtons::Ok => (Some(OK), None),
|
||||
MessageDialogButtons::OkCancel => (Some(OK), Some(CANCEL)),
|
||||
MessageDialogButtons::YesNo => (Some(YES), Some(NO)),
|
||||
MessageDialogButtons::OkCustom(ok) => (Some(ok.as_str()), Some(CANCEL)),
|
||||
MessageDialogButtons::OkCancelCustom(ok, cancel) => {
|
||||
(Some(ok.as_str()), Some(cancel.as_str()))
|
||||
|
||||
@@ -59,6 +59,8 @@ pub enum MessageDialogButtons {
|
||||
Ok,
|
||||
/// 2 buttons `Ok` and `Cancel` with OS default dialog texts
|
||||
OkCancel,
|
||||
/// 2 buttons `Yes` and `No` with OS default dialog texts
|
||||
YesNo,
|
||||
/// A single `Ok` button with custom text
|
||||
OkCustom(String),
|
||||
/// 2 buttons `Ok` and `Cancel` with custom texts
|
||||
|
||||
Reference in New Issue
Block a user