Skip to content

feat: 允许用户为 Code 和 Video 类型自定义支持的文件扩展名#55

Merged
GuoJikun merged 6 commits into
mainfrom
copilot/task-21582741-875893978-ea863470-3ce1-4311-b387-ae1e05525e93
May 14, 2026
Merged

feat: 允许用户为 Code 和 Video 类型自定义支持的文件扩展名#55
GuoJikun merged 6 commits into
mainfrom
copilot/task-21582741-875893978-ea863470-3ce1-4311-b387-ae1e05525e93

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 13, 2026

Code 和 Video 类型的支持格式硬编码在 Rust 映射表中,用户无法扩展。Video 自定义格式需要 ffmpeg 转码才有意义,因此编辑入口应在 ffmpeg 启用后才开放。

后端(Rust)

  • utils/mod.rsget_file_info() 新增 custom_code_exts / custom_video_exts 参数,文件类型检测先匹配内置映射表,未命中时再检查用户自定义扩展名(自定义列表一次性小写化后比较,避免循环分配)
  • preview.rs:引入 StoreExt,在 preview_file() 中从 config.data store 读取 customCodeExtensions / customVideoExtensions,传入 get_file_info();store 不可用时降级为空数组

前端(Vue)

  • settings.vue
    • 新增"自定义代码格式"独立设置区块,Tag 形式展示已添加的扩展名,支持输入添加和点击删除,数据持久化到 store
    • 视频设置区块内新增自定义视频格式编辑区,useLocalFfmpegfalse 时输入框和按钮禁用,addVideoExt() 内部同样做状态守卫
// 存储键
customCodeExtensions: string[]   // config.data store
customVideoExtensions: string[]  // config.data store

自定义扩展名在用户输入时统一 toLowerCase() + 去除前缀 . 后存储,后端读取后直接与已小写化的文件扩展名做字符串相等比较。

Copilot AI and others added 2 commits May 13, 2026 08:20
- 修改 Rust 后端 get_file_info() 接受用户自定义扩展名参数
- 修改 preview.rs 从 store 读取自定义扩展名并传入文件类型检测
- 修改 settings.vue 添加代码格式和视频格式自定义编辑 UI
  - 代码类型:随时可添加/删除自定义扩展名
  - 视频类型:仅在启用 ffmpeg 解析时可编辑

Agent-Logs-Url: https://github.com/GuoJikun/quicklook/sessions/14b87908-38c1-41c6-92fd-8823e5cd8154

Co-authored-by: GuoJikun <21582741+GuoJikun@users.noreply.github.com>
@GuoJikun GuoJikun marked this pull request as ready for review May 13, 2026 08:26
Copilot AI review requested due to automatic review settings May 13, 2026 08:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Allows users to extend the file extensions recognized as Code or Video, so that file types not present in the hard-coded Rust mapping can be previewed. The Video custom-extension editor is gated on useLocalFfmpeg since native decoding of non-standard formats requires ffmpeg transcoding.

Changes:

  • Extend get_file_info() with custom_code_exts / custom_video_exts slices that act as a fallback after the built-in extension map.
  • Read customCodeExtensions / customVideoExtensions from the config.data store inside preview_file() and forward them to get_file_info().
  • Add UI in settings.vue to add/remove custom code and video extensions (tag-list + input), persist them to the store, and disable the video editor when ffmpeg is not enabled.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src-tauri/src/utils/mod.rs Adds two extra parameters to get_file_info and falls back to user-defined extension lists when the built-in map misses.
src-tauri/src/preview.rs Imports StoreExt, reads the two custom extension lists from config.data, and passes them to get_file_info.
src/views/settings.vue Adds new settings sections (and CSS) for managing custom Code/Video extensions, with ffmpeg gating on the video side.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +159 to +170
let file_type_opt = file_type_opt.or_else(|| {
let ext_lower = extension.as_str(); // extension 已经是小写
let code_exts_lower: Vec<String> = custom_code_exts.iter().map(|e| e.to_lowercase()).collect();
let video_exts_lower: Vec<String> = custom_video_exts.iter().map(|e| e.to_lowercase()).collect();
if code_exts_lower.iter().any(|e| e == ext_lower) {
Some("Code".to_string())
} else if video_exts_lower.iter().any(|e| e == ext_lower) {
Some("Video".to_string())
} else {
None
}
});
Comment thread src/views/settings.vue
Comment on lines +254 to +263
<el-tag
v-for="ext in customVideoExts"
:key="ext"
closable
:disabled="!useLocalFfmpeg"
@close="useLocalFfmpeg && removeVideoExt(ext)"
style="margin: 2px 4px 2px 0"
>
{{ ext }}
</el-tag>
Comment thread src-tauri/src/preview.rs Outdated
GuoJikun and others added 4 commits May 13, 2026 16:41
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: _zhiqiu <qwerboy0912@gmail.com>
@GuoJikun GuoJikun merged commit 9f7d000 into main May 14, 2026
2 checks passed
@GuoJikun GuoJikun deleted the copilot/task-21582741-875893978-ea863470-3ce1-4311-b387-ae1e05525e93 branch May 14, 2026 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants