feat: 允许用户为 Code 和 Video 类型自定义支持的文件扩展名#55
Merged
GuoJikun merged 6 commits intoMay 14, 2026
Merged
Conversation
- 修改 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>
Agent-Logs-Url: https://github.com/GuoJikun/quicklook/sessions/14b87908-38c1-41c6-92fd-8823e5cd8154 Co-authored-by: GuoJikun <21582741+GuoJikun@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
GuoJikun
May 13, 2026 08:25
View session
Contributor
There was a problem hiding this comment.
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()withcustom_code_exts/custom_video_extsslices that act as a fallback after the built-in extension map. - Read
customCodeExtensions/customVideoExtensionsfrom theconfig.datastore insidepreview_file()and forward them toget_file_info(). - Add UI in
settings.vueto 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 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> |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: _zhiqiu <qwerboy0912@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Code 和 Video 类型的支持格式硬编码在 Rust 映射表中,用户无法扩展。Video 自定义格式需要 ffmpeg 转码才有意义,因此编辑入口应在 ffmpeg 启用后才开放。
后端(Rust)
utils/mod.rs:get_file_info()新增custom_code_exts/custom_video_exts参数,文件类型检测先匹配内置映射表,未命中时再检查用户自定义扩展名(自定义列表一次性小写化后比较,避免循环分配)preview.rs:引入StoreExt,在preview_file()中从config.datastore 读取customCodeExtensions/customVideoExtensions,传入get_file_info();store 不可用时降级为空数组前端(Vue)
settings.vue:useLocalFfmpeg为false时输入框和按钮禁用,addVideoExt()内部同样做状态守卫自定义扩展名在用户输入时统一
toLowerCase()+ 去除前缀.后存储,后端读取后直接与已小写化的文件扩展名做字符串相等比较。