🦄refactor(mac/tray/lyric): 重构 macOS 状态栏歌词功能,解决多项显示与交互问题,全面提升稳定性与用户体验 by Pissofdvpe · Pull Request #890 · imsyy/SPlayer

Summary of Changes

Hello @Pissofdvpe, 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!

本次拉取请求对 macOS 状态栏歌词功能进行了全面的重构和深度优化。核心目标是提升其稳定性、响应速度和用户体验,同时解决了一系列显示与交互问题。通过统一状态管理、明确模块职责、优化歌词更新机制以及改进托盘菜单同步,显著提升了功能的可靠性和流畅性,并增强了代码的可维护性。

Highlights

  • 统一状态管理: 通过将 macOS 状态栏歌词的启用状态集中至全局 Store 管理,取代了此前分散的局部变量,从根本上解决了功能开启/关闭逻辑中因状态不同步导致的竞态条件和行为异常。
  • 明确模块职责边界: 移除了 electron/main/tray/index.ts 中冗余的歌词设置方法,并使 ipc-mac-statusbar.ts 在歌词功能关闭时直接调用 tray?.setTitle(getCurrentSongTitle()),解决了歌词与歌曲信息相互覆盖的 UI 渲染冲突。
  • 增强歌词显示与更新机制: 在 updateMacStatusBarLyric 函数中引入 forceUpdate 参数和 isMacosLyricEnabled 检查,并将歌词更新的权威触发点统一到 TASKBAR_IPC_CHANNELS.SYNC_TICK 事件处理器,确保歌词显示更平滑、精确,解决了启动时延迟显示或拖动进度时跳动的问题。
  • 改进托盘菜单 UI 同步: 通过在 macos-lyric:toggle 事件处理器中调用 (tray as any)?.initTrayMenu() 来强制刷新托盘菜单,并修改 createTrayMenu 直接从 Store 读取状态,实现了菜单项与实际歌词功能启用状态的实时同步。
  • 提升代码健壮性与可维护性: 优化了类型接口与实现,移除了冗余代码及不再需要的导入,使整体代码结构更加清晰,降低了长期维护成本,为未来的功能扩展奠定了坚实基础。
Changelog
  • electron/main/ipc/ipc-mac-statusbar.ts
    • 导入了 getCurrentSongTitle 函数,用于在歌词功能禁用时恢复托盘标题。
    • 修改了 updateMacStatusBarLyric 函数,增加了 forceUpdate 参数,并加入了 isMacosLyricEnabled 检查,确保在歌词功能禁用时显示歌曲标题。
    • 更新了 initMacStatusBarIpc 中的 macos-lyric:toggle 事件处理器,以强制刷新托盘菜单并根据歌词启用状态设置托盘标题。
    • 调整了 SYNC_STATESYNC_TICK 事件处理逻辑,将歌词更新的权威触发点统一到 SYNC_TICK,并移除了冗余的歌词更新调用。
  • electron/main/ipc/ipc-tray.ts
    • 移除了 macStatusBarLyricEnabled 局部状态变量,转而从全局 Store 获取状态。
    • 导出了 getCurrentSongTitle 函数,以便其他模块获取当前歌曲标题。
    • 修改了 play-song-change 事件处理逻辑,使其根据 Store 中 macOS 歌词的启用状态来决定是否更新托盘标题。
    • 移除了 mac-toggle-statusbar-lyric IPC 监听器,相关逻辑已转移到 ipc-mac-statusbar.ts
  • electron/main/tray/index.ts
    • 移除了 macStatusBarLyricShowmacStatusBarLyricTitle 状态变量,简化了托盘模块的内部状态管理。
    • 更新了 MainTray 接口,移除了 setMacStatusBarLyricShowsetMacStatusBarLyricTitle 方法,并添加了 initTrayMenu() 方法。
    • 修改了 createTrayMenu 函数,使其接受 store 参数,并直接从 Store 读取 macOS 歌词的启用状态来构建菜单项。
    • CreateTray 类中的 initTrayMenu 方法改为 public,并修改了构造函数和 initTrayMenu 方法,使其在创建和更新菜单时都传入 store 实例。
    • setTitle 方法中移除了 this._win.setTitle(title),使托盘标题的设置与主窗口标题解耦。
Activity
  • 没有检测到人工活动。
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.

  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.