feat(fs): enhance scope config to accept string as well (#1053)

* feat(fs): enhance scope config to accept string as well

* clippy

* Update protocol.rs

* regression resolving path variables

* add change file

---------

Co-authored-by: Lucas Nogueira <lucas@tauri.app>
This commit is contained in:
Amr Bashir
2024-03-26 11:37:03 -03:00
committed by GitHub
co-authored by Lucas Nogueira
parent fe4ad4dd5c
commit f39d362add
10 changed files with 189 additions and 112 deletions
+28 -2
View File
@@ -2,12 +2,38 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
use std::{fs::create_dir_all, path::Path};
use std::{
fs::create_dir_all,
path::{Path, PathBuf},
};
#[path = "src/scope.rs"]
#[allow(dead_code)]
mod scope;
/// FS scope entry.
#[derive(schemars::JsonSchema)]
#[serde(untagged)]
#[allow(unused)]
enum FsScopeEntry {
/// FS scope path.
Value(PathBuf),
Object {
/// FS scope path.
path: PathBuf,
},
}
// Ensure scope entry is kept up to date
impl From<FsScopeEntry> for scope::EntryRaw {
fn from(value: FsScopeEntry) -> Self {
match value {
FsScopeEntry::Value(path) => scope::EntryRaw::Value(path),
FsScopeEntry::Object { path } => scope::EntryRaw::Object { path },
}
}
}
const BASE_DIR_VARS: &[&str] = &[
"AUDIO",
"CACHE",
@@ -163,6 +189,6 @@ permissions = [
tauri_plugin::Builder::new(COMMANDS)
.global_api_script_path("./api-iife.js")
.global_scope_schema(schemars::schema_for!(scope::Entry))
.global_scope_schema(schemars::schema_for!(FsScopeEntry))
.build();
}