🦄refactor(mac/tray/lyric): 重构 macOS 状态栏歌词功能,解决多项显示与交互问题,全面提升稳定性与用户体验#890
Conversation
- 统一状态管理,解决功能切换竞态条件 - 明确模块职责,消除歌词与歌曲信息覆盖问题 - 优化歌词显示更新机制,解决启动和拖动时的闪烁卡顿 - 提升代码健壮性,解决类型错误并精简冗余代码
Summary of ChangesHello @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
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
- 移除 electron/main/ipc/ipc-mac-statusbar.ts 中 updateMacStatusBarLyric 和 startInterpolation 函数的 store 参数,改为函数内部通过 useStore() 获取实例。 - 更新 ipc-mac-statusbar.ts 中所有对 updateMacStatusBarLyric 和 startInterpolation 的调用,移除 store 参数。 - 移除 electron/main/tray/index.ts 中 createTrayMenu 函数的 store 参数,改为函数内部通过 useStore() 获取实例。 - 移除 electron/main/tray/index.ts 中 CreateTray 类冗余的 _store 成员变量。 - 更新 CreateTray 类中所有对 createTrayMenu 的调用,移除 store 参数。
There was a problem hiding this comment.
Pull request overview
This PR refactors the macOS status bar lyrics feature to improve stability, eliminate race conditions, and enhance maintainability. The key architectural change is migrating from scattered local state variables to centralized Store-based state management, clarifying module boundaries, and improving the lyric display update mechanism.
Changes:
- Migrated macOS status bar lyrics state from local variables to centralized Store management (
macos.statusBarLyric.enabled) - Removed redundant methods (
setMacStatusBarLyricShow,setMacStatusBarLyricTitle) from tray module and exposedinitTrayMenu()as public - Refactored lyric update mechanism with
forceUpdateparameter and direct state checks inupdateMacStatusBarLyric
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| electron/main/tray/index.ts | Removed macOS-specific state variables and methods; exposed initTrayMenu as public; removed window title setting from setTitle method; updated menu to read state directly from Store |
| electron/main/ipc/ipc-tray.ts | Removed local macOS lyric state tracking and old event handler; exported getCurrentSongTitle function; updated song change handler to check Store for macOS lyric state |
| electron/main/ipc/ipc-mac-statusbar.ts | Refactored updateMacStatusBarLyric to check Store directly; added forceUpdate parameter; improved toggle event handler to call initTrayMenu and properly restore title; streamlined SYNC_STATE and SYNC_TICK event handling |
| const updateMacStatusBarLyric = ( | ||
| forceUpdate: boolean = false, | ||
| ) => { | ||
| const store = useStore(); |
There was a problem hiding this comment.
The updateMacStatusBarLyric function calls useStore() every time it's invoked, including during the 50ms interpolation timer interval. While electron-store handles internal singleton behavior, repeatedly instantiating the Store wrapper could have minor performance implications. Consider caching the store instance at the module level (e.g., const store = useStore() at the top of the file) to avoid repeated instantiation, similar to how macLyricLines and other state variables are maintained at the module level.
本次提交对 macOS 状态栏歌词功能进行了深度优化与结构性重构,旨在全面提升其稳定性、响应速度、用户体验及代码可维护性,修复了系列显示与交互问题:
核心重构与优化:
统一状态管理,消除功能切换的竞态条件:
store.get("macos.statusBarLyric.enabled")直接在关键逻辑点查询最新状态。Store管理,取代了此前分散且易导致不一致的局部变量。明确模块职责边界,消除 UI 渲染冲突:
electron/main/tray/index.ts中冗余的setMacStatusBarLyricShow和setMacStatusBarLyricTitle方法,并通过ipc-tray.ts导出getCurrentSongTitle。ipc-mac-statusbar.ts在歌词功能关闭时直接调用tray?.setTitle(getCurrentSongTitle())。增强歌词显示与更新机制,优化平滑度与精确性:
updateMacStatusBarLyric函数中添加forceUpdate参数和isMacosLyricEnabled检查,并将歌词更新的权威触发点统一到TASKBAR_IPC_CHANNELS.SYNC_TICK事件处理器。updateMacStatusBarLyric的forceUpdate参数,并优化了歌词在启动和进度拖动时的更新策略。改进托盘菜单 UI 同步,提升交互一致性:
macos-lyric:toggle事件处理器中调用(tray as any)?.initTrayMenu()来强制刷新托盘菜单,并修改createTrayMenu直接从Store读取状态。提升代码健壮性与可维护性:
MainTray接口中添加initTrayMenu(): void声明;将CreateTray类中的initTrayMenu方法改为public。electron/main/index.ts中不再使用的ipcMain和useStore导入。electron/main/ipc/ipc-mac-statusbar.ts中的歌词和 IPC payload 类型,使其与@applemusic-like-lyrics/lyric和@shared模块保持一致。本次重构全面提升了 macOS 状态栏歌词功能的内部机制,带来了更稳定、更流畅、更符合预期的用户体验。