fix: make builder methods chainable
This commit is contained in:
parent
db6a72cbdd
commit
e2914d8b7c
3 changed files with 101 additions and 75 deletions
|
@ -2,11 +2,9 @@ use anyhow::ensure;
|
|||
use tauri_sys::dialog::{FileDialogBuilder, MessageDialogBuilder, MessageDialogKind};
|
||||
|
||||
pub async fn ask() -> anyhow::Result<()> {
|
||||
let mut builder = MessageDialogBuilder::new();
|
||||
builder.set_title("Tauri");
|
||||
builder.set_kind(MessageDialogKind::Warning);
|
||||
|
||||
let works = builder
|
||||
let works = MessageDialogBuilder::new()
|
||||
.set_title("Tauri")
|
||||
.set_kind(MessageDialogKind::Warning)
|
||||
.ask("Does this work? \n Click Yes to mark this test as passing")
|
||||
.await?;
|
||||
|
||||
|
@ -16,11 +14,9 @@ pub async fn ask() -> anyhow::Result<()> {
|
|||
}
|
||||
|
||||
pub async fn confirm() -> anyhow::Result<()> {
|
||||
let mut builder = MessageDialogBuilder::new();
|
||||
builder.set_title("Tauri");
|
||||
builder.set_kind(MessageDialogKind::Warning);
|
||||
|
||||
let works = builder
|
||||
let works = MessageDialogBuilder::new()
|
||||
.set_title("Tauri")
|
||||
.set_kind(MessageDialogKind::Warning)
|
||||
.confirm("Does this work? \n Click Ok to mark this test as passing")
|
||||
.await?;
|
||||
|
||||
|
@ -30,20 +26,20 @@ pub async fn confirm() -> anyhow::Result<()> {
|
|||
}
|
||||
|
||||
pub async fn message() -> anyhow::Result<()> {
|
||||
let mut builder = MessageDialogBuilder::new();
|
||||
builder.set_title("Tauri");
|
||||
builder.set_kind(MessageDialogKind::Warning);
|
||||
|
||||
builder.message("This is a message just for you!").await?;
|
||||
MessageDialogBuilder::new()
|
||||
.set_title("Tauri")
|
||||
.set_kind(MessageDialogKind::Warning)
|
||||
.message("This is a message just for you!")
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn pick_file() -> anyhow::Result<()> {
|
||||
let mut builder = FileDialogBuilder::new();
|
||||
builder.set_title("Select a file to mark this test as passing");
|
||||
|
||||
let file = builder.pick_file().await?;
|
||||
let file = FileDialogBuilder::new()
|
||||
.set_title("Select a file to mark this test as passing")
|
||||
.pick_file()
|
||||
.await?;
|
||||
|
||||
ensure!(file.is_some());
|
||||
|
||||
|
@ -51,10 +47,10 @@ pub async fn pick_file() -> anyhow::Result<()> {
|
|||
}
|
||||
|
||||
pub async fn pick_files() -> anyhow::Result<()> {
|
||||
let mut builder = FileDialogBuilder::new();
|
||||
builder.set_title("Select a multiple files to mark this test as passing");
|
||||
|
||||
let file = builder.pick_files().await?;
|
||||
let file = FileDialogBuilder::new()
|
||||
.set_title("Select a multiple files to mark this test as passing")
|
||||
.pick_files()
|
||||
.await?;
|
||||
|
||||
ensure!(file.is_some());
|
||||
ensure!(file.unwrap().len() > 1);
|
||||
|
@ -63,10 +59,10 @@ pub async fn pick_files() -> anyhow::Result<()> {
|
|||
}
|
||||
|
||||
pub async fn pick_folder() -> anyhow::Result<()> {
|
||||
let mut builder = FileDialogBuilder::new();
|
||||
builder.set_title("Select a folder to mark this test as passing");
|
||||
|
||||
let file = builder.pick_folder().await?;
|
||||
let file = FileDialogBuilder::new()
|
||||
.set_title("Select a folder to mark this test as passing")
|
||||
.pick_folder()
|
||||
.await?;
|
||||
|
||||
ensure!(file.is_some());
|
||||
|
||||
|
@ -74,10 +70,10 @@ pub async fn pick_folder() -> anyhow::Result<()> {
|
|||
}
|
||||
|
||||
pub async fn pick_folders() -> anyhow::Result<()> {
|
||||
let mut builder = FileDialogBuilder::new();
|
||||
builder.set_title("Select a multiple folders to mark this test as passing");
|
||||
|
||||
let file = builder.pick_folders().await?;
|
||||
let file = FileDialogBuilder::new()
|
||||
.set_title("Select a multiple folders to mark this test as passing")
|
||||
.pick_folders()
|
||||
.await?;
|
||||
|
||||
ensure!(file.is_some());
|
||||
ensure!(file.unwrap().len() > 1);
|
||||
|
@ -86,10 +82,10 @@ pub async fn pick_folders() -> anyhow::Result<()> {
|
|||
}
|
||||
|
||||
pub async fn save() -> anyhow::Result<()> {
|
||||
let mut builder = FileDialogBuilder::new();
|
||||
builder.set_title("Select a file to mark this test as passing");
|
||||
|
||||
let file = builder.save().await?;
|
||||
let file = FileDialogBuilder::new()
|
||||
.set_title("Select a file to mark this test as passing")
|
||||
.save()
|
||||
.await?;
|
||||
|
||||
ensure!(file.is_some());
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue