20 Persisted Scope
1分钟内可阅读完
保存文件系统与资源作用域,并在应用重新打开时恢复它们。
支持的平台
| 平台 | 支持程度 | 说明 |
|---|---|---|
| Windows | 完整支持 | |
| Linux | 完整支持 | |
| macOS | 完整支持 | |
| Android | 完整支持 | |
| iOS | 完整支持 |
设置
安装 persisted-scope 插件即可开始。
安装方式
自动
使用你的项目包管理器添加依赖:
| |
| |
| |
| |
| |
| |
手动
在
src-tauri文件夹中运行以下命令,把插件加入Cargo.toml里的项目依赖:1cargo add tauri-plugin-persisted-scope修改
lib.rs初始化插件:1 2 3 4 5 6 7#[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { tauri::Builder::default() .plugin(tauri_plugin_persisted_scope::init()) .run(tauri::generate_context!()) .expect("error while running tauri application"); }
警告
persisted-scope 插件必须在 fs 插件之后注册和初始化,如下例所示:
| |
否则持久化作用域将无法工作! 在开发模式下启动应用时,你还应该会看到类似这样的警告信息:
Please make sure to register the `fs` plugin before the `persisted-scope` plugin!
用法
设置完成后,该插件会自动保存并恢复文件系统与资源作用域。