Skip to content
This repository was archived by the owner on Jul 17, 2026. It is now read-only.

refactor(download): 重构下载管理器以支持自定义下载类型 将自定义下载相关字段从 SongType 中分离,新增独立的 CustomDownloadType 类型。重构下载管理器实现策略模式,将歌曲下载和自定义下载分别封装为 SongDownloadStrategy 和 CustomDownloadStrategy 类,统一通过 DownloadStrategy 接口处理。同时提取歌词处理逻辑到 LyricHelper 辅助类,优化代码结构和可维护性。 - #829

Merged
kazukokawagawa merged 9 commits into
devfrom
dev-fix
Feb 7, 2026

Conversation

@kazukokawagawa

Copy link
Copy Markdown
Collaborator

No description provided.

- 拆分过长的 import 语句为多行
- 调整条件运算符和长字符串的换行以符合代码规范
- 统一代码缩进和括号风格
- 移除行尾多余的空格
将自定义下载相关字段从 SongType 中分离,新增独立的 CustomDownloadType 类型。重构下载管理器实现策略模式,将歌曲下载和自定义下载分别封装为 SongDownloadStrategy 和 CustomDownloadStrategy 类,统一通过 DownloadStrategy 接口处理。同时提取歌词处理逻辑到 LyricHelper 辅助类,优化代码结构和可维护性。
- 将 LyricHelper 类重构为纯函数式的 LyricProcessor 模块,减少对 Store 的直接依赖
- 为 CustomDownloadType 添加 type 字段以支持 discriminated union
- 在下载管理器启动时迁移旧的自定义下载任务数据
- 统一歌词处理选项传递方式,提高代码可测试性和可维护性
- 将逐字歌词获取逻辑从 LyricProcessor 移至 DownloadManager
- 引入 generateVerbatimContent 和 generateAssContent 纯函数生成文件内容
- 统一处理旧数据迁移中的 type 字段推断逻辑
- 保持原有功能不变,提高代码可测试性和模块化
确保在应用启动时统一处理旧数据的 type 字段迁移,避免在下载过程中重复执行。这解决了下载管理器可能因迁移逻辑而延迟初始化的问题,并保证了数据一致性。
新增 `save-file` IPC 处理器,支持将内容写入指定路径的文件。处理编码参数并提供错误日志记录。
@kazukokawagawa
kazukokawagawa marked this pull request as ready for review February 6, 2026 04:44
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @kazukokawagawa, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求对下载管理系统进行了重大改进,通过引入策略模式和专用类型,增强了对自定义下载的支持。歌词处理功能被封装到独立的模块中,提升了代码结构和可维护性。这些变更使得下载流程更加灵活、健壮,并为未来的功能扩展奠定了基础。

Highlights

  • 下载管理器重构: 下载管理器已使用策略模式进行全面重构,以更清晰地分离歌曲下载和自定义下载逻辑。现在,歌曲下载由 SongDownloadStrategy 处理,而自定义下载则由 CustomDownloadStrategy 处理,两者都遵循 DownloadStrategy 接口。
  • 自定义下载类型: 新增了独立的 CustomDownloadType 类型,将自定义下载相关的字段(如 url 和 referer)从 SongType 中分离出来,使类型定义更加清晰和专业。数据存储也已更新以支持此新类型。
  • 歌词处理模块化: 所有复杂的歌词处理逻辑(包括基本歌词、逐字歌词、ASS字幕生成以及繁简转换)都被提取到一个新的辅助类 LyricProcessor 中。这大大提高了代码的可维护性和可重用性,并简化了下载管理器的主逻辑。
  • Electron IPC 文件保存: Electron 主进程中新增了一个 save-file IPC 处理器,允许渲染进程安全地将文件内容保存到本地磁盘,支持指定路径、内容和编码。
  • 旧数据迁移: 为确保向后兼容性,数据存储中增加了迁移逻辑,能够识别并更新旧的下载任务数据,为其分配正确的 type 字段(song 或 custom)。
Changelog
  • .gitignore
    • 新增 task.md 到忽略列表。
  • electron/main/ipc/ipc-file.ts
    • 新增 save-file IPC 处理器,允许渲染进程保存文件内容到指定路径和编码。
  • src/core/resource/DownloadManager.ts
    • 重构下载管理器,采用 DownloadStrategy 接口和 SongDownloadStrategy、CustomDownloadStrategy 实现类。
    • 将歌词处理逻辑完全委托给新的 LyricProcessor 类。
    • 更新 addCustomDownload 方法,使用 CustomDownloadType 并生成字符串类型的唯一ID。
    • 修改 queue 和 activeDownloads 以管理 DownloadStrategy 实例,支持多态处理。
    • 更新 retryDownload 和 retryAllDownloads 方法,以适应新的下载策略和ID类型(number | string)。
    • 移除 SongType 中与自定义下载相关的字段(isCustom, customUrl, customReferer)。
  • src/core/resource/LyricProcessor.ts
    • 新增文件 LyricProcessor.ts,封装所有歌词处理相关功能。
    • 提供 processBasic 处理基础歌词。
    • 提供 parseVerbatim 解析逐字歌词(TTML/YRC),并支持 QQ音乐 QRC 歌词作为回退。
    • 提供 convertToTraditionalIfNeeded 进行繁简转换。
    • 提供 generateVerbatimContent 生成逐字歌词文件内容(TTML/YRC)。
    • 提供 generateAssContent 生成 ASS 字幕文件内容。
  • src/stores/data.ts
    • 更新 downloadingSongs 列表中 song 属性的类型为 SongType | CustomDownloadType。
    • 在 init 方法中添加旧下载任务数据的迁移逻辑,以确保所有任务都有明确的 type 字段。
    • 更新 addDownloadingSong、updateDownloadStatus、updateDownloadProgress、removeDownloadingSong、markDownloadFailed 和 resetDownloadingSong 方法的 songId 参数类型为 number | string,以支持自定义下载的字符串ID。
  • src/types/main.ts
    • 从 SongType 中移除 isCustom、customUrl 和 customReferer 字段。
    • 新增 CustomDownloadType 类型,用于明确定义自定义下载任务的结构。
Activity
  • 作者 kazukokawagawa 创建了此拉取请求。
  • 此拉取请求的标题和内容表明其旨在重构下载管理器,以支持自定义下载类型并优化歌词处理逻辑。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@kazukokawagawa kazukokawagawa self-assigned this Feb 6, 2026
gemini-code-assist[bot]

This comment was marked as outdated.

- 保存文件时自动创建父目录,避免因目录不存在导致的失败
- 歌词处理增加罗马音支持,当启用下载罗马音选项时生成对应歌词轨道
- 修复自定义歌曲类型识别逻辑,迁移旧字段并确保ID一致性
- 统一路径分隔符为斜杠,提高跨平台兼容性
- 改进艺术家信息拼接方式,支持多位艺术家显示
修复下载任务处理中条件判断错误,将 `downloadResult.success` 改为检查 `downloadResult.status === "success"` 以正确处理下载状态。

为歌词处理器添加翻译与罗马音合并功能,当启用相关选项时,会解析并时间轴对齐多语言歌词,最终合并输出为LRC格式。同时增强错误日志,打印任务ID和具体错误信息。
@kazukokawagawa
kazukokawagawa merged commit 0ad9e1d into dev Feb 7, 2026
4 checks passed
@kazukokawagawa
kazukokawagawa deleted the dev-fix branch February 7, 2026 04:19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

2 participants