feat: 添加缓存 & 歌曲偏移#18
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
该 PR 在 SPlayer-Next(Electron 主进程 + Vue 渲染进程 + 多歌词窗口)中引入「歌曲文件缓存/缓存管理」能力,并新增「按曲目记忆的歌词偏移」链路(主进程权威、渲染端/窗口端镜像同步),同时扩展了设置页的本地与缓存管理入口及设置备份/恢复能力。
Changes:
- 新增歌曲文件级缓存(下载、LRU 淘汰、缓存目录切换、缓存统计与清理)及对应 IPC/DB 支撑。
- 新增按 Track.id 记忆的歌词偏移:主进程持久化 + 广播,渲染端与歌词窗口实时叠加偏移更新。
- 设置页新增「本地与缓存」分类与缓存管理 UI,并重做「数据管理」为备份/恢复/重置工作流。
Reviewed changes
Copilot reviewed 45 out of 47 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| windows/shared/composables/useNowPlayingSync.ts | 窗口端同步叠加歌词偏移 |
| src/utils/time.ts | 新增带符号秒数格式化 |
| src/types/settings-schema.ts | 设置项类型扩展 number |
| src/stores/streaming.ts | getStreamUrl 支持自定义 sessionId;init 自动连接 |
| src/stores/status.ts | 状态层新增 lyricOffsetMs 镜像字段 |
| src/settings/schema.ts | 设置 schema 注入 localCache 分类 |
| src/settings/categories/localCache.ts | 新增「本地与缓存」设置分类 |
| src/settings/categories/general.ts | 重命名 reset 区块并增强关键词/布局 |
| src/services/streaming/session.ts | 精简为 PlaySessionId 生成器 |
| src/services/audioSource.ts | 解析音源时接入歌曲缓存命中/后台下载 |
| src/i18n/locales/zh-CN.json | 新增缓存/备份恢复/歌词偏移文案 |
| src/i18n/locales/en-US.json | 新增缓存/备份恢复/歌词偏移文案(英文) |
| src/core/player/index.ts | loadTrack 适配新 resolveTrackSource;订阅偏移变更 |
| src/core/player/events.ts | 歌词索引更新叠加 lyricOffsetMs |
| src/composables/useCacheStats.ts | 新增缓存统计 composable |
| src/components/ui/SNumberInput.vue | 新增数值输入控件(reka-ui NumberField) |
| src/components/settings/SettingsItem.vue | 设置项渲染支持 number 类型 |
| src/components/settings/custom/StorageManager.vue | 数据管理改为备份/恢复/重置流程 |
| src/components/settings/custom/FileCacheManager.vue | 文件类缓存目录/占用/清理 UI |
| src/components/settings/custom/DbCacheManager.vue | DB 类缓存占用/清理 UI |
| src/components/player/FullPlayer/index.vue | 全屏播放器加入歌词偏移快捷调节 |
| src/components/list/SongList.vue | header 布局调整(滚动条边缘补偿) |
| shared/types/settings.ts | SystemConfig 增加 localLyric/cache;ConfigApi 增加导入导出/replaceAll |
| shared/types/nowPlaying.ts | NowPlaying snapshot/事件增加 lyricOffsetMs 与订阅/设置 API |
| shared/defaults/settings.ts | 补齐新增配置默认值 |
| electron/preload/index.ts | 暴露 cache/config/nowPlaying/system 新 IPC API |
| electron/preload/index.d.ts | preload 类型声明更新 |
| electron/main/utils/protocol.ts | cache:// 协议改为使用动态缓存根目录 |
| electron/main/utils/logger.ts | 新增 songCache logger scope |
| electron/main/utils/config.ts | 缓存根目录改为可配置;导出各子目录 getter |
| electron/main/store/index.ts | store 增加 replaceAll |
| electron/main/services/songCache.ts | 新增歌曲缓存服务(下载/LRU/清理/统计) |
| electron/main/services/scanner.ts | 扫描服务使用动态封面缓存目录 |
| electron/main/services/nowPlaying.ts | 主进程维护并广播歌词偏移;持久化到 store |
| electron/main/services/engine.ts | 支持封面缓存目录动态同步到原生引擎 |
| electron/main/ipc/theme.ts | 背景图缓存目录改为动态 getter |
| electron/main/ipc/system.ts | 新增 relaunch IPC |
| electron/main/ipc/player.ts | 解码失败时作废损坏的歌曲缓存项 |
| electron/main/ipc/nowPlaying.ts | 新增 setLyricOffset IPC + 广播偏移变化 |
| electron/main/ipc/index.ts | 注册 cache IPC |
| electron/main/ipc/config.ts | 新增配置整盘替换/导入导出 IPC |
| electron/main/ipc/cache.ts | 新增缓存统计/清理/目录切换/歌曲缓存 IPC |
| electron/main/database/songCache.ts | 新增 song_cache 表 DAO |
| electron/main/database/index.ts | 初始化 song_cache 表与索引 |
| electron/main/core/index.ts | 启动时 initSongCache |
| electron/main/apis/musicbrainz.ts | 歌手头像缓存目录改为动态 getter |
| components.d.ts | 全局组件类型声明更新 |
Comment on lines
26
to
31
| /** cache:// 协议的处理函数 */ | ||
| const cacheHandler = (request: Request): Response | Promise<Response> => { | ||
| const relativePath = decodeURIComponent(request.url.slice(`${SCHEME}://`.length)); | ||
| const filePath = path.join(appCacheDir, relativePath); | ||
| const filePath = path.join(getAppCacheDir(), relativePath); | ||
| return net.fetch(`file://${filePath.replace(/\\/g, "/")}`); | ||
| }; |
Comment on lines
+70
to
+73
| const acquireSlot = async (): Promise<void> => { | ||
| if (inFlight.size < MAX_CONCURRENT) return; | ||
| await new Promise<void>((resolve) => waiting.push(resolve)); | ||
| }; |
Comment on lines
+92
to
+99
| export const setLyricOffset = (trackId: string, offsetMs: number): void => { | ||
| if (!trackId) return; | ||
| const truncated = Math.trunc(offsetMs); | ||
| const value = Math.max(-LYRIC_OFFSET_LIMIT_MS, Math.min(LYRIC_OFFSET_LIMIT_MS, truncated)); | ||
| const map = { ...(store.get("player.lyricOffsets") ?? {}) }; | ||
| if (value === 0) delete map[trackId]; | ||
| else map[trackId] = value; | ||
| store.set("player.lyricOffsets", map); |
Comment on lines
+45
to
+64
| /** | ||
| * 递归累计目录占用 | ||
| * @param dir - 目录路径 | ||
| * @returns 占用字节数 | ||
| */ | ||
| const dirSize = (dir: string): number => { | ||
| if (!existsSync(dir)) return 0; | ||
| let total = 0; | ||
| for (const entry of readdirSync(dir, { withFileTypes: true })) { | ||
| const full = path.join(dir, entry.name); | ||
| try { | ||
| if (entry.isDirectory()) { | ||
| total += dirSize(full); | ||
| } else if (entry.isFile()) { | ||
| total += statSync(full).size; | ||
| } | ||
| } catch {} | ||
| } | ||
| return total; | ||
| }; |
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.
No description provided.