mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-08-13 18:50:20 +02:00
fix(fs)!: use tauri::scope::fs::Scope (#2070)
This commit is contained in:
+21
-15
@@ -15,7 +15,7 @@ use serde::Deserialize;
|
||||
use tauri::{
|
||||
ipc::ScopeObject,
|
||||
plugin::{Builder as PluginBuilder, TauriPlugin},
|
||||
utils::acl::Value,
|
||||
utils::{acl::Value, config::FsScope},
|
||||
AppHandle, DragDropEvent, Manager, RunEvent, Runtime, WindowEvent,
|
||||
};
|
||||
|
||||
@@ -39,7 +39,6 @@ pub use desktop::Fs;
|
||||
pub use mobile::Fs;
|
||||
|
||||
pub use error::Error;
|
||||
pub use scope::{Event as ScopeEvent, Scope};
|
||||
|
||||
pub use file_path::FilePath;
|
||||
pub use file_path::SafeFilePath;
|
||||
@@ -365,21 +364,26 @@ impl ScopeObject for scope::Entry {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct Scope {
|
||||
pub(crate) scope: tauri::fs::Scope,
|
||||
pub(crate) require_literal_leading_dot: Option<bool>,
|
||||
}
|
||||
|
||||
pub trait FsExt<R: Runtime> {
|
||||
fn fs_scope(&self) -> &Scope;
|
||||
fn try_fs_scope(&self) -> Option<&Scope>;
|
||||
fn fs_scope(&self) -> tauri::fs::Scope;
|
||||
fn try_fs_scope(&self) -> Option<tauri::fs::Scope>;
|
||||
|
||||
/// Cross platform file system APIs that also support manipulating Android files.
|
||||
fn fs(&self) -> &Fs<R>;
|
||||
}
|
||||
|
||||
impl<R: Runtime, T: Manager<R>> FsExt<R> for T {
|
||||
fn fs_scope(&self) -> &Scope {
|
||||
self.state::<Scope>().inner()
|
||||
fn fs_scope(&self) -> tauri::fs::Scope {
|
||||
self.state::<Scope>().scope.clone()
|
||||
}
|
||||
|
||||
fn try_fs_scope(&self) -> Option<&Scope> {
|
||||
self.try_state::<Scope>().map(|s| s.inner())
|
||||
fn try_fs_scope(&self) -> Option<tauri::fs::Scope> {
|
||||
self.try_state::<Scope>().map(|s| s.scope.clone())
|
||||
}
|
||||
|
||||
fn fs(&self) -> &Fs<R> {
|
||||
@@ -419,11 +423,13 @@ pub fn init<R: Runtime>() -> TauriPlugin<R, Option<config::Config>> {
|
||||
watcher::unwatch
|
||||
])
|
||||
.setup(|app, api| {
|
||||
let mut scope = Scope::default();
|
||||
scope.require_literal_leading_dot = api
|
||||
.config()
|
||||
.as_ref()
|
||||
.and_then(|c| c.require_literal_leading_dot);
|
||||
let scope = Scope {
|
||||
require_literal_leading_dot: api
|
||||
.config()
|
||||
.as_ref()
|
||||
.and_then(|c| c.require_literal_leading_dot),
|
||||
scope: tauri::fs::Scope::new(app, &FsScope::default())?,
|
||||
};
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
{
|
||||
@@ -446,9 +452,9 @@ pub fn init<R: Runtime>() -> TauriPlugin<R, Option<config::Config>> {
|
||||
let scope = app.fs_scope();
|
||||
for path in paths {
|
||||
if path.is_file() {
|
||||
scope.allow_file(path);
|
||||
let _ = scope.allow_file(path);
|
||||
} else {
|
||||
scope.allow_directory(path, true);
|
||||
let _ = scope.allow_directory(path, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user