Skip to content

Commit

Permalink
feat(core): expose message dialog's title option, ref #4183 (#4186)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored May 21, 2022
1 parent a7a9fde commit ae99f99
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changes/expose-message-dialog-title.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri": patch
"api": patch
---

Expose `title` option in the message dialog API.
2 changes: 1 addition & 1 deletion core/tauri/scripts/bundle.js

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions core/tauri/src/endpoints/dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ pub enum Cmd {
#[cmd(dialog_save, "dialog > save")]
SaveDialog { options: SaveDialogOptions },
#[cmd(dialog_message, "dialog > message")]
MessageDialog { message: String },
MessageDialog {
title: Option<String>,
message: String,
},
#[cmd(dialog_ask, "dialog > ask")]
AskDialog {
title: Option<String>,
Expand Down Expand Up @@ -168,10 +171,14 @@ impl Cmd {
}

#[module_command_handler(dialog_message)]
fn message_dialog<R: Runtime>(context: InvokeContext<R>, message: String) -> super::Result<()> {
fn message_dialog<R: Runtime>(
context: InvokeContext<R>,
title: Option<String>,
message: String,
) -> super::Result<()> {
crate::api::dialog::blocking::message(
Some(&context.window),
&context.window.app_handle.package_info().name,
title.unwrap_or_else(|| context.window.app_handle.package_info().name.clone()),
message,
);
Ok(())
Expand Down
3 changes: 2 additions & 1 deletion tooling/api/src/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,12 @@ async function save(options: SaveDialogOptions = {}): Promise<string> {
*
* @return {Promise<void>} A promise indicating the success or failure of the operation.
*/
async function message(message: string): Promise<void> {
async function message(message: string, title?: string): Promise<void> {
return invokeTauriCommand({
__tauriModule: 'Dialog',
message: {
cmd: 'messageDialog',
title,
message
}
})
Expand Down

0 comments on commit ae99f99

Please sign in to comment.