tauri-apps / tauri-apps/plugins-workspace
[persisted-scope] v2.0.0-alpha - Not persisted after restart ?
- Dominant language
- Rust
- Stars
- 1.8k
- Forks
- 602
- Avg merge
- 4d 14h
- Merged PRs (30d)
- 9
Description
Hi!
I have an issue where the scope isn't getting restored after restarting the application. Wonder if that plugin supports it.
If it doesn't, I'd have to have all the `*` variations in my `fs` allow scope but I don't want this for security reasons.
Here's what happening in my `main.rs` file, nothing special here.
```rust
fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_persisted_scope::init())
.plugin(tauri_plugin_fs::init())
.plugin(tauri_plugin_dialog::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
```
Then, in my app, I open a directory using the following piece of code :
```javascript
import { open } from '@tauri-apps/plugin-dialog';
import { documentDir } from '@tauri-apps/api/path';
const selectedFolderPath = await open({
multiple: false,
directory: true,
recursive: true,
defaultPath: await documentDir()
});
```
Then I save the path inside `localStorage`. When the app gets restarted, it reads that value from `localStorage` and tries to open back the folder with the following function (also used when opening for the first time the folder through `open`) :
```typescript
import { readDir } from "@tauri-apps/plugin-fs";
// I kinda liked the API of FileEntry in 1.x, so I tried to reimplement it.
export interface FileEntry {
name: string;
path: string;
children?: Array;
}
// Since I'm on Windows, I hardwritten this until I find another better way.
const sep = "\\";
export const listRecursivelyFilesInside = async (absolutePath: string): Promise> => {
const entries = await readDir(absolutePath);
const output: Array = [];
for (const entry of entries) {
if (entry.isDirectory) {
const dir = absolutePath + sep + entry.name;
const entries = await listRecursivelyFilesInside(dir);
output.push({
name: entry.name,
path: dir,
children: entries
});
}
else {
output.push({
name: entry.name,
path: absolutePath + sep + entry.name
});
}
}
return output;
}
```
But whenever I restart the app, I get hit by a `Error: "forbidden path: C:\\..."`.
Happens on development and production.
Any idea ? Thanks !
Contributor guide
Assessment
This issue has not been assessed yet.