fix(settings): 「打开数据目录」改为打开资料目录,文案不再提 localStorage/IndexedDB
This commit is contained in:
1 parent
21a32c0fe3
commit
b20dbc9ad7
2 files changed
+21
-4
No files matched your search
+17
-1
@@ -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")]
|
||||
|
||||
@@ -139,16 +139,17 @@
|
||||
function DataDirRow () {
|
||||
const D = (typeof window !== 'undefined') ? window.IWBDesktop : null
|
||||
const enabled = !!(D && D.isTauri && D.isTauri())
|
||||
const [path, setPath] = React.useState('')
|
||||
// 初始就把「资料目录」显示出来(不等点按钮),避免把应用私有目录误当成数据所在
|
||||
const [path, setPath] = React.useState(() => { try { return (window.IWBStorageFile && window.IWBStorageFile.dir) ? window.IWBStorageFile.dir() : '' } catch (e) { return '' } })
|
||||
const [err, setErr] = React.useState('')
|
||||
if (!enabled) return el('div', { className: 'iwb-hint' }, '数据保存:本浏览器(localStorage/IndexedDB)')
|
||||
const open = async () => {
|
||||
try { setPath(await D.openDataDir()); setErr('') } catch (e) { setErr(String((e && e.message) || e)) }
|
||||
}
|
||||
return el('div', null,
|
||||
el('div', { className: 'iwb-hint' }, '数据保存:本机应用私有目录(localStorage / IndexedDB 都在里面)。' + (path ? ' 路径:' + path : '')),
|
||||
el('div', { className: 'iwb-hint' }, '数据保存:资料目录(data.json + canvases/ + images/,都是普通文件)。' + (path ? ' 路径:' + path : '')),
|
||||
el('div', { className: 'iwb-row' },
|
||||
el('button', { className: 'iwb-btn iwb-btn-sm', onClick: open }, '打开数据目录'),
|
||||
el('button', { className: 'iwb-btn iwb-btn-sm', onClick: open }, '打开资料目录'),
|
||||
err ? el('span', { className: 'iwb-status-err' }, err) : null,
|
||||
),
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user