mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-08-13 18:50:20 +02:00
feat: update to tauri beta, add permissions (#862)
Co-authored-by: Lucas Nogueira <lucas@tauri.app> Co-authored-by: Lucas Nogueira <lucas@crabnebula.dev>
This commit is contained in:
co-authored by
Lucas Nogueira
Lucas Nogueira
parent
506ce4835b
commit
d198c01486
+38
-18
@@ -11,21 +11,25 @@
|
||||
html_favicon_url = "https://github.com/tauri-apps/tauri/raw/dev/app-icon.png"
|
||||
)]
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use serde::Deserialize;
|
||||
use tauri::{
|
||||
ipc::ScopeObject,
|
||||
plugin::{Builder as PluginBuilder, TauriPlugin},
|
||||
scope::fs::Scope,
|
||||
utils::config::FsScope,
|
||||
FileDropEvent, Manager, RunEvent, Runtime, WindowEvent,
|
||||
utils::acl::Value,
|
||||
AppHandle, FileDropEvent, Manager, RunEvent, Runtime, WindowEvent,
|
||||
};
|
||||
|
||||
mod commands;
|
||||
mod config;
|
||||
mod error;
|
||||
mod scope;
|
||||
#[cfg(feature = "watch")]
|
||||
mod watcher;
|
||||
|
||||
pub use config::Config;
|
||||
pub use error::Error;
|
||||
pub use scope::{Event as ScopeEvent, Scope};
|
||||
|
||||
type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
@@ -44,8 +48,27 @@ impl<R: Runtime, T: Manager<R>> FsExt<R> for T {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init<R: Runtime>() -> TauriPlugin<R, Option<Config>> {
|
||||
PluginBuilder::<R, Option<Config>>::new("fs")
|
||||
impl ScopeObject for scope::Entry {
|
||||
type Error = Error;
|
||||
fn deserialize<R: Runtime>(
|
||||
app: &AppHandle<R>,
|
||||
raw: Value,
|
||||
) -> std::result::Result<Self, Self::Error> {
|
||||
#[derive(Deserialize)]
|
||||
struct EntryRaw {
|
||||
path: PathBuf,
|
||||
}
|
||||
|
||||
let entry = serde_json::from_value::<EntryRaw>(raw.into())?;
|
||||
|
||||
Ok(Self {
|
||||
path: app.path().parse(entry.path)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init<R: Runtime>() -> TauriPlugin<R, Option<config::Config>> {
|
||||
PluginBuilder::<R, Option<config::Config>>::new("fs")
|
||||
.js_init_script(include_str!("api-iife.js").to_string())
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
commands::create,
|
||||
@@ -76,16 +99,13 @@ pub fn init<R: Runtime>() -> TauriPlugin<R, Option<Config>> {
|
||||
#[cfg(feature = "watch")]
|
||||
watcher::unwatch
|
||||
])
|
||||
.setup(|app: &tauri::AppHandle<R>, api| {
|
||||
let default_scope = FsScope::default();
|
||||
app.manage(Scope::new(
|
||||
app,
|
||||
api.config()
|
||||
.as_ref()
|
||||
.map(|c| &c.scope)
|
||||
.unwrap_or(&default_scope),
|
||||
)?);
|
||||
|
||||
.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);
|
||||
app.manage(scope);
|
||||
Ok(())
|
||||
})
|
||||
.on_event(|app, event| {
|
||||
@@ -98,9 +118,9 @@ pub fn init<R: Runtime>() -> TauriPlugin<R, Option<Config>> {
|
||||
let scope = app.fs_scope();
|
||||
for path in paths {
|
||||
if path.is_file() {
|
||||
let _ = scope.allow_file(path);
|
||||
scope.allow_file(path);
|
||||
} else {
|
||||
let _ = scope.allow_directory(path, false);
|
||||
scope.allow_directory(path, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user