feat(dialog): Implemented android save dialog. (#1657)

* Implemented android save dialog.

* small cleanup

* lint

---------

Co-authored-by: Lucas Nogueira <lucas@tauri.app>
This commit is contained in:
mikoto2000
2024-08-13 20:41:30 +09:00
committed by GitHub
parent 5081f30daf
commit bc7eecf420
9 changed files with 112 additions and 12 deletions
+6 -3
View File
@@ -17,8 +17,10 @@ use tauri::{
Manager, Runtime,
};
#[cfg(any(desktop, target_os = "ios"))]
use std::fs;
use std::{
fs,
path::{Path, PathBuf},
sync::mpsc::sync_channel,
};
@@ -273,6 +275,7 @@ pub struct FileDialogBuilder<R: Runtime> {
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct FileDialogPayload<'a> {
file_name: &'a Option<String>,
filters: &'a Vec<Filter>,
multiple: bool,
}
@@ -298,6 +301,7 @@ impl<R: Runtime> FileDialogBuilder<R> {
#[cfg(mobile)]
pub(crate) fn payload(&self, multiple: bool) -> FileDialogPayload<'_> {
FileDialogPayload {
file_name: &self.file_name,
filters: &self.filters,
multiple,
}
@@ -471,7 +475,6 @@ impl<R: Runtime> FileDialogBuilder<R> {
/// })
/// })
/// ```
#[cfg(desktop)]
pub fn save_file<F: FnOnce(Option<PathBuf>) + Send + 'static>(self, f: F) {
save_file(self, f)
}
@@ -572,13 +575,13 @@ impl<R: Runtime> FileDialogBuilder<R> {
/// // the file path is `None` if the user closed the dialog
/// }
/// ```
#[cfg(desktop)]
pub fn blocking_save_file(self) -> Option<PathBuf> {
blocking_fn!(self, save_file)
}
}
// taken from deno source code: https://github.com/denoland/deno/blob/ffffa2f7c44bd26aec5ae1957e0534487d099f48/runtime/ops/fs.rs#L913
#[cfg(desktop)]
#[inline]
fn to_msec(maybe_time: std::result::Result<std::time::SystemTime, std::io::Error>) -> Option<u64> {
match maybe_time {