@@ -14,19 +14,21 @@ use tauri_macros::{command_enum, module_command_handler, CommandModule};
1414use std:: path:: PathBuf ;
1515
1616macro_rules! message_dialog {
17- ( $fn_name: ident, $allowlist: ident, $buttons: expr) => {
17+ ( $fn_name: ident, $allowlist: ident, $button_labels_type : ty , $ buttons: expr) => {
1818 #[ module_command_handler( $allowlist) ]
1919 fn $fn_name<R : Runtime >(
2020 context: InvokeContext <R >,
2121 title: Option <String >,
2222 message: String ,
2323 level: Option <MessageDialogType >,
24+ button_labels: $button_labels_type,
2425 ) -> super :: Result <bool > {
26+ let determine_button = $buttons;
2527 let mut builder = crate :: api:: dialog:: blocking:: MessageDialogBuilder :: new(
2628 title. unwrap_or_else( || context. window. app_handle. package_info( ) . name. clone( ) ) ,
2729 message,
2830 )
29- . buttons( $buttons ) ;
31+ . buttons( determine_button ( button_labels ) ) ;
3032 #[ cfg( any( windows, target_os = "macos" ) ) ]
3133 {
3234 builder = builder. parent( & context. window) ;
@@ -139,20 +141,26 @@ pub enum Cmd {
139141 message : String ,
140142 #[ serde( rename = "type" ) ]
141143 level : Option < MessageDialogType > ,
144+ #[ serde( rename = "buttonLabel" ) ]
145+ button_label : Option < String > ,
142146 } ,
143147 #[ cmd( dialog_ask, "dialog > ask" ) ]
144148 AskDialog {
145149 title : Option < String > ,
146150 message : String ,
147151 #[ serde( rename = "type" ) ]
148152 level : Option < MessageDialogType > ,
153+ #[ serde( rename = "buttonLabels" ) ]
154+ button_label : Option < ( String , String ) > ,
149155 } ,
150156 #[ cmd( dialog_confirm, "dialog > confirm" ) ]
151157 ConfirmDialog {
152158 title : Option < String > ,
153159 message : String ,
154160 #[ serde( rename = "type" ) ]
155161 level : Option < MessageDialogType > ,
162+ #[ serde( rename = "buttonLabels" ) ]
163+ button_labels : Option < ( String , String ) > ,
156164 } ,
157165}
158166
@@ -255,19 +263,36 @@ impl Cmd {
255263 message_dialog ! (
256264 message_dialog,
257265 dialog_message,
258- crate :: api:: dialog:: MessageDialogButtons :: Ok
266+ Option <String >,
267+ |label: Option <String >| {
268+ label
269+ . map( crate :: api:: dialog:: MessageDialogButtons :: OkWithLabel )
270+ . unwrap_or( crate :: api:: dialog:: MessageDialogButtons :: Ok )
271+ }
259272 ) ;
260273
261274 message_dialog ! (
262275 ask_dialog,
263276 dialog_ask,
264- crate :: api:: dialog:: MessageDialogButtons :: YesNo
277+ Option <( String , String ) >,
278+ |labels: Option <( String , String ) >| {
279+ labels
280+ . map( |( yes, no) | crate :: api:: dialog:: MessageDialogButtons :: OkCancelWithLabels ( yes, no) )
281+ . unwrap_or( crate :: api:: dialog:: MessageDialogButtons :: YesNo )
282+ }
265283 ) ;
266284
267285 message_dialog ! (
268286 confirm_dialog,
269287 dialog_confirm,
270- crate :: api:: dialog:: MessageDialogButtons :: OkCancel
288+ Option <( String , String ) >,
289+ |labels: Option <( String , String ) >| {
290+ labels
291+ . map( |( ok, cancel) | {
292+ crate :: api:: dialog:: MessageDialogButtons :: OkCancelWithLabels ( ok, cancel)
293+ } )
294+ . unwrap_or( crate :: api:: dialog:: MessageDialogButtons :: OkCancel )
295+ }
271296 ) ;
272297}
273298
0 commit comments