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

优化下载与修复音质切换BUG - #660

Merged
imsyy merged 12 commits into
devfrom
dev-perf
Dec 26, 2025
Merged

imsyy merged 12 commits into
devfrom
dev-perf

Conversation

@kazukokawagawa

Copy link
Copy Markdown
Collaborator

No description provided.

@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!

This pull request significantly upgrades the application's download system, focusing on reliability, performance, and user control. Key improvements include enabling concurrent downloads, ensuring download tasks persist across application restarts, and providing a mechanism to cancel ongoing downloads. These changes aim to deliver a more stable and user-friendly download experience.

Highlights

  • Enhanced Download Management: Implemented concurrent download capabilities, allowing multiple files to download simultaneously, and introduced robust error handling for cancellations and temporary file management.
  • Download State Persistence: Added functionality to initialize and restore pending download tasks upon application startup, improving user experience by resuming interrupted downloads.
  • Download Cancellation Support: Introduced an IPC mechanism to cancel active downloads from the main process, providing users with more control over their download queue.
  • Improved Lyric Processing: Refactored and centralized the logic for processing and combining different lyric types (original, translated, romaji) for downloaded songs.
  • Minor UI/UX Adjustments: Included small improvements such as custom text selection styling in comments and conditional disabling of quality selection in the player.
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. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a significant and well-executed refactoring of the download management system. Key improvements include support for concurrent downloads, download cancellation, and robust state restoration on application startup. The code has been made more modular and readable, particularly by extracting the complex lyric processing logic into a separate method. My review focuses on further improving type safety and streamlining some of the new logic for better maintainability.

Comment thread electron/main/ipc/ipc-file.ts Outdated
const item = downloadItems.get(songId);
if (item) {
item.cancel();
downloadItems.delete(songId);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The downloadItems.delete(songId) call here is redundant. The finally block in the download-file handler already ensures that the item is deleted from downloadItems after the download completes, fails, or is cancelled. Removing this line will centralize the cleanup logic and prevent potential confusion. The item.cancel() call will cause the download() promise to reject, which will trigger the finally block in download-file.

Comment on lines +41 to +59
// 1. 重置下载中状态为等待中 (应用重启后的恢复)
dataStore.downloadingSongs.forEach((item) => {
if (item.status === "downloading") {
dataStore.updateDownloadStatus(item.song.id, "waiting");
dataStore.updateDownloadProgress(item.song.id, 0, "0MB", "0MB");
}
});

// 2. 将等待中的任务加入队列
dataStore.downloadingSongs.forEach((item) => {
if (item.status === "waiting") {
const isQueued = this.queue.some((t) => t.song.id === item.song.id);
const isActive = this.activeDownloads.has(item.song.id);

if (!isQueued && !isActive) {
this.queue.push({ song: item.song, quality: item.quality });
}
}
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The init method currently iterates over dataStore.downloadingSongs twice. This can be optimized by combining the two loops into one. This improves both performance and readability by processing each item in a single pass.

    // 1. 重置下载中状态为等待中 (应用重启后的恢复) 并加入队列
    dataStore.downloadingSongs.forEach((item) => {
      let isWaiting = item.status === "waiting";
      if (item.status === "downloading") {
        dataStore.updateDownloadStatus(item.song.id, "waiting");
        dataStore.updateDownloadProgress(item.song.id, 0, "0MB", "0MB");
        isWaiting = true;
      }

      if (isWaiting) {
        const isQueued = this.queue.some((t) => t.song.id === item.song.id);
        const isActive = this.activeDownloads.has(item.song.id);

        if (!isQueued && !isActive) {
          this.queue.push({ song: item.song, quality: item.quality });
        }
      }
    });

Comment on lines 210 to 211
} catch (error) {
console.error("Download failed:", error);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

For better type safety, it's recommended to type error as unknown in catch blocks. This ensures that you perform necessary type checks before accessing properties on the error object.

    } catch (error: unknown) {
      console.error("Download failed:", error);

@imsyy imsyy changed the title Dev perf 优化下载与修复音质切换BUG Dec 26, 2025
@imsyy

imsyy commented Dec 26, 2025

Copy link
Copy Markdown
Member

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

本次 PR 带来了多项重要优化和修复,显著提升了应用的稳定性和用户体验。对 DownloadManager 的重构非常出色,引入了并发下载、任务取消和启动时恢复下载等功能,使下载模块更加健壮。同时,修复了音质切换的 BUG,特别是针对云盘歌曲的处理。此外,还增加了一些新的 UI 功能和设置,如播放器展开动画和开发者展示,并对播放失败处理等细节进行了优化。代码整体质量很高,结构清晰。我提出了一些关于代码可维护性的建议,希望能有所帮助。

Comment on lines +182 to +183
.filter((item: any) => item.login !== "type-bot" && item.type !== "Bot")
.map((item: any) => ({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

为了提高代码的可读性和可维护性,建议为从 GitHub API 获取的贡献者数据定义一个明确的类型(例如 GithubContributor),而不是使用 any。这有助于类型检查并使数据结构更清晰。

this.failSkipCount++;

// 连续跳过 3 首直接暂停
if (this.failSkipCount >= 3) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

这里的数字 3 是一个“魔术数字”。建议将其定义为一个具有描述性名称的常量(例如 MAX_CONSECUTIVE_FAIL_SKIPS),以提高代码的可读性,并使其在将来更易于修改。

@imsyy
imsyy merged commit a421ea5 into dev Dec 26, 2025
3 checks passed
@kazukokawagawa
kazukokawagawa deleted the dev-perf branch December 29, 2025 05:37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants