fix(settings): 「打开数据目录」改为打开资料目录,文案不再提 localStorage/IndexedDB

This commit is contained in:
qiqi committed 2026-11-17 06:52:13 +08:00
1 parent 21a32c0fe3
commit b20dbc9ad7
2 files changed
+21 -4

No files matched your search

+17 -1
View File
@@ -136,13 +136,29 @@ fn grant_dir(app: AppHandle, dir: String) -> Result<String, String> {
app.fs_scope()
.allow_directory(&p, true)
.map_err(|e| e.to_string())?;
// 记到 app config:这样「打开资料目录」按钮不需要前端传路径,也不给前端任意开目录的能力
if let Ok(cfg) = app.path().app_config_dir() {
let _ = std::fs::create_dir_all(&cfg);
let _ = std::fs::write(cfg.join("data-dir.txt"), p.to_string_lossy().as_bytes());
}
Ok(p.to_string_lossy().to_string())
}
// 打开应用数据目录(设置里的「打开数据目录」按钮用;macOS 访达 / Windows 资源管理器 / Linux xdg-open)
#[tauri::command]
fn open_app_data_dir(app: AppHandle) -> Result<String, String> {
let dir = app.path().app_data_dir().map_err(|e| e.to_string())?;
// 资料目录(用户选的那个)优先;没设置过才退回应用私有目录
let recorded = app
.path()
.app_config_dir()
.ok()
.and_then(|c| std::fs::read_to_string(c.join("data-dir.txt")).ok())
.map(|s| s.trim().to_string())
.filter(|s| !s.is_empty() && std::path::Path::new(s).exists());
let dir = match recorded {
Some(p) => std::path::PathBuf::from(p),
None => app.path().app_data_dir().map_err(|e| e.to_string())?,
};
std::fs::create_dir_all(&dir).map_err(|e| e.to_string())?;
let path = dir.to_string_lossy().to_string();
#[cfg(target_os = "macos")]