mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-07-08 16:07:50 +02:00
chore: update to tauri 3.0.0-alpha.9
autogenerated commands format changed, needed FS plugin small change
This commit is contained in:
+36
-88
@@ -7,8 +7,6 @@ use std::{
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use tauri_utils::acl::manifest::PermissionFile;
|
||||
|
||||
#[path = "src/scope.rs"]
|
||||
#[allow(dead_code)]
|
||||
mod scope;
|
||||
@@ -77,35 +75,35 @@ const BASE_DIR_VARS: &[&str] = &[
|
||||
"APPCACHE",
|
||||
"APPLOG",
|
||||
];
|
||||
const COMMANDS: &[(&str, &[&str])] = &[
|
||||
("mkdir", &[]),
|
||||
("create", &[]),
|
||||
("copy_file", &[]),
|
||||
("remove", &[]),
|
||||
("rename", &[]),
|
||||
("truncate", &[]),
|
||||
("ftruncate", &[]),
|
||||
("write", &[]),
|
||||
("write_file", &["open", "write"]),
|
||||
("write_text_file", &[]),
|
||||
("read_dir", &[]),
|
||||
("read_file", &[]),
|
||||
("read", &[]),
|
||||
("open", &[]),
|
||||
("read_text_file", &[]),
|
||||
("read_text_file_lines", &["read_text_file_lines_next"]),
|
||||
("read_text_file_lines_next", &[]),
|
||||
("seek", &[]),
|
||||
("stat", &[]),
|
||||
("lstat", &[]),
|
||||
("fstat", &[]),
|
||||
("exists", &[]),
|
||||
("watch", &[]),
|
||||
// `write_file` and `read_text_file_lines` allow nested commands, so their permissions are
|
||||
// manually authored in `permissions/commands/` instead of being autogenerated from this list.
|
||||
const COMMANDS: &[&str] = &[
|
||||
"mkdir",
|
||||
"create",
|
||||
"copy_file",
|
||||
"remove",
|
||||
"rename",
|
||||
"truncate",
|
||||
"ftruncate",
|
||||
"write",
|
||||
"write_text_file",
|
||||
"read_dir",
|
||||
"read_file",
|
||||
"read",
|
||||
"open",
|
||||
"read_text_file",
|
||||
"read_text_file_lines_next",
|
||||
"seek",
|
||||
"stat",
|
||||
"lstat",
|
||||
"fstat",
|
||||
"exists",
|
||||
"watch",
|
||||
// TODO: Remove this in v3
|
||||
("unwatch", &[]),
|
||||
("size", &[]),
|
||||
("start_accessing_security_scoped_resource", &[]),
|
||||
("stop_accessing_security_scoped_resource", &[]),
|
||||
"unwatch",
|
||||
"size",
|
||||
"start_accessing_security_scoped_resource",
|
||||
"stop_accessing_security_scoped_resource",
|
||||
];
|
||||
|
||||
fn main() {
|
||||
@@ -211,62 +209,12 @@ permissions = [
|
||||
}
|
||||
}
|
||||
|
||||
tauri_plugin::Builder::new(
|
||||
&COMMANDS
|
||||
.iter()
|
||||
// FIXME: https://docs.rs/crate/tauri-plugin-fs/2.1.0/builds/1571296
|
||||
.filter(|c| c.1.is_empty())
|
||||
.map(|c| c.0)
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
.global_api_script_path("./api-iife.js")
|
||||
.global_scope_schema(
|
||||
schemars::SchemaGenerator::new(schemars::generate::SchemaSettings::draft07())
|
||||
.into_root_schema_for::<FsScopeEntry>(),
|
||||
)
|
||||
.android_path("android")
|
||||
.build();
|
||||
|
||||
// workaround to include nested permissions as `tauri_plugin` doesn't support it
|
||||
let permissions_dir = autogenerated.join("commands");
|
||||
for (command, nested_commands) in COMMANDS {
|
||||
if nested_commands.is_empty() {
|
||||
continue;
|
||||
}
|
||||
|
||||
let permission_path = permissions_dir.join(format!("{command}.toml"));
|
||||
|
||||
let content = std::fs::read_to_string(&permission_path)
|
||||
.unwrap_or_else(|_| panic!("failed to read {command}.toml"));
|
||||
|
||||
let mut permission_file = toml::from_str::<PermissionFile>(&content)
|
||||
.unwrap_or_else(|_| panic!("failed to deserialize {command}.toml"));
|
||||
|
||||
for p in permission_file
|
||||
.permission
|
||||
.iter_mut()
|
||||
.filter(|p| p.identifier.starts_with("allow"))
|
||||
{
|
||||
for c in nested_commands.iter().map(|s| s.to_string()) {
|
||||
if !p.commands.allow.contains(&c) {
|
||||
p.commands.allow.push(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let out = toml::to_string_pretty(&permission_file)
|
||||
.unwrap_or_else(|_| panic!("failed to serialize {command}.toml"));
|
||||
let out = format!(
|
||||
r#"# Automatically generated - DO NOT EDIT!
|
||||
|
||||
"$schema" = "../../schemas/schema.json"
|
||||
|
||||
{out}"#
|
||||
);
|
||||
|
||||
if content != out {
|
||||
std::fs::write(permission_path, out)
|
||||
.unwrap_or_else(|_| panic!("failed to write {command}.toml"));
|
||||
}
|
||||
}
|
||||
tauri_plugin::Builder::new(COMMANDS)
|
||||
.global_api_script_path("./api-iife.js")
|
||||
.global_scope_schema(
|
||||
schemars::SchemaGenerator::new(schemars::generate::SchemaSettings::draft07())
|
||||
.into_root_schema_for::<FsScopeEntry>(),
|
||||
)
|
||||
.android_path("android")
|
||||
.build();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user