|
|
|
@ -7,6 +7,8 @@ use std::{
|
|
|
|
|
path::{Path, PathBuf},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
use tauri_utils::acl::manifest::PermissionFile;
|
|
|
|
|
|
|
|
|
|
#[path = "src/scope.rs"]
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
mod scope;
|
|
|
|
@ -75,31 +77,31 @@ const BASE_DIR_VARS: &[&str] = &[
|
|
|
|
|
"APPCACHE",
|
|
|
|
|
"APPLOG",
|
|
|
|
|
];
|
|
|
|
|
const COMMANDS: &[&str] = &[
|
|
|
|
|
"mkdir",
|
|
|
|
|
"create",
|
|
|
|
|
"copy_file",
|
|
|
|
|
"remove",
|
|
|
|
|
"rename",
|
|
|
|
|
"truncate",
|
|
|
|
|
"ftruncate",
|
|
|
|
|
"write",
|
|
|
|
|
"write_file",
|
|
|
|
|
"write_text_file",
|
|
|
|
|
"read_dir",
|
|
|
|
|
"read_file",
|
|
|
|
|
"read",
|
|
|
|
|
"open",
|
|
|
|
|
"read_text_file",
|
|
|
|
|
"read_text_file_lines",
|
|
|
|
|
"read_text_file_lines_next",
|
|
|
|
|
"seek",
|
|
|
|
|
"stat",
|
|
|
|
|
"lstat",
|
|
|
|
|
"fstat",
|
|
|
|
|
"exists",
|
|
|
|
|
"watch",
|
|
|
|
|
"unwatch",
|
|
|
|
|
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", &[]),
|
|
|
|
|
("unwatch", &[]),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
@ -205,9 +207,47 @@ permissions = [
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tauri_plugin::Builder::new(COMMANDS)
|
|
|
|
|
tauri_plugin::Builder::new(&COMMANDS.iter().map(|c| c.0).collect::<Vec<_>>())
|
|
|
|
|
.global_api_script_path("./api-iife.js")
|
|
|
|
|
.global_scope_schema(schemars::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"))
|
|
|
|
|
{
|
|
|
|
|
p.commands
|
|
|
|
|
.allow
|
|
|
|
|
.extend(nested_commands.iter().map(|s| s.to_string()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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}"#
|
|
|
|
|
);
|
|
|
|
|
std::fs::write(permission_path, out)
|
|
|
|
|
.unwrap_or_else(|_| panic!("failed to write {command}.toml"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|