feat: improve DX of events (#12)

* feat: improve DX of events

* Update global_shortcut.rs

* Update event.rs

* deploy docs to gh pages

* Delete rustdoc.yml

* add tests for global shortcut

* improve logs produced by tauri_log

* wip docs

* update docs

* move error to separate module

* feat: simplify functions returning array backed iterators

* rebase and cleanup

* fixes
This commit is contained in:
Jonas Kruckenberg 2022-11-19 20:33:06 +01:00 committed by GitHub
parent 300fe18d22
commit e28a0bb749
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 655 additions and 289 deletions

View file

@ -19,9 +19,11 @@
//! ```
//! It is recommended to allowlist only the APIs you use for optimal bundle size and security.
use js_sys::Array;
use serde::Serialize;
use std::path::{Path, PathBuf};
use crate::utils::ArrayIterator;
#[derive(Debug, Clone, Copy, Hash, Serialize)]
struct DialogFilter<'a> {
extensions: &'a [&'a str],
@ -162,12 +164,19 @@ impl<'a> FileDialogBuilder<'a> {
/// ```
///
/// Requires [`allowlist > dialog > open`](https://tauri.app/v1/api/config#dialogallowlistconfig.open) to be enabled.
pub async fn pick_files(&mut self) -> crate::Result<Option<Vec<PathBuf>>> {
pub async fn pick_files(&mut self) -> crate::Result<Option<impl Iterator<Item = PathBuf>>> {
self.multiple = true;
let raw = inner::open(serde_wasm_bindgen::to_value(&self)?).await?;
Ok(serde_wasm_bindgen::from_value(raw)?)
if let Ok(files) = Array::try_from(raw) {
let files =
ArrayIterator::new(files).map(|raw| serde_wasm_bindgen::from_value(raw).unwrap());
Ok(Some(files))
} else {
Ok(None)
}
}
/// Shows the dialog to select a single folder.
@ -206,13 +215,20 @@ impl<'a> FileDialogBuilder<'a> {
/// ```
///
/// Requires [`allowlist > dialog > open`](https://tauri.app/v1/api/config#dialogallowlistconfig.open) to be enabled.
pub async fn pick_folders(&mut self) -> crate::Result<Option<Vec<PathBuf>>> {
pub async fn pick_folders(&mut self) -> crate::Result<Option<impl Iterator<Item = PathBuf>>> {
self.directory = true;
self.multiple = true;
let raw = inner::open(serde_wasm_bindgen::to_value(&self)?).await?;
Ok(serde_wasm_bindgen::from_value(raw)?)
if let Ok(files) = Array::try_from(raw) {
let files =
ArrayIterator::new(files).map(|raw| serde_wasm_bindgen::from_value(raw).unwrap());
Ok(Some(files))
} else {
Ok(None)
}
}
/// Open a file/directory save dialog.