fix: 修复项目详情页打开文件夹功能

问题分析:
1. 权限问题:Tauri opener插件缺少必要的权限配置
2. 路径格式问题:Windows长路径格式(\\?\前缀)导致opener插件无法处理

修复方案:
1. 权限配置修复:
   - 在capabilities/default.json中添加opener:allow-open-path权限
   - 添加opener:allow-reveal-item-in-dir权限
   - 同时添加fs和dialog相关权限以支持完整功能

2. 路径处理优化:
   - 检测并移除Windows长路径前缀(\\?\)
   - 添加备用方案:如果openPath失败,尝试revealItemInDir
   - 增加错误处理和用户友好的提示信息
   - 添加调试日志便于问题排查

技术细节:
- openPath: 直接打开文件夹
- revealItemInDir: 在文件管理器中显示文件夹
- 路径标准化处理确保跨平台兼容性

现在项目详情页的打开文件夹功能应该可以正常工作了!
This commit is contained in:
imeepos 2025-07-13 22:00:30 +08:00
parent 27353e352f
commit 6978b8bbfd
3 changed files with 34 additions and 3 deletions

View File

@ -31,5 +31,5 @@
### 优化
提交代码 然后优化:
feature: 我已经确认环境中已经安装了 ffmpeg和ffmprobe 日志却显示:场景检测失败
TODO: 需要优化成一刀切
feature: 在导入时启动异步处理(更好的用户体验)

View File

@ -5,6 +5,14 @@
"windows": ["main"],
"permissions": [
"core:default",
"opener:default"
"opener:default",
"opener:allow-open-path",
"opener:allow-reveal-item-in-dir",
"fs:default",
"fs:allow-read-file",
"fs:allow-read-dir",
"dialog:default",
"dialog:allow-open",
"dialog:allow-save"
]
}

View File

@ -61,9 +61,32 @@ export const ProjectDetails: React.FC = () => {
if (project) {
try {
const { openPath } = await import('@tauri-apps/plugin-opener');
await openPath(project.path);
// 处理 Windows 路径格式,移除 \\?\ 前缀
let normalizedPath = project.path;
if (normalizedPath.startsWith('\\\\?\\')) {
normalizedPath = normalizedPath.substring(4);
}
console.log('尝试打开路径:', normalizedPath);
await openPath(normalizedPath);
} catch (error) {
console.error('打开文件夹失败:', error);
// 如果 openPath 失败,尝试使用 revealItemInDir
try {
const { revealItemInDir } = await import('@tauri-apps/plugin-opener');
let normalizedPath = project.path;
if (normalizedPath.startsWith('\\\\?\\')) {
normalizedPath = normalizedPath.substring(4);
}
console.log('尝试使用 revealItemInDir 打开:', normalizedPath);
await revealItemInDir(normalizedPath);
} catch (fallbackError) {
console.error('备用方法也失败:', fallbackError);
// 可以在这里显示用户友好的错误提示
alert('无法打开文件夹,请检查路径是否存在');
}
}
}
};