文件系统
访问文件系统。
支持的平台
此插件需要 Rust 版本至少为 1.77.2
平台 | 级别 | 注释 |
---|---|---|
windows | 通过 MSI 或 NSIS 以 | |
linux | 无法写入访问 | |
macos | 无法写入访问 | |
android | | 默认情况下,访问权限仅限于应用程序文件夹 |
ios | | 默认情况下,访问权限仅限于应用程序文件夹 |
设置
安装 fs 插件以开始使用。
使用您的项目包管理器添加依赖项
npm run tauri add fs
yarn run tauri add fs
pnpm tauri add fs
deno task tauri add fs
bun tauri add fs
cargo tauri add fs
-
在
src-tauri
文件夹中运行以下命令,将插件添加到Cargo.toml
项目的依赖项中cargo add tauri-plugin-fs -
修改
lib.rs
以初始化插件src-tauri/src/lib.rs #[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() {tauri::Builder::default().plugin(tauri_plugin_fs::init()).run(tauri::generate_context!()).expect("error while running tauri application");} -
使用您首选的 JavaScript 包管理器安装 JavaScript Guest 绑定
npm install @tauri-apps/plugin-fsyarn add @tauri-apps/plugin-fspnpm add @tauri-apps/plugin-fsdeno add npm:@tauri-apps/plugin-fsbun add @tauri-apps/plugin-fs
配置
Android
当使用音频、缓存、文档、下载、图片、公共或视频目录时,您的应用必须具有外部存储的访问权限。
将以下权限添加到 gen/android/app/src/main/AndroidManifest.xml
文件中 manifest
标签中
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
iOS
Apple 要求应用开发者指定 API 使用的批准理由,以增强用户隐私。
您必须在 src-tauri/gen/apple
文件夹中创建一个 PrivacyInfo.xcprivacy
文件,其中包含所需的 NSPrivacyAccessedAPICategoryFileTimestamp 键和 C617.1 建议理由。
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"> <dict> <key>NSPrivacyAccessedAPITypes</key> <array> <dict> <key>NSPrivacyAccessedAPIType</key> <string>NSPrivacyAccessedAPICategoryFileTimestamp</string> <key>NSPrivacyAccessedAPITypeReasons</key> <array> <string>C617.1</string> </array> </dict> </array> </dict></plist>
用法
fs 插件在 JavaScript 和 Rust 中都可用。
import { exists, BaseDirectory } from '@tauri-apps/plugin-fs';// when using `"withGlobalTauri": true`, you may use// const { exists, BaseDirectory } = window.__TAURI__.fs;
// Check if the `$APPDATA/avatar.png` file existsawait exists('avatar.png', { baseDir: BaseDirectory.AppData });
use tauri_plugin_fs::FsExt;
#[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() { tauri::Builder::default() .plugin(tauri_plugin_fs::init()) .setup(|app| { // allowed the given directory let scope = app.fs_scope(); scope.allow_directory("/path/to/directory", false); dbg!(scope.allowed());
Ok(()) }) .run(tauri::generate_context!()) .expect("error while running tauri application");}
安全
此模块阻止路径遍历,不允许使用父目录访问器(即,不允许使用“/usr/path/to/../file”或“../path/to/file”路径)。使用此 API 访问的路径必须是相对于 基本目录 之一,或使用 path API 创建的。
有关更多信息,请参阅 @tauri-apps/plugin-fs - 安全。
路径
文件系统插件提供了两种操作路径的方式:基本目录 和 path API。
-
基本目录
每个 API 都有一个 options 参数,允许您定义一个 baseDir,它充当操作的工作目录。
import { readFile } from '@tauri-apps/plugin-fs';const contents = await readFile('avatars/tauri.png', {baseDir: BaseDirectory.Home,});在上面的示例中,读取了 ~/avatars/tauri.png 文件,因为我们正在使用 Home 基本目录。
-
path API
或者,您可以使用 path API 执行路径操作。
import { readFile } from '@tauri-apps/plugin-fs';import * as path from '@tauri-apps/api/path';const home = await path.homeDir();const contents = await readFile(await path.join(home, 'avatars/tauri.png'));
文件
创建
创建一个文件并返回其句柄。如果文件已存在,则将其截断。
import { create, BaseDirectory } from '@tauri-apps/plugin-fs';const file = await create('foo/bar.txt', { baseDir: BaseDirectory.AppData });await file.write(new TextEncoder().encode('Hello world'));await file.close();
写入
该插件为文本和二进制文件的写入提供了单独的 API,以提高性能。
-
文本文件
import { writeTextFile, BaseDirectory } from '@tauri-apps/plugin-fs';const contents = JSON.stringify({ notifications: true });await writeTextFile('config.json', contents, {baseDir: BaseDirectory.AppConfig,}); -
二进制文件
import { writeFile, BaseDirectory } from '@tauri-apps/plugin-fs';const contents = new Uint8Array(); // fill a byte arrayawait writeFile('config', contents, {baseDir: BaseDirectory.AppConfig,});
打开
打开一个文件并返回其句柄。使用此 API,您可以更好地控制文件的打开方式(只读模式、只写模式、追加而不是覆盖、仅在文件不存在时创建等)。
-
只读
这是默认模式。
import { open, BaseDirectory } from '@tauri-apps/plugin-fs';const file = await open('foo/bar.txt', {read: true,baseDir: BaseDirectory.AppData,});const stat = await file.stat();const buf = new Uint8Array(stat.size);await file.read(buf);const textContents = new TextDecoder().decode(buf);await file.close(); -
只写
import { open, BaseDirectory } from '@tauri-apps/plugin-fs';const file = await open('foo/bar.txt', {write: true,baseDir: BaseDirectory.AppData,});await file.write(new TextEncoder().encode('Hello world'));await file.close();默认情况下,文件会在任何
file.write()
调用时被截断。请参阅以下示例,了解如何追加到现有内容。 -
追加
import { open, BaseDirectory } from '@tauri-apps/plugin-fs';const file = await open('foo/bar.txt', {append: true,baseDir: BaseDirectory.AppData,});await file.write(new TextEncoder().encode('world'));await file.close();请注意,
{ append: true }
与{ write: true, append: true }
具有相同的效果。 -
截断
当设置了
truncate
选项并且文件已存在时,文件将被截断为长度 0。import { open, BaseDirectory } from '@tauri-apps/plugin-fs';const file = await open('foo/bar.txt', {write: true,truncate: true,baseDir: BaseDirectory.AppData,});await file.write(new TextEncoder().encode('world'));await file.close();此选项需要将
write
设置为true
。如果您想使用多个
file.write()
调用重写现有文件,则可以将其与append
选项一起使用。 -
创建
默认情况下,
open
API 仅打开现有文件。要创建文件(如果文件不存在),并在文件存在时打开它,请将create
设置为true
import { open, BaseDirectory } from '@tauri-apps/plugin-fs';const file = await open('foo/bar.txt', {write: true,create: true,baseDir: BaseDirectory.AppData,});await file.write(new TextEncoder().encode('world'));await file.close();为了创建文件,
write
或append
也必须设置为true
。如果文件已存在时要失败,请参阅
createNew
。 -
createNew
createNew
的工作方式类似于create
,但如果文件已存在,则会失败。import { open, BaseDirectory } from '@tauri-apps/plugin-fs';const file = await open('foo/bar.txt', {write: true,createNew: true,baseDir: BaseDirectory.AppData,});await file.write(new TextEncoder().encode('world'));await file.close();为了创建文件,
write
也必须设置为true
。
读取
该插件为文本和二进制文件的读取提供了单独的 API,以提高性能。
-
文本文件
import { readTextFile, BaseDirectory } from '@tauri-apps/plugin-fs';const configToml = await readTextFile('config.toml', {baseDir: BaseDirectory.AppConfig,});如果文件很大,您可以使用
readTextFileLines
API 流式传输其行。import { readTextFileLines, BaseDirectory } from '@tauri-apps/plugin-fs';const lines = await readTextFileLines('app.logs', {baseDir: BaseDirectory.AppLog,});for await (const line of lines) {console.log(line);} -
二进制文件
import { readFile, BaseDirectory } from '@tauri-apps/plugin-fs';const icon = await readFile('icon.png', {baseDir: BaseDirectory.Resources,});
移除
调用 remove()
以删除文件。如果文件不存在,则返回错误。
import { remove, BaseDirectory } from '@tauri-apps/plugin-fs';await remove('user.db', { baseDir: BaseDirectory.AppLocalData });
复制
copyFile
函数接受源路径和目标路径。请注意,您必须分别配置每个基本目录。
import { copyFile, BaseDirectory } from '@tauri-apps/plugin-fs';await copyFile('user.db', 'user.db.bk', { fromPathBaseDir: BaseDirectory.AppLocalData, toPathBaseDir: BaseDirectory.Temp,});
在上面的示例中,<app-local-data>/user.db 文件被复制到 $TMPDIR/user.db.bk。
存在
使用 exists()
函数检查文件是否存在
import { exists, BaseDirectory } from '@tauri-apps/plugin-fs';const tokenExists = await exists('token', { baseDir: BaseDirectory.AppLocalData,});
元数据
可以使用 stat
和 lstat
函数检索文件元数据。stat
遵循符号链接(如果其指向的实际文件不在作用域允许范围内,则返回错误),而 lstat
不遵循符号链接,而是返回符号链接本身的信息。
import { stat, BaseDirectory } from '@tauri-apps/plugin-fs';const metadata = await stat('app.db', { baseDir: BaseDirectory.AppLocalData,});
重命名
rename
函数接受源路径和目标路径。请注意,您必须分别配置每个基本目录。
import { rename, BaseDirectory } from '@tauri-apps/plugin-fs';await rename('user.db.bk', 'user.db', { fromPathBaseDir: BaseDirectory.AppLocalData, toPathBaseDir: BaseDirectory.Temp,});
在上面的示例中,<app-local-data>/user.db.bk 文件被重命名为 $TMPDIR/user.db。
截断
截断或扩展指定文件以达到指定的文件长度(默认为 0)。
- 截断为 0 长度
import { truncate } from '@tauri-apps/plugin-fs';await truncate('my_file.txt', 0, { baseDir: BaseDirectory.AppLocalData });
- 截断为特定长度
import { truncate, readTextFile, writeTextFile, BaseDirectory,} from '@tauri-apps/plugin-fs';
const filePath = 'file.txt';await writeTextFile(filePath, 'Hello World', { baseDir: BaseDirectory.AppLocalData,});await truncate(filePath, 7, { baseDir: BaseDirectory.AppLocalData,});const data = await readTextFile(filePath, { baseDir: BaseDirectory.AppLocalData,});console.log(data); // "Hello W"
目录
创建
要创建目录,请调用 mkdir
函数
import { mkdir, BaseDirectory } from '@tauri-apps/plugin-fs';await mkdir('images', { baseDir: BaseDirectory.AppLocalData,});
读取
readDir
函数递归列出目录的条目
import { readDir, BaseDirectory } from '@tauri-apps/plugin-fs';const entries = await readDir('users', { baseDir: BaseDirectory.AppLocalData });
移除
调用 remove()
以删除目录。如果目录不存在,则返回错误。
import { remove, BaseDirectory } from '@tauri-apps/plugin-fs';await remove('images', { baseDir: BaseDirectory.AppLocalData });
如果目录不为空,则必须将 recursive
选项设置为 true
import { remove, BaseDirectory } from '@tauri-apps/plugin-fs';await remove('images', { baseDir: BaseDirectory.AppLocalData, recursive: true,});
存在
使用 exists()
函数检查目录是否存在
import { exists, BaseDirectory } from '@tauri-apps/plugin-fs';const tokenExists = await exists('images', { baseDir: BaseDirectory.AppLocalData,});
元数据
可以使用 stat
和 lstat
函数检索目录元数据。stat
遵循符号链接(如果其指向的实际文件不在作用域允许范围内,则返回错误),而 lstat
不遵循符号链接,而是返回符号链接本身的信息。
import { stat, BaseDirectory } from '@tauri-apps/plugin-fs';const metadata = await stat('databases', { baseDir: BaseDirectory.AppLocalData,});
监视更改
要监视目录或文件的更改,请使用 watch
或 watchImmediate
函数。
-
watch
watch
经过防抖处理,因此仅在一定延迟后才发出事件import { watch, BaseDirectory } from '@tauri-apps/plugin-fs';await watch('app.log',(event) => {console.log('app.log event', event);},{baseDir: BaseDirectory.AppLog,delayMs: 500,}); -
watchImmediate
watchImmediate
立即通知事件的监听器import { watchImmediate, BaseDirectory } from '@tauri-apps/plugin-fs';await watchImmediate('logs',(event) => {console.log('logs directory event', event);},{baseDir: BaseDirectory.AppLog,recursive: true,});
默认情况下,目录上的监视操作是非递归的。将 recursive
选项设置为 true
以递归监视所有子目录的更改。
权限
默认情况下,所有潜在危险的插件命令和作用域都被阻止且无法访问。您必须修改 capabilities
配置中的权限才能启用这些。
有关更多信息,请参阅功能概述和使用插件权限的分步指南。
{ "$schema": "../gen/schemas/desktop-schema.json", "identifier": "main-capability", "description": "Capability for the main window", "windows": ["main"], "permissions": [ "fs:default", { "identifier": "fs:allow-exists", "allow": [{ "path": "$APPDATA/*" }] } ]}
默认权限
这组权限描述了 fs
插件默认启用或拒绝的文件系统访问类型。
已授予的权限
此默认权限集允许读取应用程序特定目录(AppConfig、AppData、AppLocalData、AppCache、AppLog)以及在其中创建的所有文件和子目录。这些目录的位置取决于运行应用程序的操作系统。
通常,这些目录需要在运行时由应用程序手动创建,然后才能访问其中的文件或文件夹。
因此,也允许通过 mkdir
命令创建所有这些文件夹。
拒绝的权限
默认情况下,此默认权限集会阻止访问 Tauri 应用程序的关键组件。在 Windows 上,Webview 数据文件夹访问被拒绝。
此默认权限集包括以下内容
create-app-specific-dirs
read-app-specific-dirs-recursive
deny-default
权限表
标识符 | 描述 |
---|---|
|
这允许对完整的应用程序文件夹、文件和子目录进行完全递归的读取访问。 |
|
这允许对完整的应用程序文件夹、文件和子目录进行完全递归的写入访问。 |
|
这允许对应用程序文件夹进行非递归的读取访问。 |
|
这允许对应用程序文件夹进行非递归的写入访问。 |
|
这允许对应用程序文件夹的元数据进行完全递归的读取访问,包括文件列表和统计信息。 |
|
这允许对应用程序文件夹的元数据进行非递归的读取访问,包括文件列表和统计信息。 |
|
此作用域允许对完整的应用程序文件夹(包括子目录和文件)进行递归访问。 |
|
此作用域允许访问应用程序文件夹中所有文件的以及顶层目录的内容列表。 |
|
此作用域允许列出应用程序目录中的所有文件和文件夹。 |
|
这允许对完整的 |
|
这允许对完整的 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
此作用域允许对完整的 |
|
此作用域允许访问 |
|
此作用域允许列出 |
|
这允许对完整的 |
|
这允许对完整的 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
此作用域允许对完整的 |
|
此作用域允许访问 |
|
此作用域允许列出 |
|
这允许对完整的 |
|
这允许对完整的 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
此作用域允许对完整的 |
|
此作用域允许访问 |
|
此作用域允许列出 |
|
这允许对完整的 |
|
这允许对完整的 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
此作用域允许对完整的 |
|
此作用域允许访问 |
|
此作用域允许列出 |
|
这允许对完整的 |
|
这允许对完整的 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
此作用域允许对完整的 |
|
此作用域允许访问 |
|
此作用域允许列出 |
|
这允许对完整的 |
|
这允许对完整的 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
此作用域允许对完整的 |
|
此作用域允许访问 |
|
此作用域允许列出 |
|
这允许对完整的 |
|
这允许对完整的 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
此作用域允许对完整的 |
|
此作用域允许访问 |
|
此作用域允许列出 |
|
这允许对完整的 |
|
这允许对完整的 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
此作用域允许对完整的 |
|
此作用域允许访问 |
|
此作用域允许列出 |
|
这允许对完整的 |
|
这允许对完整的 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
此作用域允许对完整的 |
|
此作用域允许访问 |
|
此作用域允许列出 |
|
这允许对完整的 |
|
这允许对完整的 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
此作用域允许对完整的 |
|
此作用域允许访问 |
|
此作用域允许列出 |
|
这允许对完整的 |
|
这允许对完整的 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
此作用域允许对完整的 |
|
此作用域允许访问 |
|
此作用域允许列出 |
|
这允许对完整的 |
|
这允许对完整的 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
此作用域允许对完整的 |
|
此作用域允许访问 |
|
此作用域允许列出 |
|
这允许对完整的 |
|
这允许对完整的 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
此作用域允许对完整的 |
|
此作用域允许访问 |
|
此作用域允许列出 |
|
这允许对完整的 |
|
这允许对完整的 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
此作用域允许对完整的 |
|
此作用域允许访问 |
|
此作用域允许列出 |
|
这允许对完整的 |
|
这允许对完整的 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
此作用域允许对完整的 |
|
此作用域允许访问 |
|
此作用域允许列出 |
|
这允许对完整的 |
|
这允许对完整的 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
此作用域允许对完整的 |
|
此作用域允许访问 |
|
此作用域允许列出 |
|
这允许对完整的 |
|
这允许对完整的 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
此作用域允许对完整的 |
|
此作用域允许访问 |
|
此作用域允许列出 |
|
这允许对完整的 |
|
这允许对完整的 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
此作用域允许对完整的 |
|
此作用域允许访问 |
|
此作用域允许列出 |
|
这允许对完整的 |
|
这允许对完整的 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
此作用域允许对完整的 |
|
此作用域允许访问 |
|
此作用域允许列出 |
|
这允许对完整的 |
|
这允许对完整的 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
此作用域允许对完整的 |
|
此作用域允许访问 |
|
此作用域允许列出 |
|
这允许对完整的 |
|
这允许对完整的 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
此作用域允许对完整的 |
|
此作用域允许访问 |
|
此作用域允许列出 |
|
这允许对完整的 |
|
这允许对完整的 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
此作用域允许对完整的 |
|
此作用域允许访问 |
|
此作用域允许列出 |
|
这允许对完整的 |
|
这允许对完整的 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
此作用域允许对完整的 |
|
此作用域允许访问 |
|
此作用域允许列出 |
|
这允许对完整的 |
|
这允许对完整的 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
这允许对 |
|
此作用域允许对完整的 |
|
此作用域允许访问 |
|
此作用域允许列出 |
|
启用 |
|
拒绝 |
|
启用 |
|
拒绝 |
|
启用 |
|
拒绝 |
|
启用 |
|
拒绝 |
|
启用 |
|
拒绝 |
|
启用 |
|
拒绝 |
|
启用 |
|
拒绝 |
|
启用 |
|
拒绝 |
|
启用 |
|
拒绝 |
|
启用 |
|
拒绝 |
|
启用 |
|
拒绝 |
|
启用 |
|
拒绝 |
|
启用 |
|
拒绝 |
|
启用 |
|
拒绝 |
|
启用 |
|
拒绝 |
|
启用 |
|
拒绝 |
|
启用 seek 命令,无需任何预配置的作用域。 |
|
禁用 seek 命令,无需任何预配置的作用域。 |
|
启用 size 命令,无需任何预配置的作用域。 |
|
禁用 size 命令,无需任何预配置的作用域。 |
|
启用 stat 命令,无需任何预配置的作用域。 |
|
禁用 stat 命令,无需任何预配置的作用域。 |
|
启用 truncate 命令,无需任何预配置的作用域。 |
|
禁用 truncate 命令,无需任何预配置的作用域。 |
|
启用 unwatch 命令,无需任何预配置的作用域。 |
|
禁用 unwatch 命令,无需任何预配置的作用域。 |
|
启用 watch 命令,无需任何预配置的作用域。 |
|
禁用 watch 命令,无需任何预配置的作用域。 |
|
启用 write 命令,无需任何预配置的作用域。 |
|
禁用 write 命令,无需任何预配置的作用域。 |
|
启用 write_file 命令,无需任何预配置的作用域。 |
|
禁用 write_file 命令,无需任何预配置的作用域。 |
|
启用 write_text_file 命令,无需任何预配置的作用域。 |
|
禁用 write_text_file 命令,无需任何预配置的作用域。 |
|
此权限允许创建应用程序特定的目录。 |
|
默认情况下,这会拒绝访问危险的 Tauri 相关文件和文件夹。 |
|
这拒绝读取 Linux 上 |
|
这拒绝读取 Windows 上 |
|
这将启用所有读取相关命令,无需任何预配置的可访问路径。 |
|
此权限允许对应用程序特定的基本目录进行递归读取操作。 |
|
这将启用目录读取和文件元数据相关命令,无需任何预配置的可访问路径。 |
|
这将启用文件读取相关命令,无需任何预配置的可访问路径。 |
|
这将启用所有索引或元数据相关命令,无需任何预配置的可访问路径。 |
|
一个空的权限,您可以用来修改全局作用域。 |
|
这将启用所有写入相关命令,无需任何预配置的可访问路径。 |
|
这将启用所有文件写入相关命令,无需任何预配置的可访问路径。 |
作用域
此插件权限包括用于定义允许或显式拒绝哪些路径的作用域。有关作用域的更多信息,请参阅命令作用域。
每个 allow
或 deny
作用域都必须包含一个数组,列出所有应允许或拒绝的路径。作用域条目的格式为 { path: string }
。
作用域条目可以使用 $<path>
变量来引用常见的系统路径,例如 home 目录、应用程序资源目录和配置目录。下表列出了您可以引用的所有常见路径
路径 | 变量 |
---|---|
appConfigDir | $APPCONFIG |
appDataDir | $APPDATA |
appLocalDataDir | $APPLOCALDATA |
appcacheDir | $APPCACHE |
applogDir | $APPLOG |
audioDir | $AUDIO |
cacheDir | $CACHE |
configDir | $CONFIG |
dataDir | $DATA |
localDataDir | $LOCALDATA |
desktopDir | $DESKTOP |
documentDir | $DOCUMENT |
downloadDir | $DOWNLOAD |
executableDir | $EXE |
fontDir | $FONT |
homeDir | $HOME |
pictureDir | $PICTURE |
publicDir | $PUBLIC |
runtimeDir | $RUNTIME |
templateDir | $TEMPLATE |
videoDir | $VIDEO |
resourceDir | $RESOURCE |
tempDir | $TEMP |
示例
- 全局作用域
要将作用域应用于任何 fs
命令,请使用 fs:scope
权限
{ "$schema": "../gen/schemas/desktop-schema.json", "identifier": "main-capability", "description": "Capability for the main window", "windows": ["main"], "permissions": [ { "identifier": "fs:scope", "allow": [{ "path": "$APPDATA" }, { "path": "$APPDATA/**" }] } ]}
要将作用域应用于特定的 fs
命令,请使用对象形式的权限 { "identifier": string, "allow"?: [], "deny"?: [] }
{ "$schema": "../gen/schemas/desktop-schema.json", "identifier": "main-capability", "description": "Capability for the main window", "windows": ["main"], "permissions": [ { "identifier": "fs:allow-rename", "allow": [{ "path": "$HOME/**" }] }, { "identifier": "fs:allow-rename", "deny": [{ "path": "$HOME/.config/**" }] }, { "identifier": "fs:allow-exists", "allow": [{ "path": "$APPDATA/*" }] } ]}
© 2025 Tauri Contributors. CC-BY / MIT