mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-05-25 13:17:47 +02:00
refactor: move deleted tauri APIs, prepare for next release (#355)
This commit is contained in:
committed by
GitHub
parent
937e6a5be6
commit
702b7b36bd
@@ -6,6 +6,7 @@ use std::path::PathBuf;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tauri::{command, Manager, Runtime, State, Window};
|
||||
use tauri_plugin_fs::FsExt;
|
||||
|
||||
use crate::{Dialog, FileDialogBuilder, FileResponse, MessageDialogKind, Result};
|
||||
|
||||
@@ -114,16 +115,18 @@ pub(crate) async fn open<R: Runtime>(
|
||||
let folders = dialog_builder.blocking_pick_folders();
|
||||
if let Some(folders) = &folders {
|
||||
for folder in folders {
|
||||
window
|
||||
.fs_scope()
|
||||
.allow_directory(folder, options.recursive)?;
|
||||
if let Some(s) = window.try_fs_scope() {
|
||||
s.allow_directory(folder, options.recursive)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
OpenResponse::Folders(folders)
|
||||
} else {
|
||||
let folder = dialog_builder.blocking_pick_folder();
|
||||
if let Some(path) = &folder {
|
||||
window.fs_scope().allow_directory(path, options.recursive)?;
|
||||
if let Some(s) = window.try_fs_scope() {
|
||||
s.allow_directory(path, options.recursive)?;
|
||||
}
|
||||
}
|
||||
OpenResponse::Folder(folder)
|
||||
}
|
||||
@@ -134,14 +137,24 @@ pub(crate) async fn open<R: Runtime>(
|
||||
let files = dialog_builder.blocking_pick_files();
|
||||
if let Some(files) = &files {
|
||||
for file in files {
|
||||
window.fs_scope().allow_file(&file.path)?;
|
||||
if let Some(s) = window.try_fs_scope() {
|
||||
s.allow_file(&file.path)?;
|
||||
}
|
||||
window
|
||||
.state::<tauri::scope::Scopes>()
|
||||
.allow_file(&file.path)?;
|
||||
}
|
||||
}
|
||||
OpenResponse::Files(files)
|
||||
} else {
|
||||
let file = dialog_builder.blocking_pick_file();
|
||||
if let Some(file) = &file {
|
||||
window.fs_scope().allow_file(&file.path)?;
|
||||
if let Some(s) = window.try_fs_scope() {
|
||||
s.allow_file(&file.path)?;
|
||||
}
|
||||
window
|
||||
.state::<tauri::scope::Scopes>()
|
||||
.allow_file(&file.path)?;
|
||||
}
|
||||
OpenResponse::File(file)
|
||||
};
|
||||
@@ -177,7 +190,10 @@ pub(crate) async fn save<R: Runtime>(
|
||||
|
||||
let path = dialog_builder.blocking_save_file();
|
||||
if let Some(p) = &path {
|
||||
window.fs_scope().allow_file(p)?;
|
||||
if let Some(s) = window.try_fs_scope() {
|
||||
s.allow_file(p)?;
|
||||
}
|
||||
window.state::<tauri::scope::Scopes>().allow_file(p)?;
|
||||
}
|
||||
|
||||
Ok(path)
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
|
||||
use serde::de::DeserializeOwned;
|
||||
use tauri::{plugin::PluginApi, AppHandle, Runtime};
|
||||
|
||||
@@ -101,6 +102,14 @@ impl From<MessageDialogKind> for rfd::MessageLevel {
|
||||
}
|
||||
}
|
||||
|
||||
struct WindowHandle(RawWindowHandle);
|
||||
|
||||
unsafe impl HasRawWindowHandle for WindowHandle {
|
||||
fn raw_window_handle(&self) -> RawWindowHandle {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<R: Runtime> From<FileDialogBuilder<R>> for FileDialog {
|
||||
fn from(d: FileDialogBuilder<R>) -> Self {
|
||||
let mut builder = FileDialog::new();
|
||||
@@ -119,8 +128,8 @@ impl<R: Runtime> From<FileDialogBuilder<R>> for FileDialog {
|
||||
builder = builder.add_filter(&filter.name, &v);
|
||||
}
|
||||
#[cfg(desktop)]
|
||||
if let Some(_parent) = d.parent {
|
||||
// TODO builder = builder.set_parent(&parent);
|
||||
if let Some(parent) = d.parent {
|
||||
builder = builder.set_parent(&WindowHandle(parent));
|
||||
}
|
||||
|
||||
builder
|
||||
@@ -144,8 +153,8 @@ impl<R: Runtime> From<MessageDialogBuilder<R>> for rfd::MessageDialog {
|
||||
dialog = dialog.set_buttons(buttons);
|
||||
}
|
||||
|
||||
if let Some(_parent) = d.parent {
|
||||
// TODO dialog.set_parent(parent);
|
||||
if let Some(parent) = d.parent {
|
||||
dialog = dialog.set_parent(&WindowHandle(parent));
|
||||
}
|
||||
|
||||
dialog
|
||||
|
||||
@@ -21,6 +21,8 @@ pub enum Error {
|
||||
#[cfg(mobile)]
|
||||
#[error("File save dialog is not implemented on mobile")]
|
||||
FileSaveDialogNotImplemented,
|
||||
#[error(transparent)]
|
||||
Fs(#[from] tauri_plugin_fs::Error),
|
||||
}
|
||||
|
||||
impl Serialize for Error {
|
||||
|
||||
Reference in New Issue
Block a user