mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-04-21 11:26:15 +02:00
fix(dialog): On Android, do not add a Cancel button to message dialogs (#873)
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"dialog": "patch"
|
||||
---
|
||||
|
||||
On Android, do not add a `Cancel` button to message dialogs.
|
||||
@@ -1,5 +1,5 @@
|
||||
<script>
|
||||
import { open, save, confirm } from "@tauri-apps/plugin-dialog";
|
||||
import { open, save, confirm, message } from "@tauri-apps/plugin-dialog";
|
||||
import { readFile } from "@tauri-apps/plugin-fs";
|
||||
|
||||
export let onMessage;
|
||||
@@ -22,6 +22,16 @@
|
||||
}
|
||||
|
||||
async function prompt() {
|
||||
confirm("Do you want to do something?")
|
||||
.then((res) =>
|
||||
onMessage(
|
||||
res ? "Yes" : "No"
|
||||
)
|
||||
)
|
||||
.catch(onMessage);
|
||||
}
|
||||
|
||||
async function promptCustom() {
|
||||
confirm("Is Tauri awesome?", {
|
||||
okLabel: "Absolutely",
|
||||
cancelLabel: "Totally",
|
||||
@@ -34,6 +44,10 @@
|
||||
.catch(onMessage);
|
||||
}
|
||||
|
||||
async function msg() {
|
||||
await message("Tauri is awesome!");
|
||||
}
|
||||
|
||||
function openDialog() {
|
||||
open({
|
||||
title: "My wonderful open dialog",
|
||||
@@ -130,3 +144,5 @@
|
||||
>Open save dialog</button
|
||||
>
|
||||
<button class="btn" id="prompt-dialog" on:click={prompt}>Prompt</button>
|
||||
<button class="btn" id="custom-prompt-dialog" on:click={promptCustom}>Prompt (custom)</button>
|
||||
<button class="btn" id="message-dialog" on:click={msg}>Message</button>
|
||||
|
||||
@@ -190,16 +190,16 @@ class DialogPlugin(private val activity: Activity): Plugin(activity) {
|
||||
dialog.dismiss()
|
||||
handler(false, true)
|
||||
}
|
||||
.setNegativeButton(
|
||||
args.cancelButtonLabel ?: "Cancel"
|
||||
) { dialog, _ ->
|
||||
dialog.dismiss()
|
||||
handler(false, false)
|
||||
}
|
||||
.setOnCancelListener { dialog ->
|
||||
dialog.dismiss()
|
||||
handler(true, false)
|
||||
}
|
||||
if (args.cancelButtonLabel != null) {
|
||||
builder.setNegativeButton( args.cancelButtonLabel) { dialog, _ ->
|
||||
dialog.dismiss()
|
||||
handler(false, false)
|
||||
}
|
||||
}
|
||||
val dialog = builder.create()
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user