mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-05-17 02:07:29 +08:00
Compare commits
6 Commits
main
..
7759d9b23a
| Author | SHA1 | Date | |
|---|---|---|---|
| 7759d9b23a | |||
| c889ac301b | |||
| 1e30a11881 | |||
| 34713430e1 | |||
| eaf1636505 | |||
| e032afeae8 |
@@ -1,71 +0,0 @@
|
|||||||
name: PR Check
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
branches: [main]
|
|
||||||
types: [opened, edited, synchronize, reopened]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
# 检查 PR 标题是否符合 Conventional Commits 规范
|
|
||||||
pr-title:
|
|
||||||
name: PR Title
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Setup Node.js
|
|
||||||
uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: 24
|
|
||||||
|
|
||||||
- name: Install commitlint
|
|
||||||
run: npm install --no-save @commitlint/cli @commitlint/config-conventional
|
|
||||||
|
|
||||||
- name: Validate PR title
|
|
||||||
env:
|
|
||||||
PR_TITLE: ${{ github.event.pull_request.title }}
|
|
||||||
run: echo "$PR_TITLE" | npx commitlint
|
|
||||||
|
|
||||||
# 检查所有提交信息是否符合 Conventional Commits 规范
|
|
||||||
commit-messages:
|
|
||||||
name: Commit Messages
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Setup Node.js
|
|
||||||
uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: 24
|
|
||||||
|
|
||||||
- name: Install commitlint
|
|
||||||
run: npm install --no-save @commitlint/cli @commitlint/config-conventional
|
|
||||||
|
|
||||||
- name: Validate commit messages
|
|
||||||
run: npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose
|
|
||||||
|
|
||||||
# 运行 lint 和类型检查
|
|
||||||
code-quality:
|
|
||||||
name: Code Quality
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Setup Node.js
|
|
||||||
uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: 24
|
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: npm install
|
|
||||||
|
|
||||||
- name: Lint
|
|
||||||
run: npx eslint --max-warnings 0 "src/**/*.{ts,tsx,vue,js}"
|
|
||||||
|
|
||||||
- name: Type check
|
|
||||||
run: npm run typecheck
|
|
||||||
|
|
||||||
- name: I18n check
|
|
||||||
run: npm run lint:i18n
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
npx --no -- commitlint --edit "$1"
|
|
||||||
@@ -0,0 +1,423 @@
|
|||||||
|
# CLAUDE.md
|
||||||
|
|
||||||
|
本文件为 Claude Code (claude.ai/code) 提供项目指南。
|
||||||
|
|
||||||
|
## 项目概述
|
||||||
|
|
||||||
|
Alger Music Player 是基于 **Electron + Vue 3 + TypeScript** 构建的第三方网易云音乐播放器,支持桌面端(Windows/macOS/Linux)、Web 和移动端,具备本地 API 服务、桌面歌词、无损音乐下载、音源解锁、EQ 均衡器等功能。
|
||||||
|
|
||||||
|
## 技术栈
|
||||||
|
|
||||||
|
- **桌面端**: Electron 40 + electron-vite 5
|
||||||
|
- **前端框架**: Vue 3.5 (Composition API + `<script setup>`)
|
||||||
|
- **状态管理**: Pinia 3 + pinia-plugin-persistedstate
|
||||||
|
- **UI 框架**: naive-ui(自动导入)
|
||||||
|
- **样式**: Tailwind CSS 3(仅在模板中使用 class,禁止在 `<style>` 中使用 `@apply`)
|
||||||
|
- **图标**: remixicon
|
||||||
|
- **音频**: 原生 HTMLAudioElement + Web Audio API(EQ 均衡器)
|
||||||
|
- **工具库**: VueUse, lodash
|
||||||
|
- **国际化**: vue-i18n(5 种语言:zh-CN、en-US、ja-JP、ko-KR、zh-Hant)
|
||||||
|
- **音乐 API**: netease-cloud-music-api-alger + @unblockneteasemusic/server
|
||||||
|
- **自动更新**: electron-updater(GitHub Releases)
|
||||||
|
- **构建**: Vite 6, electron-builder
|
||||||
|
|
||||||
|
## 开发命令
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 安装依赖(推荐 Node 18+)
|
||||||
|
npm install
|
||||||
|
|
||||||
|
# 桌面端开发(推荐)
|
||||||
|
npm run dev
|
||||||
|
|
||||||
|
# Web 端开发(需自建 netease-cloud-music-api 服务)
|
||||||
|
npm run dev:web
|
||||||
|
|
||||||
|
# 类型检查
|
||||||
|
npm run typecheck # 全部检查
|
||||||
|
npm run typecheck:node # 主进程
|
||||||
|
npm run typecheck:web # 渲染进程
|
||||||
|
|
||||||
|
# 代码规范
|
||||||
|
npm run lint # ESLint + i18n 检查
|
||||||
|
npm run format # Prettier 格式化
|
||||||
|
|
||||||
|
# 构建
|
||||||
|
npm run build # 构建渲染进程和主进程
|
||||||
|
npm run build:win # Windows 安装包
|
||||||
|
npm run build:mac # macOS DMG
|
||||||
|
npm run build:linux # AppImage, deb, rpm
|
||||||
|
npm run build:unpack # 仅构建不打包
|
||||||
|
```
|
||||||
|
|
||||||
|
## 项目架构
|
||||||
|
|
||||||
|
### 目录结构
|
||||||
|
|
||||||
|
```
|
||||||
|
src/
|
||||||
|
├── main/ # Electron 主进程
|
||||||
|
│ ├── index.ts # 入口,窗口生命周期
|
||||||
|
│ ├── modules/ # 功能模块(15 个文件)
|
||||||
|
│ │ ├── window.ts # 窗口管理(主窗口、迷你模式、歌词窗口)
|
||||||
|
│ │ ├── tray.ts # 系统托盘
|
||||||
|
│ │ ├── shortcuts.ts # 全局快捷键
|
||||||
|
│ │ ├── fileManager.ts # 下载管理
|
||||||
|
│ │ ├── remoteControl.ts # 远程控制 HTTP API
|
||||||
|
│ │ └── update.ts # 自动更新(electron-updater)
|
||||||
|
│ ├── lyric.ts # 歌词窗口
|
||||||
|
│ ├── server.ts # 本地 API 服务
|
||||||
|
│ └── unblockMusic.ts # 音源解锁服务
|
||||||
|
│
|
||||||
|
├── preload/index.ts # IPC 桥接(暴露 window.api)
|
||||||
|
│
|
||||||
|
├── shared/ # 主进程/渲染进程共享代码
|
||||||
|
│ └── appUpdate.ts # 更新状态类型定义
|
||||||
|
│
|
||||||
|
├── i18n/ # 国际化
|
||||||
|
│ ├── lang/ # 语言文件(5 语言 × 15 分类 = 75 个文件)
|
||||||
|
│ ├── main.ts # 主进程 i18n
|
||||||
|
│ ├── renderer.ts # 渲染进程 i18n
|
||||||
|
│ └── utils.ts # i18n 工具
|
||||||
|
│
|
||||||
|
└── renderer/ # Vue 应用
|
||||||
|
├── store/modules/ # Pinia 状态(15 个模块)
|
||||||
|
│ ├── playerCore.ts # 🔑 播放核心状态(纯状态:播放/暂停、音量、倍速)
|
||||||
|
│ ├── playlist.ts # 🔑 播放列表管理(上/下一首、播放模式)
|
||||||
|
│ ├── settings.ts # 应用设置
|
||||||
|
│ ├── user.ts # 用户认证与同步
|
||||||
|
│ ├── lyric.ts # 歌词状态
|
||||||
|
│ ├── music.ts # 音乐元数据
|
||||||
|
│ └── favorite.ts # 收藏管理
|
||||||
|
│
|
||||||
|
├── services/ # 服务层
|
||||||
|
│ ├── audioService.ts # 🔑 原生 HTMLAudioElement + Web Audio API(EQ、MediaSession)
|
||||||
|
│ ├── playbackController.ts # 🔑 播放控制流(playTrack 入口、generation 取消、初始化恢复)
|
||||||
|
│ ├── playbackRequestManager.ts # 请求 ID 追踪(供 usePlayerHooks 内部取消检查)
|
||||||
|
│ ├── preloadService.ts # 下一首 URL 预验证
|
||||||
|
│ ├── SongSourceConfigManager.ts # 单曲音源配置
|
||||||
|
│ └── translation-engines/ # 翻译引擎策略
|
||||||
|
│
|
||||||
|
├── hooks/ # 组合式函数(9 个文件)
|
||||||
|
│ ├── MusicHook.ts # 🔑 音乐主逻辑(歌词、进度、快捷键)
|
||||||
|
│ ├── usePlayerHooks.ts # 播放器 hooks
|
||||||
|
│ ├── useDownload.ts # 下载功能
|
||||||
|
│ └── IndexDBHook.ts # IndexedDB 封装
|
||||||
|
│
|
||||||
|
├── api/ # API 层(16 个文件)
|
||||||
|
│ ├── musicParser.ts # 🔑 多音源 URL 解析(策略模式)
|
||||||
|
│ ├── music.ts # 网易云音乐 API
|
||||||
|
│ ├── bilibili.ts # B站音源
|
||||||
|
│ ├── gdmusic.ts # GD Music 平台
|
||||||
|
│ ├── lxMusicStrategy.ts # LX Music 音源策略
|
||||||
|
│ ├── donation.ts # 捐赠 API
|
||||||
|
│ └── parseFromCustomApi.ts # 自定义 API 解析
|
||||||
|
│
|
||||||
|
├── components/ # 组件(59+ 个文件)
|
||||||
|
│ ├── common/ # 通用组件(24 个)
|
||||||
|
│ ├── player/ # 播放器组件(10 个)
|
||||||
|
│ ├── settings/ # 设置弹窗组件(7 个)
|
||||||
|
│ └── ...
|
||||||
|
│
|
||||||
|
├── views/ # 页面(53 个文件)
|
||||||
|
│ ├── set/ # 设置页(已拆分为 Tab 组件)
|
||||||
|
│ │ ├── index.vue # 设置页壳组件(导航 + provide/inject)
|
||||||
|
│ │ ├── keys.ts # InjectionKey 定义
|
||||||
|
│ │ ├── SBtn.vue # 自定义按钮组件
|
||||||
|
│ │ ├── SInput.vue # 自定义输入组件
|
||||||
|
│ │ ├── SSelect.vue # 自定义选择器组件
|
||||||
|
│ │ ├── SettingItem.vue
|
||||||
|
│ │ ├── SettingSection.vue
|
||||||
|
│ │ └── tabs/ # 7 个 Tab 组件
|
||||||
|
│ │ ├── BasicTab.vue
|
||||||
|
│ │ ├── PlaybackTab.vue
|
||||||
|
│ │ ├── ApplicationTab.vue
|
||||||
|
│ │ ├── NetworkTab.vue
|
||||||
|
│ │ ├── SystemTab.vue
|
||||||
|
│ │ ├── AboutTab.vue
|
||||||
|
│ │ └── DonationTab.vue
|
||||||
|
│ └── ...
|
||||||
|
│
|
||||||
|
├── router/ # Vue Router(3 个文件)
|
||||||
|
├── types/ # TypeScript 类型(20 个文件)
|
||||||
|
├── utils/ # 工具函数(17 个文件)
|
||||||
|
├── directive/ # 自定义指令
|
||||||
|
├── const/ # 常量定义
|
||||||
|
└── assets/ # 静态资源
|
||||||
|
```
|
||||||
|
|
||||||
|
### 核心模块职责
|
||||||
|
|
||||||
|
| 模块 | 文件 | 职责 |
|
||||||
|
|------|------|------|
|
||||||
|
| 播放控制 | `services/playbackController.ts` | 🔑 播放入口(playTrack)、generation 取消、初始化恢复、URL 过期处理 |
|
||||||
|
| 音频服务 | `services/audioService.ts` | 原生 HTMLAudioElement + Web Audio API、EQ 滤波、MediaSession |
|
||||||
|
| 播放状态 | `store/playerCore.ts` | 纯状态:播放/暂停、音量、倍速、当前歌曲、音频设备 |
|
||||||
|
| 播放列表 | `store/playlist.ts` | 列表管理、播放模式、上/下一首 |
|
||||||
|
| 音源解析 | `api/musicParser.ts` | 多音源 URL 解析与缓存 |
|
||||||
|
| 音乐钩子 | `hooks/MusicHook.ts` | 歌词解析、进度跟踪、键盘快捷键 |
|
||||||
|
|
||||||
|
### 播放系统架构
|
||||||
|
|
||||||
|
```
|
||||||
|
用户操作 / 自动播放
|
||||||
|
↓
|
||||||
|
playbackController.playTrack(song) ← 唯一入口,generation++ 取消旧操作
|
||||||
|
├─ 加载歌词 + 背景色
|
||||||
|
├─ 获取播放 URL(getSongDetail)
|
||||||
|
└─ audioService.play(url, track)
|
||||||
|
├─ audio.src = url ← 单一 HTMLAudioElement,换歌改 src
|
||||||
|
├─ Web Audio API EQ 链 ← createMediaElementSource 只调一次
|
||||||
|
└─ 原生 DOM 事件 → emit
|
||||||
|
↓
|
||||||
|
MusicHook 监听(进度、歌词同步、播放状态)
|
||||||
|
```
|
||||||
|
|
||||||
|
**关键设计**:
|
||||||
|
- **Generation-based 取消**:每次 `playTrack()` 递增 generation,await 后检查是否过期,过期则静默退出
|
||||||
|
- **单一 HTMLAudioElement**:启动时创建,永不销毁。换歌改 `audio.src`,EQ 链不重建
|
||||||
|
- **Seek**:直接 `audio.currentTime = time`,无 Howler.js 的 pause→play 问题
|
||||||
|
|
||||||
|
### 音源解析策略
|
||||||
|
|
||||||
|
`musicParser.ts` 使用 **策略模式** 从多个来源解析音乐 URL:
|
||||||
|
|
||||||
|
**优先级顺序**(可通过 `SongSourceConfigManager` 按曲配置):
|
||||||
|
1. `custom` - 自定义 API
|
||||||
|
2. `bilibili` - B站音频
|
||||||
|
3. `gdmusic` - GD Music 平台
|
||||||
|
4. `lxmusic` - LX Music HTTP 源
|
||||||
|
5. `unblock` - UnblockNeteaseMusic 服务
|
||||||
|
|
||||||
|
**缓存策略**:
|
||||||
|
- 成功的 URL 在 IndexedDB 缓存 30 分钟(`music_url_cache`)
|
||||||
|
- 失败的尝试在内存中缓存 1 分钟(应用重启自动清除)
|
||||||
|
- 音源配置变更时缓存失效
|
||||||
|
|
||||||
|
### 设置页架构
|
||||||
|
|
||||||
|
设置页(`views/set/`)采用 **provide/inject** 模式拆分为 7 个 Tab 组件:
|
||||||
|
|
||||||
|
- `index.vue` 作为壳组件:管理 Tab 导航、`setData` 双向绑定与防抖保存
|
||||||
|
- `keys.ts` 定义类型化的 InjectionKey:`SETTINGS_DATA_KEY`、`SETTINGS_MESSAGE_KEY`、`SETTINGS_DIALOG_KEY`
|
||||||
|
- 自定义 UI 组件(`SBtn`、`SInput`、`SSelect`)替代部分 naive-ui 组件
|
||||||
|
- 字体选择器保留 naive-ui `n-select`(需要 filterable + multiple + render-label)
|
||||||
|
|
||||||
|
## 代码规范
|
||||||
|
|
||||||
|
### 命名
|
||||||
|
|
||||||
|
- **目录**: kebab-case(`components/music-player`)
|
||||||
|
- **组件**: PascalCase(`MusicPlayer.vue`)
|
||||||
|
- **组合式函数**: camelCase + `use` 前缀(`usePlayer.ts`)
|
||||||
|
- **Store**: camelCase(`playerCore.ts`)
|
||||||
|
- **常量**: UPPER_SNAKE_CASE(`MAX_RETRY_COUNT`)
|
||||||
|
|
||||||
|
### TypeScript
|
||||||
|
|
||||||
|
- **优先使用 `type` 而非 `interface`**
|
||||||
|
- **禁止使用 `enum`,使用 `const` 对象 + `as const`**
|
||||||
|
- 所有导出函数必须有类型标注
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// ✅ 正确
|
||||||
|
type SongResult = { id: number; name: string };
|
||||||
|
const PlayMode = { ORDER: 'order', LOOP: 'loop' } as const;
|
||||||
|
|
||||||
|
// ❌ 避免
|
||||||
|
interface ISongResult { ... }
|
||||||
|
enum PlayMode { ... }
|
||||||
|
```
|
||||||
|
|
||||||
|
### Vue 组件结构
|
||||||
|
|
||||||
|
```vue
|
||||||
|
<script setup lang="ts">
|
||||||
|
// 1. 导入(按类型分组)
|
||||||
|
import { ref, computed, onMounted } from 'vue';
|
||||||
|
import { usePlayerStore } from '@/store';
|
||||||
|
import type { SongResult } from '@/types/music';
|
||||||
|
|
||||||
|
// 2. Props & Emits
|
||||||
|
const props = defineProps<{ id: number }>();
|
||||||
|
const emit = defineEmits<{ play: [id: number] }>();
|
||||||
|
|
||||||
|
// 3. Store
|
||||||
|
const playerStore = usePlayerStore();
|
||||||
|
|
||||||
|
// 4. 响应式状态(使用描述性命名:isLoading, hasError)
|
||||||
|
const isLoading = ref(false);
|
||||||
|
|
||||||
|
// 5. 计算属性
|
||||||
|
const displayName = computed(() => /* ... */);
|
||||||
|
|
||||||
|
// 6. 方法(动词开头命名)
|
||||||
|
const handlePlay = () => { /* ... */ };
|
||||||
|
|
||||||
|
// 7. 生命周期钩子
|
||||||
|
onMounted(() => { /* ... */ });
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<!-- naive-ui 组件 + Tailwind CSS -->
|
||||||
|
</template>
|
||||||
|
```
|
||||||
|
|
||||||
|
### 样式规范
|
||||||
|
|
||||||
|
- **禁止在 `<style>` 中使用 `@apply`**,所有 Tailwind 类直接写在模板中
|
||||||
|
- 如发现代码中有 `@apply` 用法,应优化为内联 Tailwind class
|
||||||
|
- `<style scoped>` 仅用于无法用 Tailwind 实现的 CSS(如 keyframes 动画、`:deep()` 穿透)
|
||||||
|
|
||||||
|
### 导入约定
|
||||||
|
|
||||||
|
- **naive-ui 组件**:自动导入,无需手动 import
|
||||||
|
- **Vue 组合式 API**:`useDialog`、`useMessage`、`useNotification`、`useLoadingBar` 自动导入
|
||||||
|
- **路径别名**:`@` → `src/renderer`,`@i18n` → `src/i18n`
|
||||||
|
|
||||||
|
## 关键实现模式
|
||||||
|
|
||||||
|
### 状态持久化
|
||||||
|
|
||||||
|
Store 使用 `pinia-plugin-persistedstate` 自动持久化:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
export const useXxxStore = defineStore('xxx', () => {
|
||||||
|
// store 逻辑
|
||||||
|
}, {
|
||||||
|
persist: {
|
||||||
|
key: 'xxx-store',
|
||||||
|
storage: localStorage,
|
||||||
|
pick: ['fieldsToPersist'] // 仅持久化指定字段
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### IPC 通信
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// 主进程 (src/main/modules/*)
|
||||||
|
ipcMain.handle('channel-name', async (_, args) => {
|
||||||
|
return result;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Preload (src/preload/index.ts)
|
||||||
|
const api = {
|
||||||
|
methodName: (args) => ipcRenderer.invoke('channel-name', args)
|
||||||
|
};
|
||||||
|
contextBridge.exposeInMainWorld('api', api);
|
||||||
|
|
||||||
|
// 渲染进程 (src/renderer/*)
|
||||||
|
const result = await window.api.methodName(args);
|
||||||
|
```
|
||||||
|
|
||||||
|
### IndexedDB 使用
|
||||||
|
|
||||||
|
使用 `IndexDBHook` 组合式函数:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const db = await useIndexedDB('dbName', [
|
||||||
|
{ name: 'storeName', keyPath: 'id' }
|
||||||
|
], version);
|
||||||
|
|
||||||
|
const { saveData, getData, deleteData } = db;
|
||||||
|
await saveData('storeName', { id: 1, data: 'value' });
|
||||||
|
const data = await getData('storeName', 1);
|
||||||
|
```
|
||||||
|
|
||||||
|
### 新增页面
|
||||||
|
|
||||||
|
1. 创建 `src/renderer/views/xxx/index.vue`
|
||||||
|
2. 在 `src/renderer/router/other.ts` 中添加路由
|
||||||
|
3. 在 `src/i18n/lang/*/` 下所有 5 种语言中添加 i18n 键值
|
||||||
|
|
||||||
|
### 新增 Store
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// src/renderer/store/modules/xxx.ts
|
||||||
|
import { defineStore } from 'pinia';
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
|
export const useXxxStore = defineStore('xxx', () => {
|
||||||
|
const state = ref(initialValue);
|
||||||
|
const action = () => { /* ... */ };
|
||||||
|
return { state, action };
|
||||||
|
});
|
||||||
|
|
||||||
|
// 在 src/renderer/store/index.ts 中导出
|
||||||
|
export * from './modules/xxx';
|
||||||
|
```
|
||||||
|
|
||||||
|
### 新增音源策略
|
||||||
|
|
||||||
|
编辑 `src/renderer/api/musicParser.ts`:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
class NewStrategy implements MusicSourceStrategy {
|
||||||
|
name = 'new';
|
||||||
|
priority = 5;
|
||||||
|
canHandle(sources: string[]) { return sources.includes('new'); }
|
||||||
|
async parse(id: number, data: any): Promise<ParsedMusicResult> {
|
||||||
|
// 实现解析逻辑
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 在 ParserManager 构造函数中注册
|
||||||
|
this.strategies.push(new NewStrategy());
|
||||||
|
```
|
||||||
|
|
||||||
|
## 平台相关说明
|
||||||
|
|
||||||
|
### Web 端开发
|
||||||
|
|
||||||
|
运行 `npm run dev:web` 需要:
|
||||||
|
1. 自建 `netease-cloud-music-api` 服务
|
||||||
|
2. 在项目根目录创建 `.env.development.local`:
|
||||||
|
```env
|
||||||
|
VITE_API=https://your-api-server.com
|
||||||
|
VITE_API_MUSIC=https://your-unblock-server.com
|
||||||
|
```
|
||||||
|
|
||||||
|
### Electron 功能
|
||||||
|
|
||||||
|
- **窗口管理**: `src/main/modules/window.ts`(主窗口、迷你模式、歌词窗口)
|
||||||
|
- **系统托盘**: `src/main/modules/tray.ts`
|
||||||
|
- **全局快捷键**: `src/main/modules/shortcuts.ts`
|
||||||
|
- **自动更新**: `src/main/modules/update.ts`(electron-updater + GitHub Releases)
|
||||||
|
- **远程控制**: `src/main/modules/remoteControl.ts`(HTTP API 远程播放控制)
|
||||||
|
- **磁盘缓存**: 音乐和歌词文件缓存,支持可配置目录、容量上限、LRU/FIFO 清理策略
|
||||||
|
|
||||||
|
## API 请求注意事项
|
||||||
|
|
||||||
|
- **axios 响应结构**:`request.get('/xxx')` 返回 axios response,实际数据在 `res.data` 中。若 API 本身也有 `data` 字段(如 `/personal_fm` 返回 `{data: [...], code: 200}`),则需要 `res.data.data` 才能拿到真正的数组,**不要** 直接用 `res.data` 当结果。
|
||||||
|
- **避免并发请求风暴**:首页不要一次性并发请求大量接口(如 15 个歌单详情),会导致本地 API 服务与 `music.163.com` 的 TLS 连接被 reset(502)。应使用懒加载(hover 时加载)或严格限制并发数。
|
||||||
|
- **timestamp 参数**:对 `/personal_fm` 等需要实时数据的接口,传 `timestamp: Date.now()` 避免服务端缓存和 stale 连接。`request.ts` 拦截器已自动添加 timestamp,API 层无需重复添加。
|
||||||
|
|
||||||
|
### 本地 API 服务调试
|
||||||
|
|
||||||
|
- **地址**:`http://127.0.0.1:{port}`,默认端口 `30488`,可在设置中修改
|
||||||
|
- **API 文档**:基于 [NeteaseCloudMusicApi](https://www.npmjs.com/package/NeteaseCloudMusicApi)(v4.29),接口文档参见 node_modules/NeteaseCloudMusicApi/public/docs/home.md
|
||||||
|
- **调试方式**:可直接用 `curl` 测试接口,例如:
|
||||||
|
```bash
|
||||||
|
# 测试私人FM(需登录 cookie)
|
||||||
|
curl "http://127.0.0.1:30488/personal_fm?timestamp=$(date +%s000)"
|
||||||
|
# 测试歌单详情
|
||||||
|
curl "http://127.0.0.1:30488/playlist/detail?id=12449928929"
|
||||||
|
# 测试FM不喜欢
|
||||||
|
curl -X POST "http://127.0.0.1:30488/fm_trash?id=歌曲ID×tamp=$(date +%s000)"
|
||||||
|
```
|
||||||
|
- **502 排查**:通常是并发请求过多导致 TLS 连接 reset,用 curl 单独调用可验证接口本身是否正常
|
||||||
|
- **Cookie 传递**:渲染进程通过 `request.ts` 拦截器自动附加 `localStorage` 中的 token
|
||||||
|
|
||||||
|
## 重要注意事项
|
||||||
|
|
||||||
|
- **主分支**: `dev_electron`(PR 目标分支,非 `main`)
|
||||||
|
- **自动导入**: naive-ui 组件、Vue 组合式 API(`ref`、`computed` 等)均已自动导入
|
||||||
|
- **代码风格**: 使用 ESLint + Prettier,通过 husky + lint-staged 在 commit 时自动执行
|
||||||
|
- **国际化**: 所有面向用户的文字必须翻译为 5 种语言
|
||||||
|
- **提交规范**: commit message 中禁止包含 `Co-Authored-By` 信息
|
||||||
|
- **IndexedDB 存储**:
|
||||||
|
- `music`: 歌曲元数据缓存
|
||||||
|
- `music_lyric`: 歌词缓存
|
||||||
|
- `api_cache`: 通用 API 响应缓存
|
||||||
|
- `music_url_cache`: 音乐 URL 缓存(30 分钟 TTL)
|
||||||
@@ -16,5 +16,7 @@
|
|||||||
<true/>
|
<true/>
|
||||||
<key>com.apple.security.files.downloads.read-write</key>
|
<key>com.apple.security.files.downloads.read-write</key>
|
||||||
<true/>
|
<true/>
|
||||||
|
<key>com.apple.security.device.microphone</key>
|
||||||
|
<true/>
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
extends: ['@commitlint/config-conventional'],
|
|
||||||
rules: {
|
|
||||||
'type-enum': [
|
|
||||||
2,
|
|
||||||
'always',
|
|
||||||
['feat', 'fix', 'perf', 'refactor', 'docs', 'style', 'test', 'build', 'ci', 'chore', 'revert']
|
|
||||||
],
|
|
||||||
'subject-empty': [2, 'never'],
|
|
||||||
'type-empty': [2, 'never']
|
|
||||||
}
|
|
||||||
};
|
|
||||||
+1
-9
@@ -18,7 +18,6 @@
|
|||||||
"dev:web": "vite dev",
|
"dev:web": "vite dev",
|
||||||
"build": "electron-vite build",
|
"build": "electron-vite build",
|
||||||
"postinstall": "electron-builder install-app-deps",
|
"postinstall": "electron-builder install-app-deps",
|
||||||
"fix-sandbox": "node scripts/fix-sandbox.js",
|
|
||||||
"build:unpack": "npm run build && electron-builder --dir",
|
"build:unpack": "npm run build && electron-builder --dir",
|
||||||
"build:win": "npm run build && electron-builder --win --publish never",
|
"build:win": "npm run build && electron-builder --win --publish never",
|
||||||
"build:mac": "npm run build && electron-builder --mac --x64 --publish never && cp dist/latest-mac.yml dist/latest-mac-x64.yml && electron-builder --mac --arm64 --publish never && cp dist/latest-mac.yml dist/latest-mac-arm64.yml && node scripts/merge_latest_mac_yml.mjs dist/latest-mac-x64.yml dist/latest-mac-arm64.yml dist/latest-mac.yml",
|
"build:mac": "npm run build && electron-builder --mac --x64 --publish never && cp dist/latest-mac.yml dist/latest-mac-x64.yml && electron-builder --mac --arm64 --publish never && cp dist/latest-mac.yml dist/latest-mac-arm64.yml && node scripts/merge_latest_mac_yml.mjs dist/latest-mac-x64.yml dist/latest-mac-arm64.yml dist/latest-mac.yml",
|
||||||
@@ -37,7 +36,6 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@electron-toolkit/preload": "^3.0.2",
|
"@electron-toolkit/preload": "^3.0.2",
|
||||||
"@electron-toolkit/utils": "^4.0.0",
|
"@electron-toolkit/utils": "^4.0.0",
|
||||||
"@httptoolkit/dbus-native": "^0.1.5",
|
|
||||||
"@unblockneteasemusic/server": "^0.27.10",
|
"@unblockneteasemusic/server": "^0.27.10",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"crypto-js": "^4.2.0",
|
"crypto-js": "^4.2.0",
|
||||||
@@ -51,7 +49,6 @@
|
|||||||
"form-data": "^4.0.5",
|
"form-data": "^4.0.5",
|
||||||
"husky": "^9.1.7",
|
"husky": "^9.1.7",
|
||||||
"jsencrypt": "^3.5.4",
|
"jsencrypt": "^3.5.4",
|
||||||
"mpris-service": "^2.1.2",
|
|
||||||
"music-metadata": "^11.10.3",
|
"music-metadata": "^11.10.3",
|
||||||
"netease-cloud-music-api-alger": "^4.30.0",
|
"netease-cloud-music-api-alger": "^4.30.0",
|
||||||
"node-fetch": "^2.7.0",
|
"node-fetch": "^2.7.0",
|
||||||
@@ -61,8 +58,6 @@
|
|||||||
"vue-i18n": "^11.2.2"
|
"vue-i18n": "^11.2.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@commitlint/cli": "^20.5.0",
|
|
||||||
"@commitlint/config-conventional": "^20.5.0",
|
|
||||||
"@electron-toolkit/eslint-config": "^2.1.0",
|
"@electron-toolkit/eslint-config": "^2.1.0",
|
||||||
"@electron-toolkit/eslint-config-ts": "^3.1.0",
|
"@electron-toolkit/eslint-config-ts": "^3.1.0",
|
||||||
"@electron-toolkit/tsconfig": "^1.0.1",
|
"@electron-toolkit/tsconfig": "^1.0.1",
|
||||||
@@ -153,6 +148,7 @@
|
|||||||
"entitlements": "build/entitlements.mac.plist",
|
"entitlements": "build/entitlements.mac.plist",
|
||||||
"entitlementsInherit": "build/entitlements.mac.plist",
|
"entitlementsInherit": "build/entitlements.mac.plist",
|
||||||
"extendInfo": {
|
"extendInfo": {
|
||||||
|
"NSMicrophoneUsageDescription": "AlgerMusicPlayer needs access to the microphone for audio visualization.",
|
||||||
"NSCameraUsageDescription": "Application requests access to the device's camera.",
|
"NSCameraUsageDescription": "Application requests access to the device's camera.",
|
||||||
"NSDocumentsFolderUsageDescription": "Application requests access to the user's Documents folder.",
|
"NSDocumentsFolderUsageDescription": "Application requests access to the user's Documents folder.",
|
||||||
"NSDownloadsFolderUsageDescription": "Application requests access to the user's Downloads folder."
|
"NSDownloadsFolderUsageDescription": "Application requests access to the user's Downloads folder."
|
||||||
@@ -226,9 +222,5 @@
|
|||||||
"electron",
|
"electron",
|
||||||
"esbuild"
|
"esbuild"
|
||||||
]
|
]
|
||||||
},
|
|
||||||
"optionalDependencies": {
|
|
||||||
"jsbi": "^4.3.2",
|
|
||||||
"x11": "^2.3.0"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "Alger Music Player",
|
"name": "Alger Music PWA",
|
||||||
"short_name": "AlgerMusic",
|
|
||||||
"description": "AlgerMusicPlayer 音乐播放器,支持在线播放、歌词显示、音乐下载等功能。",
|
|
||||||
"start_url": "/",
|
|
||||||
"display": "standalone",
|
|
||||||
"background_color": "#ffffff",
|
|
||||||
"theme_color": "#000000",
|
|
||||||
"icons": [
|
"icons": [
|
||||||
{
|
{
|
||||||
"src": "./icon.png",
|
"src": "./icon.png",
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
/**
|
|
||||||
* 修复 Linux 下 Electron sandbox 权限问题
|
|
||||||
* chrome-sandbox 需要 root 拥有且权限为 4755
|
|
||||||
*
|
|
||||||
* 注意:此脚本需要 sudo 权限,仅在 CI 环境或手动执行时使用
|
|
||||||
* 用法:sudo npm run fix-sandbox
|
|
||||||
*/
|
|
||||||
const { execSync } = require('child_process');
|
|
||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
|
||||||
|
|
||||||
if (process.platform === 'linux') {
|
|
||||||
const sandboxPath = path.resolve(__dirname, '../node_modules/electron/dist/chrome-sandbox');
|
|
||||||
if (fs.existsSync(sandboxPath)) {
|
|
||||||
execSync(`sudo chown root:root ${sandboxPath}`);
|
|
||||||
execSync(`sudo chmod 4755 ${sandboxPath}`);
|
|
||||||
console.log('[fix-sandbox] chrome-sandbox permissions fixed');
|
|
||||||
} else {
|
|
||||||
console.log('[fix-sandbox] chrome-sandbox not found, skipping');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -13,7 +13,6 @@ import { initializeFonts } from './modules/fonts';
|
|||||||
import { initializeLocalMusicScanner } from './modules/localMusicScanner';
|
import { initializeLocalMusicScanner } from './modules/localMusicScanner';
|
||||||
import { initializeLoginWindow } from './modules/loginWindow';
|
import { initializeLoginWindow } from './modules/loginWindow';
|
||||||
import { initLxMusicHttp } from './modules/lxMusicHttp';
|
import { initLxMusicHttp } from './modules/lxMusicHttp';
|
||||||
import { initializeMpris, updateMprisCurrentSong, updateMprisPlayState } from './modules/mpris';
|
|
||||||
import { initializeOtherApi } from './modules/otherApi';
|
import { initializeOtherApi } from './modules/otherApi';
|
||||||
import { initializeRemoteControl } from './modules/remoteControl';
|
import { initializeRemoteControl } from './modules/remoteControl';
|
||||||
import { initializeShortcuts } from './modules/shortcuts';
|
import { initializeShortcuts } from './modules/shortcuts';
|
||||||
@@ -83,9 +82,6 @@ function initialize(configStore: any) {
|
|||||||
// 初始化远程控制服务
|
// 初始化远程控制服务
|
||||||
initializeRemoteControl(mainWindow);
|
initializeRemoteControl(mainWindow);
|
||||||
|
|
||||||
// 初始化 MPRIS 服务 (Linux)
|
|
||||||
initializeMpris(mainWindow);
|
|
||||||
|
|
||||||
// 初始化更新处理程序
|
// 初始化更新处理程序
|
||||||
setupUpdateHandlers(mainWindow);
|
setupUpdateHandlers(mainWindow);
|
||||||
}
|
}
|
||||||
@@ -96,11 +92,6 @@ const isSingleInstance = app.requestSingleInstanceLock();
|
|||||||
if (!isSingleInstance) {
|
if (!isSingleInstance) {
|
||||||
app.quit();
|
app.quit();
|
||||||
} else {
|
} else {
|
||||||
// 禁用 Chromium 内置的 MediaSession MPRIS 服务,避免重复显示
|
|
||||||
if (process.platform === 'linux') {
|
|
||||||
app.commandLine.appendSwitch('disable-features', 'MediaSessionService');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 在应用准备就绪前初始化GPU加速设置
|
// 在应用准备就绪前初始化GPU加速设置
|
||||||
// 必须在 app.ready 之前调用 disableHardwareAcceleration
|
// 必须在 app.ready 之前调用 disableHardwareAcceleration
|
||||||
try {
|
try {
|
||||||
@@ -180,13 +171,11 @@ if (!isSingleInstance) {
|
|||||||
// 监听播放状态变化
|
// 监听播放状态变化
|
||||||
ipcMain.on('update-play-state', (_, playing: boolean) => {
|
ipcMain.on('update-play-state', (_, playing: boolean) => {
|
||||||
updatePlayState(playing);
|
updatePlayState(playing);
|
||||||
updateMprisPlayState(playing);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// 监听当前歌曲变化
|
// 监听当前歌曲变化
|
||||||
ipcMain.on('update-current-song', (_, song: any) => {
|
ipcMain.on('update-current-song', (_, song: any) => {
|
||||||
updateCurrentSong(song);
|
updateCurrentSong(song);
|
||||||
updateMprisCurrentSong(song);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// 所有窗口关闭时的处理
|
// 所有窗口关闭时的处理
|
||||||
|
|||||||
@@ -10,65 +10,6 @@ let isDragging = false;
|
|||||||
|
|
||||||
// 添加窗口大小变化防护
|
// 添加窗口大小变化防护
|
||||||
let originalSize = { width: 0, height: 0 };
|
let originalSize = { width: 0, height: 0 };
|
||||||
// 鼠标位置轮询仅在"锁定 + 可见"时启用,解锁态下 DOM 事件已足够
|
|
||||||
let mousePresenceTimer: ReturnType<typeof setInterval> | null = null;
|
|
||||||
let lastMouseInside: boolean | null = null;
|
|
||||||
let isLyricLocked = false;
|
|
||||||
let isLyricWindowVisible = false;
|
|
||||||
|
|
||||||
const isPointInsideWindow = (
|
|
||||||
point: { x: number; y: number },
|
|
||||||
bounds: { x: number; y: number; width: number; height: number }
|
|
||||||
) => {
|
|
||||||
return (
|
|
||||||
point.x >= bounds.x &&
|
|
||||||
point.x < bounds.x + bounds.width &&
|
|
||||||
point.y >= bounds.y &&
|
|
||||||
point.y < bounds.y + bounds.height
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const stopMousePresenceTracking = () => {
|
|
||||||
if (mousePresenceTimer) {
|
|
||||||
clearInterval(mousePresenceTimer);
|
|
||||||
mousePresenceTimer = null;
|
|
||||||
}
|
|
||||||
lastMouseInside = null;
|
|
||||||
};
|
|
||||||
|
|
||||||
const emitMousePresence = () => {
|
|
||||||
if (!lyricWindow || lyricWindow.isDestroyed()) return;
|
|
||||||
|
|
||||||
const mousePoint = screen.getCursorScreenPoint();
|
|
||||||
const bounds = lyricWindow.getBounds();
|
|
||||||
const isInside = isPointInsideWindow(mousePoint, bounds);
|
|
||||||
|
|
||||||
if (isInside === lastMouseInside) return;
|
|
||||||
|
|
||||||
lastMouseInside = isInside;
|
|
||||||
lyricWindow.webContents.send('lyric-mouse-presence', isInside);
|
|
||||||
};
|
|
||||||
|
|
||||||
const startMousePresenceTracking = () => {
|
|
||||||
if (mousePresenceTimer) return;
|
|
||||||
|
|
||||||
emitMousePresence();
|
|
||||||
mousePresenceTimer = setInterval(() => {
|
|
||||||
if (!lyricWindow || lyricWindow.isDestroyed()) {
|
|
||||||
stopMousePresenceTracking();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
emitMousePresence();
|
|
||||||
}, 50);
|
|
||||||
};
|
|
||||||
|
|
||||||
const syncMousePresenceTracking = () => {
|
|
||||||
if (isLyricLocked && isLyricWindowVisible && lyricWindow && !lyricWindow.isDestroyed()) {
|
|
||||||
startMousePresenceTracking();
|
|
||||||
} else {
|
|
||||||
stopMousePresenceTracking();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const createWin = () => {
|
const createWin = () => {
|
||||||
console.log('Creating lyric window');
|
console.log('Creating lyric window');
|
||||||
@@ -161,32 +102,12 @@ const createWin = () => {
|
|||||||
|
|
||||||
// 监听窗口关闭事件
|
// 监听窗口关闭事件
|
||||||
lyricWindow.on('closed', () => {
|
lyricWindow.on('closed', () => {
|
||||||
stopMousePresenceTracking();
|
|
||||||
isLyricLocked = false;
|
|
||||||
isLyricWindowVisible = false;
|
|
||||||
if (lyricWindow) {
|
if (lyricWindow) {
|
||||||
lyricWindow.destroy();
|
lyricWindow.destroy();
|
||||||
lyricWindow = null;
|
lyricWindow = null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
lyricWindow.on('show', () => {
|
|
||||||
isLyricWindowVisible = true;
|
|
||||||
syncMousePresenceTracking();
|
|
||||||
});
|
|
||||||
lyricWindow.on('hide', () => {
|
|
||||||
isLyricWindowVisible = false;
|
|
||||||
stopMousePresenceTracking();
|
|
||||||
});
|
|
||||||
lyricWindow.on('minimize', () => {
|
|
||||||
isLyricWindowVisible = false;
|
|
||||||
stopMousePresenceTracking();
|
|
||||||
});
|
|
||||||
lyricWindow.on('restore', () => {
|
|
||||||
isLyricWindowVisible = true;
|
|
||||||
syncMousePresenceTracking();
|
|
||||||
});
|
|
||||||
|
|
||||||
// 监听窗口大小变化事件,保存新的尺寸
|
// 监听窗口大小变化事件,保存新的尺寸
|
||||||
lyricWindow.on('resize', () => {
|
lyricWindow.on('resize', () => {
|
||||||
// 如果正在拖动,忽略大小调整事件
|
// 如果正在拖动,忽略大小调整事件
|
||||||
@@ -284,17 +205,6 @@ export const loadLyricWindow = (ipcMain: IpcMain, mainWin: BrowserWindow): void
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on('set-lyric-lock-state', (_, isLocked: boolean) => {
|
|
||||||
isLyricLocked = isLocked;
|
|
||||||
if (lyricWindow && !lyricWindow.isDestroyed()) {
|
|
||||||
// 锁定时禁用 resize,避免鼠标移到边缘仍显示调整光标
|
|
||||||
lyricWindow.setResizable(!isLocked);
|
|
||||||
// 设置初始穿透状态,后续 polling 会按实际位置纠正
|
|
||||||
lyricWindow.setIgnoreMouseEvents(isLocked, { forward: true });
|
|
||||||
}
|
|
||||||
syncMousePresenceTracking();
|
|
||||||
});
|
|
||||||
|
|
||||||
// 处理鼠标事件
|
// 处理鼠标事件
|
||||||
ipcMain.on('mouseenter-lyric', () => {
|
ipcMain.on('mouseenter-lyric', () => {
|
||||||
if (lyricWindow && !lyricWindow.isDestroyed()) {
|
if (lyricWindow && !lyricWindow.isDestroyed()) {
|
||||||
|
|||||||
@@ -523,7 +523,7 @@ class DownloadManager {
|
|||||||
} else {
|
} else {
|
||||||
// Full response (200) - start from beginning
|
// Full response (200) - start from beginning
|
||||||
task.loaded = 0;
|
task.loaded = 0;
|
||||||
const contentLength = response.headers['content-length'] as string;
|
const contentLength = response.headers['content-length'];
|
||||||
task.total = contentLength ? parseInt(contentLength, 10) : 0;
|
task.total = contentLength ? parseInt(contentLength, 10) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,270 +0,0 @@
|
|||||||
import { app, BrowserWindow, ipcMain } from 'electron';
|
|
||||||
import Player from 'mpris-service';
|
|
||||||
|
|
||||||
let dbusModule: any;
|
|
||||||
try {
|
|
||||||
dbusModule = require('@httptoolkit/dbus-native');
|
|
||||||
} catch {
|
|
||||||
// dbus-native 不可用(非 Linux 环境)
|
|
||||||
}
|
|
||||||
|
|
||||||
interface SongInfo {
|
|
||||||
id?: number | string;
|
|
||||||
name: string;
|
|
||||||
picUrl?: string;
|
|
||||||
ar?: Array<{ name: string }>;
|
|
||||||
artists?: Array<{ name: string }>;
|
|
||||||
al?: { name: string };
|
|
||||||
album?: { name: string };
|
|
||||||
duration?: number;
|
|
||||||
dt?: number;
|
|
||||||
song?: {
|
|
||||||
artists?: Array<{ name: string }>;
|
|
||||||
album?: { name: string };
|
|
||||||
duration?: number;
|
|
||||||
picUrl?: string;
|
|
||||||
};
|
|
||||||
[key: string]: any;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mprisPlayer: Player | null = null;
|
|
||||||
let mainWindow: BrowserWindow | null = null;
|
|
||||||
let currentPosition = 0;
|
|
||||||
let trayLyricIface: any = null;
|
|
||||||
let trayLyricBus: any = null;
|
|
||||||
|
|
||||||
// 保存 IPC 处理函数引用,用于清理
|
|
||||||
let onPositionUpdate: ((event: any, position: number) => void) | null = null;
|
|
||||||
let onTrayLyricUpdate: ((event: any, lrcObj: string) => void) | null = null;
|
|
||||||
|
|
||||||
export function initializeMpris(mainWindowRef: BrowserWindow) {
|
|
||||||
if (process.platform !== 'linux') return;
|
|
||||||
|
|
||||||
if (mprisPlayer) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
mainWindow = mainWindowRef;
|
|
||||||
|
|
||||||
try {
|
|
||||||
mprisPlayer = Player({
|
|
||||||
name: 'AlgerMusicPlayer',
|
|
||||||
identity: 'Alger Music Player',
|
|
||||||
supportedUriSchemes: ['file', 'http', 'https'],
|
|
||||||
supportedMimeTypes: [
|
|
||||||
'audio/mpeg',
|
|
||||||
'audio/mp3',
|
|
||||||
'audio/flac',
|
|
||||||
'audio/wav',
|
|
||||||
'audio/ogg',
|
|
||||||
'audio/aac',
|
|
||||||
'audio/m4a'
|
|
||||||
],
|
|
||||||
supportedInterfaces: ['player']
|
|
||||||
});
|
|
||||||
|
|
||||||
mprisPlayer.on('quit', () => {
|
|
||||||
app.quit();
|
|
||||||
});
|
|
||||||
|
|
||||||
mprisPlayer.on('raise', () => {
|
|
||||||
if (mainWindow) {
|
|
||||||
mainWindow.show();
|
|
||||||
mainWindow.focus();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
mprisPlayer.on('next', () => {
|
|
||||||
if (mainWindow) {
|
|
||||||
mainWindow.webContents.send('global-shortcut', 'nextPlay');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
mprisPlayer.on('previous', () => {
|
|
||||||
if (mainWindow) {
|
|
||||||
mainWindow.webContents.send('global-shortcut', 'prevPlay');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
mprisPlayer.on('pause', () => {
|
|
||||||
if (mainWindow) {
|
|
||||||
mainWindow.webContents.send('mpris-pause');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
mprisPlayer.on('play', () => {
|
|
||||||
if (mainWindow) {
|
|
||||||
mainWindow.webContents.send('mpris-play');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
mprisPlayer.on('playpause', () => {
|
|
||||||
if (mainWindow) {
|
|
||||||
mainWindow.webContents.send('global-shortcut', 'togglePlay');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
mprisPlayer.on('stop', () => {
|
|
||||||
if (mainWindow) {
|
|
||||||
mainWindow.webContents.send('mpris-pause');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
mprisPlayer.getPosition = (): number => {
|
|
||||||
return currentPosition;
|
|
||||||
};
|
|
||||||
|
|
||||||
mprisPlayer.on('seek', (offset: number) => {
|
|
||||||
if (mainWindow) {
|
|
||||||
const newPosition = Math.max(0, currentPosition + offset / 1000000);
|
|
||||||
mainWindow.webContents.send('mpris-seek', newPosition);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
mprisPlayer.on('position', (event: { trackId: string; position: number }) => {
|
|
||||||
if (mainWindow) {
|
|
||||||
mainWindow.webContents.send('mpris-set-position', event.position / 1000000);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
onPositionUpdate = (_, position: number) => {
|
|
||||||
currentPosition = position * 1000 * 1000;
|
|
||||||
if (mprisPlayer) {
|
|
||||||
mprisPlayer.seeked(position * 1000 * 1000);
|
|
||||||
mprisPlayer.getPosition = () => position * 1000 * 1000;
|
|
||||||
mprisPlayer.position = position * 1000 * 1000;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
ipcMain.on('mpris-position-update', onPositionUpdate);
|
|
||||||
|
|
||||||
onTrayLyricUpdate = (_, lrcObj: string) => {
|
|
||||||
sendTrayLyric(lrcObj);
|
|
||||||
};
|
|
||||||
ipcMain.on('tray-lyric-update', onTrayLyricUpdate);
|
|
||||||
|
|
||||||
initTrayLyric();
|
|
||||||
|
|
||||||
console.log('[MPRIS] Service initialized');
|
|
||||||
} catch (error) {
|
|
||||||
console.error('[MPRIS] Failed to initialize:', error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function updateMprisPlayState(playing: boolean) {
|
|
||||||
if (!mprisPlayer || process.platform !== 'linux') return;
|
|
||||||
mprisPlayer.playbackStatus = playing ? 'Playing' : 'Paused';
|
|
||||||
}
|
|
||||||
|
|
||||||
export function updateMprisCurrentSong(song: SongInfo | null) {
|
|
||||||
if (!mprisPlayer || process.platform !== 'linux') return;
|
|
||||||
|
|
||||||
if (!song) {
|
|
||||||
mprisPlayer.metadata = {};
|
|
||||||
mprisPlayer.playbackStatus = 'Stopped';
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const artists =
|
|
||||||
song.ar?.map((a) => a.name).join(', ') ||
|
|
||||||
song.artists?.map((a) => a.name).join(', ') ||
|
|
||||||
song.song?.artists?.map((a) => a.name).join(', ') ||
|
|
||||||
'';
|
|
||||||
const album = song.al?.name || song.album?.name || song.song?.album?.name || '';
|
|
||||||
const duration = song.duration || song.dt || song.song?.duration || 0;
|
|
||||||
|
|
||||||
mprisPlayer.metadata = {
|
|
||||||
'mpris:trackid': mprisPlayer.objectPath(`track/${song.id || 0}`),
|
|
||||||
'mpris:length': duration * 1000,
|
|
||||||
'mpris:artUrl': song.picUrl || '',
|
|
||||||
'xesam:title': song.name || '',
|
|
||||||
'xesam:album': album,
|
|
||||||
'xesam:artist': artists ? [artists] : []
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function updateMprisPosition(position: number) {
|
|
||||||
if (!mprisPlayer || process.platform !== 'linux') return;
|
|
||||||
mprisPlayer.seeked(position * 1000000);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function destroyMpris() {
|
|
||||||
if (onPositionUpdate) {
|
|
||||||
ipcMain.removeListener('mpris-position-update', onPositionUpdate);
|
|
||||||
onPositionUpdate = null;
|
|
||||||
}
|
|
||||||
if (onTrayLyricUpdate) {
|
|
||||||
ipcMain.removeListener('tray-lyric-update', onTrayLyricUpdate);
|
|
||||||
onTrayLyricUpdate = null;
|
|
||||||
}
|
|
||||||
if (mprisPlayer) {
|
|
||||||
mprisPlayer.quit();
|
|
||||||
mprisPlayer = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function initTrayLyric() {
|
|
||||||
if (process.platform !== 'linux' || !dbusModule) return;
|
|
||||||
|
|
||||||
const serviceName = 'org.gnome.Shell.TrayLyric';
|
|
||||||
|
|
||||||
try {
|
|
||||||
const sessionBus = dbusModule.sessionBus({});
|
|
||||||
trayLyricBus = sessionBus;
|
|
||||||
|
|
||||||
const dbusPath = '/org/freedesktop/DBus';
|
|
||||||
const dbusInterface = 'org.freedesktop.DBus';
|
|
||||||
|
|
||||||
sessionBus.invoke(
|
|
||||||
{
|
|
||||||
path: dbusPath,
|
|
||||||
interface: dbusInterface,
|
|
||||||
member: 'GetNameOwner',
|
|
||||||
destination: 'org.freedesktop.DBus',
|
|
||||||
signature: 's',
|
|
||||||
body: [serviceName]
|
|
||||||
},
|
|
||||||
(err: any, result: any) => {
|
|
||||||
if (err || !result) {
|
|
||||||
console.log('[TrayLyric] Service not running');
|
|
||||||
} else {
|
|
||||||
onServiceAvailable();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} catch (err) {
|
|
||||||
console.error('[TrayLyric] Failed to init:', err);
|
|
||||||
}
|
|
||||||
|
|
||||||
function onServiceAvailable() {
|
|
||||||
if (!trayLyricBus) return;
|
|
||||||
const path = '/' + serviceName.replace(/\./g, '/');
|
|
||||||
trayLyricBus.getService(serviceName).getInterface(path, serviceName, (err: any, iface: any) => {
|
|
||||||
if (err) {
|
|
||||||
console.error('[TrayLyric] Failed to get service interface:', err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
trayLyricIface = iface;
|
|
||||||
console.log('[TrayLyric] Service interface ready');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function sendTrayLyric(lrcObj: string) {
|
|
||||||
if (!trayLyricIface || !trayLyricBus) return;
|
|
||||||
|
|
||||||
trayLyricBus.invoke(
|
|
||||||
{
|
|
||||||
path: '/org/gnome/Shell/TrayLyric',
|
|
||||||
interface: 'org.gnome.Shell.TrayLyric',
|
|
||||||
member: 'UpdateLyric',
|
|
||||||
destination: 'org.gnome.Shell.TrayLyric',
|
|
||||||
signature: 's',
|
|
||||||
body: [lrcObj]
|
|
||||||
},
|
|
||||||
(err: any, _result: any) => {
|
|
||||||
if (err) {
|
|
||||||
console.error('[TrayLyric] Failed to invoke UpdateLyric:', err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Vendored
-23
@@ -1,23 +0,0 @@
|
|||||||
declare module 'mpris-service' {
|
|
||||||
interface PlayerOptions {
|
|
||||||
name: string;
|
|
||||||
identity: string;
|
|
||||||
supportedUriSchemes?: string[];
|
|
||||||
supportedMimeTypes?: string[];
|
|
||||||
supportedInterfaces?: string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Player {
|
|
||||||
on(event: string, callback: (...args: any[]) => void): void;
|
|
||||||
playbackStatus: string;
|
|
||||||
metadata: Record<string, any>;
|
|
||||||
position: number;
|
|
||||||
getPosition: () => number;
|
|
||||||
seeked(position: number): void;
|
|
||||||
objectPath(path: string): string;
|
|
||||||
quit(): void;
|
|
||||||
}
|
|
||||||
|
|
||||||
function Player(options: PlayerOptions): Player;
|
|
||||||
export = Player;
|
|
||||||
}
|
|
||||||
@@ -202,18 +202,19 @@ import {
|
|||||||
useLyricProgress
|
useLyricProgress
|
||||||
} from '@/hooks/MusicHook';
|
} from '@/hooks/MusicHook';
|
||||||
import { useArtist } from '@/hooks/useArtist';
|
import { useArtist } from '@/hooks/useArtist';
|
||||||
import { useLyricBackground } from '@/hooks/useLyricBackground';
|
|
||||||
import { usePlayerStore } from '@/store/modules/player';
|
import { usePlayerStore } from '@/store/modules/player';
|
||||||
import { useSettingsStore } from '@/store/modules/settings';
|
import { useSettingsStore } from '@/store/modules/settings';
|
||||||
import { DEFAULT_LYRIC_CONFIG, LyricConfig } from '@/types/lyric';
|
import { DEFAULT_LYRIC_CONFIG, LyricConfig } from '@/types/lyric';
|
||||||
import { getImgUrl, isMobile } from '@/utils';
|
import { getImgUrl, isMobile } from '@/utils';
|
||||||
import { getTextColors } from '@/utils/linearColor';
|
import { animateGradient, getHoverBackgroundColor, getTextColors } from '@/utils/linearColor';
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
// 定义 refs
|
// 定义 refs
|
||||||
const lrcSider = ref<any>(null);
|
const lrcSider = ref<any>(null);
|
||||||
const isMouse = ref(false);
|
const isMouse = ref(false);
|
||||||
const { currentBackground, applyBackground } = useLyricBackground();
|
const currentBackground = ref('');
|
||||||
|
const animationFrame = ref<number | null>(null);
|
||||||
|
const isDark = ref(false);
|
||||||
|
|
||||||
// 计算自定义背景样式
|
// 计算自定义背景样式
|
||||||
const customBackgroundStyle = computed(() => {
|
const customBackgroundStyle = computed(() => {
|
||||||
@@ -380,6 +381,42 @@ watch(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const setTextColors = (background: string) => {
|
||||||
|
if (!background) {
|
||||||
|
textColors.value = getTextColors();
|
||||||
|
document.documentElement.style.setProperty('--hover-bg-color', getHoverBackgroundColor(false));
|
||||||
|
document.documentElement.style.setProperty('--text-color-primary', textColors.value.primary);
|
||||||
|
document.documentElement.style.setProperty('--text-color-active', textColors.value.active);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新文字颜色
|
||||||
|
textColors.value = getTextColors(background);
|
||||||
|
isDark.value = textColors.value.active === '#000000';
|
||||||
|
|
||||||
|
document.documentElement.style.setProperty(
|
||||||
|
'--hover-bg-color',
|
||||||
|
getHoverBackgroundColor(isDark.value)
|
||||||
|
);
|
||||||
|
document.documentElement.style.setProperty('--text-color-primary', textColors.value.primary);
|
||||||
|
document.documentElement.style.setProperty('--text-color-active', textColors.value.active);
|
||||||
|
|
||||||
|
// 处理背景颜色动画
|
||||||
|
if (currentBackground.value) {
|
||||||
|
if (animationFrame.value) {
|
||||||
|
cancelAnimationFrame(animationFrame.value);
|
||||||
|
}
|
||||||
|
const result = animateGradient(currentBackground.value, background, (gradient) => {
|
||||||
|
currentBackground.value = gradient;
|
||||||
|
});
|
||||||
|
if (typeof result === 'number') {
|
||||||
|
animationFrame.value = result;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
currentBackground.value = background;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const targetBackground = computed(() => {
|
const targetBackground = computed(() => {
|
||||||
if (config.value.useCustomBackground && customBackgroundStyle.value) {
|
if (config.value.useCustomBackground && customBackgroundStyle.value) {
|
||||||
if (typeof customBackgroundStyle.value === 'string') {
|
if (typeof customBackgroundStyle.value === 'string') {
|
||||||
@@ -397,7 +434,7 @@ watch(
|
|||||||
targetBackground,
|
targetBackground,
|
||||||
(newBg) => {
|
(newBg) => {
|
||||||
if (newBg) {
|
if (newBg) {
|
||||||
applyBackground(newBg);
|
setTextColors(newBg);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ immediate: true }
|
{ immediate: true }
|
||||||
@@ -486,6 +523,13 @@ const getWordStyle = (lineIndex: number, _wordIndex: number, word: any) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 组件卸载时清理动画
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
if (animationFrame.value) {
|
||||||
|
cancelAnimationFrame(animationFrame.value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const settingsStore = useSettingsStore();
|
const settingsStore = useSettingsStore();
|
||||||
|
|
||||||
const { navigateToArtist } = useArtist();
|
const { navigateToArtist } = useArtist();
|
||||||
@@ -582,6 +626,9 @@ onMounted(() => {
|
|||||||
|
|
||||||
// 移除滚动监听和全屏状态监听
|
// 移除滚动监听和全屏状态监听
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
|
if (animationFrame.value) {
|
||||||
|
cancelAnimationFrame(animationFrame.value);
|
||||||
|
}
|
||||||
if (lrcSider.value?.$el) {
|
if (lrcSider.value?.$el) {
|
||||||
lrcSider.value.$el.removeEventListener('scroll', handleScroll);
|
lrcSider.value.$el.removeEventListener('scroll', handleScroll);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -408,13 +408,12 @@ import {
|
|||||||
useLyricProgress
|
useLyricProgress
|
||||||
} from '@/hooks/MusicHook';
|
} from '@/hooks/MusicHook';
|
||||||
import { useArtist } from '@/hooks/useArtist';
|
import { useArtist } from '@/hooks/useArtist';
|
||||||
import { useLyricBackground } from '@/hooks/useLyricBackground';
|
|
||||||
import { usePlayMode } from '@/hooks/usePlayMode';
|
import { usePlayMode } from '@/hooks/usePlayMode';
|
||||||
import { audioService } from '@/services/audioService';
|
import { audioService } from '@/services/audioService';
|
||||||
import { usePlayerStore } from '@/store/modules/player';
|
import { usePlayerStore } from '@/store/modules/player';
|
||||||
import { DEFAULT_LYRIC_CONFIG, LyricConfig } from '@/types/lyric';
|
import { DEFAULT_LYRIC_CONFIG, LyricConfig } from '@/types/lyric';
|
||||||
import { getImgUrl, secondToMinute } from '@/utils';
|
import { getImgUrl, secondToMinute } from '@/utils';
|
||||||
import { getTextColors } from '@/utils/linearColor';
|
import { animateGradient, getHoverBackgroundColor, getTextColors } from '@/utils/linearColor';
|
||||||
import { showBottomToast } from '@/utils/shortcutToast';
|
import { showBottomToast } from '@/utils/shortcutToast';
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
@@ -877,10 +876,10 @@ const handleThumbTouchEnd = (e: TouchEvent) => {
|
|||||||
isThumbDragging.value = false;
|
isThumbDragging.value = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
// 背景相关(由 composable 管理)
|
// 背景相关
|
||||||
const { isDark, applyBackground } = useLyricBackground({
|
const currentBackground = ref('');
|
||||||
writeBgColor: () => playerStore.playMusic.primaryColor || undefined
|
const animationFrame = ref<number | null>(null);
|
||||||
});
|
const isDark = ref(false);
|
||||||
const config = ref<LyricConfig>({ ...DEFAULT_LYRIC_CONFIG });
|
const config = ref<LyricConfig>({ ...DEFAULT_LYRIC_CONFIG });
|
||||||
|
|
||||||
// 可见歌词计算
|
// 可见歌词计算
|
||||||
@@ -938,6 +937,49 @@ const isVisible = computed({
|
|||||||
set: (value) => emit('update:modelValue', value)
|
set: (value) => emit('update:modelValue', value)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 设置文字颜色
|
||||||
|
const setTextColors = (background: string) => {
|
||||||
|
if (!background) {
|
||||||
|
textColors.value = getTextColors();
|
||||||
|
document.documentElement.style.setProperty('--hover-bg-color', getHoverBackgroundColor(false));
|
||||||
|
document.documentElement.style.setProperty('--text-color-primary', textColors.value.primary);
|
||||||
|
document.documentElement.style.setProperty('--text-color-active', textColors.value.active);
|
||||||
|
document.documentElement.style.setProperty('--bg-color', 'rgba(25, 25, 25, 1)');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新文字颜色
|
||||||
|
textColors.value = getTextColors(background);
|
||||||
|
isDark.value = textColors.value.active === '#000000';
|
||||||
|
|
||||||
|
document.documentElement.style.setProperty(
|
||||||
|
'--hover-bg-color',
|
||||||
|
getHoverBackgroundColor(isDark.value)
|
||||||
|
);
|
||||||
|
document.documentElement.style.setProperty('--text-color-primary', textColors.value.primary);
|
||||||
|
document.documentElement.style.setProperty('--text-color-active', textColors.value.active);
|
||||||
|
|
||||||
|
// 解析背景颜色用于封面融合
|
||||||
|
let bgColor = playerStore.playMusic.primaryColor || 'rgba(25, 25, 25, 1)';
|
||||||
|
|
||||||
|
document.documentElement.style.setProperty('--bg-color', bgColor);
|
||||||
|
|
||||||
|
// 处理背景颜色动画
|
||||||
|
if (currentBackground.value) {
|
||||||
|
if (animationFrame.value) {
|
||||||
|
cancelAnimationFrame(animationFrame.value);
|
||||||
|
}
|
||||||
|
const result = animateGradient(currentBackground.value, background, (gradient) => {
|
||||||
|
currentBackground.value = gradient;
|
||||||
|
});
|
||||||
|
if (typeof result === 'number') {
|
||||||
|
animationFrame.value = result;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
currentBackground.value = background;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const targetBackground = computed(() => {
|
const targetBackground = computed(() => {
|
||||||
if (config.value.theme !== 'default') {
|
if (config.value.theme !== 'default') {
|
||||||
return themeMusic[config.value.theme] || props.background;
|
return themeMusic[config.value.theme] || props.background;
|
||||||
@@ -950,14 +992,17 @@ watch(
|
|||||||
targetBackground,
|
targetBackground,
|
||||||
(newBg) => {
|
(newBg) => {
|
||||||
if (newBg) {
|
if (newBg) {
|
||||||
applyBackground(newBg);
|
setTextColors(newBg);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ immediate: true }
|
{ immediate: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
// 组件卸载清理
|
// 组件卸载时清理动画
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
|
if (animationFrame.value) {
|
||||||
|
cancelAnimationFrame(animationFrame.value);
|
||||||
|
}
|
||||||
if (autoScrollTimer.value) {
|
if (autoScrollTimer.value) {
|
||||||
clearTimeout(autoScrollTimer.value);
|
clearTimeout(autoScrollTimer.value);
|
||||||
}
|
}
|
||||||
@@ -1068,7 +1113,7 @@ watch(isVisible, (newVal) => {
|
|||||||
if (newVal) {
|
if (newVal) {
|
||||||
// 播放器显示时,重新设置背景颜色
|
// 播放器显示时,重新设置背景颜色
|
||||||
if (targetBackground.value) {
|
if (targetBackground.value) {
|
||||||
applyBackground(targetBackground.value);
|
setTextColors(targetBackground.value);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
showFullLyrics.value = false;
|
showFullLyrics.value = false;
|
||||||
|
|||||||
@@ -69,7 +69,6 @@
|
|||||||
v-model:value="volumeSlider"
|
v-model:value="volumeSlider"
|
||||||
:step="0.01"
|
:step="0.01"
|
||||||
:tooltip="false"
|
:tooltip="false"
|
||||||
:disabled="isMuted"
|
|
||||||
vertical
|
vertical
|
||||||
@wheel.prevent="handleVolumeWheel"
|
@wheel.prevent="handleVolumeWheel"
|
||||||
></n-slider>
|
></n-slider>
|
||||||
@@ -146,13 +145,7 @@ const { navigateToArtist } = useArtist();
|
|||||||
const { isPlaying: play, playMusicEvent, handleNext, handlePrev } = usePlaybackControl();
|
const { isPlaying: play, playMusicEvent, handleNext, handlePrev } = usePlaybackControl();
|
||||||
|
|
||||||
// 音量控制(统一通过 playerStore 管理)
|
// 音量控制(统一通过 playerStore 管理)
|
||||||
const {
|
const { volumeSlider, volumeIcon: getVolumeIcon, mute, handleVolumeWheel } = useVolumeControl();
|
||||||
isMuted,
|
|
||||||
volumeSlider,
|
|
||||||
volumeIcon: getVolumeIcon,
|
|
||||||
mute,
|
|
||||||
handleVolumeWheel
|
|
||||||
} = useVolumeControl();
|
|
||||||
|
|
||||||
// 收藏
|
// 收藏
|
||||||
const { isFavorite, toggleFavorite } = useFavorite();
|
const { isFavorite, toggleFavorite } = useFavorite();
|
||||||
|
|||||||
@@ -99,16 +99,8 @@
|
|||||||
<i class="iconfont" :class="getVolumeIcon"></i>
|
<i class="iconfont" :class="getVolumeIcon"></i>
|
||||||
</div>
|
</div>
|
||||||
<div class="volume-slider">
|
<div class="volume-slider">
|
||||||
<div class="volume-percentage" :class="{ 'volume-percentage-disabled': isMuted }">
|
<div class="volume-percentage">{{ Math.round(volumeSlider) }}%</div>
|
||||||
{{ Math.round(volumeSlider) }}%
|
<n-slider v-model:value="volumeSlider" :step="0.01" :tooltip="false" vertical></n-slider>
|
||||||
</div>
|
|
||||||
<n-slider
|
|
||||||
v-model:value="volumeSlider"
|
|
||||||
:step="0.01"
|
|
||||||
:tooltip="false"
|
|
||||||
:disabled="isMuted"
|
|
||||||
vertical
|
|
||||||
></n-slider>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<n-tooltip v-if="!isMobile" trigger="hover" :z-index="9999999">
|
<n-tooltip v-if="!isMobile" trigger="hover" :z-index="9999999">
|
||||||
@@ -206,13 +198,7 @@ const { t } = useI18n();
|
|||||||
const { isPlaying: play, playMusicEvent, handleNext, handlePrev } = usePlaybackControl();
|
const { isPlaying: play, playMusicEvent, handleNext, handlePrev } = usePlaybackControl();
|
||||||
|
|
||||||
// 音量控制
|
// 音量控制
|
||||||
const {
|
const { volumeSlider, volumeIcon: getVolumeIcon, mute, handleVolumeWheel } = useVolumeControl();
|
||||||
isMuted,
|
|
||||||
volumeSlider,
|
|
||||||
volumeIcon: getVolumeIcon,
|
|
||||||
mute,
|
|
||||||
handleVolumeWheel
|
|
||||||
} = useVolumeControl();
|
|
||||||
|
|
||||||
// 收藏
|
// 收藏
|
||||||
const { isFavorite, toggleFavorite } = useFavorite();
|
const { isFavorite, toggleFavorite } = useFavorite();
|
||||||
@@ -396,10 +382,6 @@ const openPlayListDrawer = () => {
|
|||||||
@apply border border-gray-200 dark:border-gray-700;
|
@apply border border-gray-200 dark:border-gray-700;
|
||||||
@apply text-gray-800 dark:text-white;
|
@apply text-gray-800 dark:text-white;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
|
|
||||||
&.volume-percentage-disabled {
|
|
||||||
@apply text-gray-400 dark:text-gray-500;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,6 @@
|
|||||||
v-model:value="volumeSlider"
|
v-model:value="volumeSlider"
|
||||||
:step="1"
|
:step="1"
|
||||||
:tooltip="false"
|
:tooltip="false"
|
||||||
:disabled="isMuted"
|
|
||||||
@wheel.prevent="handleVolumeWheel"
|
@wheel.prevent="handleVolumeWheel"
|
||||||
></n-slider>
|
></n-slider>
|
||||||
</div>
|
</div>
|
||||||
@@ -108,13 +107,7 @@ const { isPlaying: play, playMusicEvent, handleNext, handlePrev } = usePlaybackC
|
|||||||
const { playMode, playModeIcon, togglePlayMode } = usePlayMode();
|
const { playMode, playModeIcon, togglePlayMode } = usePlayMode();
|
||||||
|
|
||||||
// 音量控制(统一通过 playerStore 管理)
|
// 音量控制(统一通过 playerStore 管理)
|
||||||
const {
|
const { volumeSlider, volumeIcon: getVolumeIcon, mute, handleVolumeWheel } = useVolumeControl();
|
||||||
isMuted,
|
|
||||||
volumeSlider,
|
|
||||||
volumeIcon: getVolumeIcon,
|
|
||||||
mute,
|
|
||||||
handleVolumeWheel
|
|
||||||
} = useVolumeControl();
|
|
||||||
|
|
||||||
// 进度条控制
|
// 进度条控制
|
||||||
const isDragging = ref(false);
|
const isDragging = ref(false);
|
||||||
|
|||||||
+99
-118
@@ -52,11 +52,6 @@ export const textColors = ref<any>(getTextColors());
|
|||||||
export let playMusic: ComputedRef<SongResult>;
|
export let playMusic: ComputedRef<SongResult>;
|
||||||
export let artistList: ComputedRef<Artist[]>;
|
export let artistList: ComputedRef<Artist[]>;
|
||||||
|
|
||||||
let lastIndex = -1;
|
|
||||||
|
|
||||||
// 缓存平台信息,避免每次歌词变化时同步 IPC 调用
|
|
||||||
const cachedPlatform = isElectron ? window.electron.ipcRenderer.sendSync('get-platform') : 'web';
|
|
||||||
|
|
||||||
export const musicDB = await useIndexedDB(
|
export const musicDB = await useIndexedDB(
|
||||||
'musicDB',
|
'musicDB',
|
||||||
[
|
[
|
||||||
@@ -149,21 +144,37 @@ const parseLyricsString = async (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 解析当前 playMusic.lyric 写入 lrcArray, 供 watcher / openLyric / onLyricWindowReady 共用
|
// 设置音乐相关的监听器
|
||||||
const ensureLyricsLoaded = async (force = false) => {
|
const setupMusicWatchers = () => {
|
||||||
const songId = playMusic.value?.id;
|
const store = getPlayerStore();
|
||||||
if (!songId) {
|
|
||||||
|
// 监听 playerStore.playMusic 的变化以更新歌词数据
|
||||||
|
watch(
|
||||||
|
() => store.playMusic.id,
|
||||||
|
async (newId, oldId) => {
|
||||||
|
// 如果没有歌曲ID,清空歌词
|
||||||
|
if (!newId) {
|
||||||
lrcArray.value = [];
|
lrcArray.value = [];
|
||||||
lrcTimeArray.value = [];
|
lrcTimeArray.value = [];
|
||||||
nowIndex.value = 0;
|
nowIndex.value = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!force && lrcArray.value.length > 0) return;
|
|
||||||
|
|
||||||
await nextTick();
|
// 避免相同ID的重复执行(但允许初始化时执行)
|
||||||
|
if (newId === oldId && lrcArray.value.length > 0) return;
|
||||||
|
|
||||||
|
// 歌曲切换时重置歌词索引
|
||||||
|
if (newId !== oldId) {
|
||||||
|
nowIndex.value = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
await nextTick(async () => {
|
||||||
|
console.log('歌曲切换,更新歌词数据');
|
||||||
|
|
||||||
|
// 检查是否有原始歌词字符串需要解析
|
||||||
const lyricData = playMusic.value.lyric;
|
const lyricData = playMusic.value.lyric;
|
||||||
if (lyricData && typeof lyricData === 'string') {
|
if (lyricData && typeof lyricData === 'string') {
|
||||||
|
// 如果歌词是字符串格式,使用新的解析器
|
||||||
const {
|
const {
|
||||||
lrcArray: parsedLrcArray,
|
lrcArray: parsedLrcArray,
|
||||||
lrcTimeArray: parsedTimeArray,
|
lrcTimeArray: parsedTimeArray,
|
||||||
@@ -172,10 +183,12 @@ const ensureLyricsLoaded = async (force = false) => {
|
|||||||
lrcArray.value = parsedLrcArray;
|
lrcArray.value = parsedLrcArray;
|
||||||
lrcTimeArray.value = parsedTimeArray;
|
lrcTimeArray.value = parsedTimeArray;
|
||||||
|
|
||||||
|
// 更新歌曲的歌词数据结构
|
||||||
if (playMusic.value.lyric && typeof playMusic.value.lyric === 'object') {
|
if (playMusic.value.lyric && typeof playMusic.value.lyric === 'object') {
|
||||||
playMusic.value.lyric.hasWordByWord = hasWordByWord;
|
playMusic.value.lyric.hasWordByWord = hasWordByWord;
|
||||||
}
|
}
|
||||||
} else if (lyricData && typeof lyricData === 'object' && lyricData.lrcArray?.length > 0) {
|
} else if (lyricData && typeof lyricData === 'object' && lyricData.lrcArray?.length > 0) {
|
||||||
|
// 使用现有的歌词数据结构
|
||||||
const rawLrc = lyricData.lrcArray || [];
|
const rawLrc = lyricData.lrcArray || [];
|
||||||
lrcTimeArray.value = lyricData.lrcTimeArray || [];
|
lrcTimeArray.value = lyricData.lrcTimeArray || [];
|
||||||
|
|
||||||
@@ -187,8 +200,11 @@ const ensureLyricsLoaded = async (force = false) => {
|
|||||||
lrcArray.value = rawLrc as any;
|
lrcArray.value = rawLrc as any;
|
||||||
}
|
}
|
||||||
} else if (isElectron && playMusic.value.playMusicUrl?.startsWith('local:///')) {
|
} else if (isElectron && playMusic.value.playMusicUrl?.startsWith('local:///')) {
|
||||||
|
// 从下载/本地文件的 ID3/FLAC 元数据中提取嵌入歌词
|
||||||
try {
|
try {
|
||||||
let filePath = decodeURIComponent(playMusic.value.playMusicUrl.replace('local:///', ''));
|
let filePath = decodeURIComponent(
|
||||||
|
playMusic.value.playMusicUrl.replace('local:///', '')
|
||||||
|
);
|
||||||
// 处理 Windows 路径:/C:/... → C:/...
|
// 处理 Windows 路径:/C:/... → C:/...
|
||||||
if (/^\/[a-zA-Z]:\//.test(filePath)) {
|
if (/^\/[a-zA-Z]:\//.test(filePath)) {
|
||||||
filePath = filePath.slice(1);
|
filePath = filePath.slice(1);
|
||||||
@@ -205,14 +221,16 @@ const ensureLyricsLoaded = async (force = false) => {
|
|||||||
if (playMusic.value.lyric && typeof playMusic.value.lyric === 'object') {
|
if (playMusic.value.lyric && typeof playMusic.value.lyric === 'object') {
|
||||||
(playMusic.value.lyric as any).hasWordByWord = hasWordByWord;
|
(playMusic.value.lyric as any).hasWordByWord = hasWordByWord;
|
||||||
}
|
}
|
||||||
} else if (typeof songId === 'number') {
|
} else {
|
||||||
|
// 无嵌入歌词 — 若有数字 ID,尝试 API 兜底
|
||||||
|
const songId = playMusic.value.id;
|
||||||
|
if (songId && typeof songId === 'number') {
|
||||||
try {
|
try {
|
||||||
const { getMusicLrc } = await import('@/api/music');
|
const { getMusicLrc } = await import('@/api/music');
|
||||||
const res = await getMusicLrc(songId);
|
const res = await getMusicLrc(songId);
|
||||||
if (res?.data?.lrc?.lyric) {
|
if (res?.data?.lrc?.lyric) {
|
||||||
const { lrcArray: apiLrcArray, lrcTimeArray: apiTimeArray } = await parseLyricsString(
|
const { lrcArray: apiLrcArray, lrcTimeArray: apiTimeArray } =
|
||||||
res.data.lrc.lyric
|
await parseLyricsString(res.data.lrc.lyric);
|
||||||
);
|
|
||||||
lrcArray.value = apiLrcArray;
|
lrcArray.value = apiLrcArray;
|
||||||
lrcTimeArray.value = apiTimeArray;
|
lrcTimeArray.value = apiTimeArray;
|
||||||
}
|
}
|
||||||
@@ -220,54 +238,30 @@ const ensureLyricsLoaded = async (force = false) => {
|
|||||||
console.error('API lyrics fallback failed:', apiErr);
|
console.error('API lyrics fallback failed:', apiErr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to extract embedded lyrics:', err);
|
console.error('Failed to extract embedded lyrics:', err);
|
||||||
}
|
}
|
||||||
} else if (typeof songId === 'number') {
|
} else {
|
||||||
// 在线歌曲但 lyric 字段尚未加载, 主动调 API 兜底
|
// 无歌词数据
|
||||||
try {
|
lrcArray.value = [];
|
||||||
const { getMusicLrc } = await import('@/api/music');
|
lrcTimeArray.value = [];
|
||||||
const res = await getMusicLrc(songId);
|
|
||||||
if (res?.data?.lrc?.lyric) {
|
|
||||||
const { lrcArray: apiLrcArray, lrcTimeArray: apiTimeArray } = await parseLyricsString(
|
|
||||||
res.data.lrc.lyric
|
|
||||||
);
|
|
||||||
lrcArray.value = apiLrcArray;
|
|
||||||
lrcTimeArray.value = apiTimeArray;
|
|
||||||
}
|
}
|
||||||
} catch (apiErr) {
|
// 当歌词数据更新时,如果歌词窗口打开,则发送数据
|
||||||
console.error('API lyrics fallback failed:', apiErr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isElectron && isLyricWindowOpen.value) {
|
if (isElectron && isLyricWindowOpen.value) {
|
||||||
|
console.log('歌词窗口已打开,同步最新歌词数据');
|
||||||
|
// 不管歌词数组是否为空,都发送最新数据
|
||||||
sendLyricToWin();
|
sendLyricToWin();
|
||||||
setTimeout(() => sendLyricToWin(), 500);
|
|
||||||
|
// 再次延迟发送,确保歌词窗口已完全加载
|
||||||
|
setTimeout(() => {
|
||||||
|
sendLyricToWin();
|
||||||
|
}, 500);
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
|
|
||||||
const setupMusicWatchers = () => {
|
|
||||||
const store = getPlayerStore();
|
|
||||||
|
|
||||||
// 切歌时 id 变化, 强制重新解析
|
|
||||||
watch(
|
|
||||||
() => store.playMusic.id,
|
|
||||||
async (newId, oldId) => {
|
|
||||||
if (newId !== oldId) nowIndex.value = 0;
|
|
||||||
await ensureLyricsLoaded(true);
|
|
||||||
},
|
},
|
||||||
{ immediate: true }
|
{ immediate: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
// 同一首歌但 lyric 字段后到 (重启 + autoPlay 关闭场景)
|
|
||||||
watch(
|
|
||||||
() => playMusic.value?.lyric,
|
|
||||||
() => {
|
|
||||||
if (lrcArray.value.length === 0 && playMusic.value?.id) {
|
|
||||||
ensureLyricsLoaded();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const setupAudioListeners = () => {
|
const setupAudioListeners = () => {
|
||||||
@@ -335,12 +329,6 @@ const setupAudioListeners = () => {
|
|||||||
sendLyricToWin();
|
sendLyricToWin();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isElectron && lrcArray.value[nowIndex.value]) {
|
|
||||||
if (lastIndex !== nowIndex.value) {
|
|
||||||
sendTrayLyric(nowIndex.value);
|
|
||||||
lastIndex = nowIndex.value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// === 逐字歌词行内进度 ===
|
// === 逐字歌词行内进度 ===
|
||||||
const { start, end } = currentLrcTiming.value;
|
const { start, end } = currentLrcTiming.value;
|
||||||
@@ -384,15 +372,6 @@ const setupAudioListeners = () => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// === MPRIS 进度更新(每 ~1 秒)===
|
|
||||||
if (isElectron && lyricThrottleCounter % 20 === 0) {
|
|
||||||
try {
|
|
||||||
window.electron.ipcRenderer.send('mpris-position-update', currentTime);
|
|
||||||
} catch {
|
|
||||||
// 忽略发送失败
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('进度更新 interval 出错:', error);
|
console.error('进度更新 interval 出错:', error);
|
||||||
// 出错时不清除 interval,让下一次 tick 继续尝试
|
// 出错时不清除 interval,让下一次 tick 继续尝试
|
||||||
@@ -441,11 +420,6 @@ const setupAudioListeners = () => {
|
|||||||
if (typeof currentTime === 'number' && !Number.isNaN(currentTime)) {
|
if (typeof currentTime === 'number' && !Number.isNaN(currentTime)) {
|
||||||
nowTime.value = currentTime;
|
nowTime.value = currentTime;
|
||||||
|
|
||||||
// === MPRIS seek 时同步进度 ===
|
|
||||||
if (isElectron) {
|
|
||||||
window.electron.ipcRenderer.send('mpris-position-update', currentTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查是否需要更新歌词
|
// 检查是否需要更新歌词
|
||||||
const newIndex = getLrcIndex(nowTime.value);
|
const newIndex = getLrcIndex(nowTime.value);
|
||||||
if (newIndex !== nowIndex.value) {
|
if (newIndex !== nowIndex.value) {
|
||||||
@@ -487,10 +461,7 @@ const setupAudioListeners = () => {
|
|||||||
if (isElectron) {
|
if (isElectron) {
|
||||||
window.api.sendSong(cloneDeep(getPlayerStore().playMusic));
|
window.api.sendSong(cloneDeep(getPlayerStore().playMusic));
|
||||||
}
|
}
|
||||||
// 兜底: 重启后首次点播放时 lrcArray 仍为空则主动加载
|
// 启动进度更新
|
||||||
if (lrcArray.value.length === 0 && playMusic.value?.id) {
|
|
||||||
ensureLyricsLoaded();
|
|
||||||
}
|
|
||||||
startProgressInterval();
|
startProgressInterval();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -535,12 +506,43 @@ const setupAudioListeners = () => {
|
|||||||
if (getPlayerStore().playMode === 1) {
|
if (getPlayerStore().playMode === 1) {
|
||||||
// 单曲循环模式
|
// 单曲循环模式
|
||||||
replayMusic();
|
replayMusic();
|
||||||
return;
|
} else if (getPlayerStore().isFmPlaying) {
|
||||||
|
// 私人FM模式:自动获取下一首
|
||||||
|
try {
|
||||||
|
const { getPersonalFM } = await import('@/api/home');
|
||||||
|
const res = await getPersonalFM();
|
||||||
|
const songs = res.data?.data;
|
||||||
|
if (Array.isArray(songs) && songs.length > 0) {
|
||||||
|
const song = songs[0];
|
||||||
|
const fmSong = {
|
||||||
|
id: song.id,
|
||||||
|
name: song.name,
|
||||||
|
picUrl: song.al?.picUrl || song.album?.picUrl,
|
||||||
|
ar: song.artists || song.ar,
|
||||||
|
al: song.al || song.album,
|
||||||
|
source: 'netease' as const,
|
||||||
|
song,
|
||||||
|
...song,
|
||||||
|
playLoading: false
|
||||||
|
} as any;
|
||||||
|
const { usePlaylistStore } = await import('@/store/modules/playlist');
|
||||||
|
const playlistStore = usePlaylistStore();
|
||||||
|
playlistStore.setPlayList([fmSong], false, false);
|
||||||
|
getPlayerStore().isFmPlaying = true; // setPlayList 会清除,需重设
|
||||||
|
const { playTrack } = await import('@/services/playbackController');
|
||||||
|
await playTrack(fmSong, true);
|
||||||
|
} else {
|
||||||
|
getPlayerStore().setIsPlay(false);
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
// 其他模式(FM/顺序/列表循环/随机):交给 playlist store 路由
|
console.error('FM自动播放下一首失败:', error);
|
||||||
|
getPlayerStore().setIsPlay(false);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 顺序播放、列表循环、随机播放模式:歌曲自然结束
|
||||||
const { usePlaylistStore } = await import('@/store/modules/playlist');
|
const { usePlaylistStore } = await import('@/store/modules/playlist');
|
||||||
usePlaylistStore().nextPlayOnEnd();
|
usePlaylistStore().nextPlayOnEnd();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
audioService.on('previoustrack', () => {
|
audioService.on('previoustrack', () => {
|
||||||
@@ -805,30 +807,6 @@ export const sendLyricToWin = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 发送歌词到系统托盘歌词(TrayLyric)
|
|
||||||
const sendTrayLyric = (index: number) => {
|
|
||||||
if (!isElectron || cachedPlatform !== 'linux') return;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const lyric = lrcArray.value[index];
|
|
||||||
if (!lyric) return;
|
|
||||||
|
|
||||||
const currentTime = lrcTimeArray.value[index] || 0;
|
|
||||||
const nextTime = lrcTimeArray.value[index + 1] || currentTime + 3;
|
|
||||||
const duration = nextTime - currentTime;
|
|
||||||
|
|
||||||
const lrcObj = JSON.stringify({
|
|
||||||
content: lyric.text || '',
|
|
||||||
time: duration.toFixed(1),
|
|
||||||
sender: 'AlgerMusicPlayer'
|
|
||||||
});
|
|
||||||
|
|
||||||
window.electron.ipcRenderer.send('tray-lyric-update', lrcObj);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('[TrayLyric] Failed to send:', error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// 歌词同步定时器
|
// 歌词同步定时器
|
||||||
let lyricSyncInterval: any = null;
|
let lyricSyncInterval: any = null;
|
||||||
|
|
||||||
@@ -866,20 +844,28 @@ const stopLyricSync = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const openLyric = async () => {
|
// 修改openLyric函数,添加定时同步
|
||||||
|
export const openLyric = () => {
|
||||||
if (!isElectron) return;
|
if (!isElectron) return;
|
||||||
|
|
||||||
|
// 检查是否有播放中的歌曲
|
||||||
if (!playMusic.value || !playMusic.value.id) {
|
if (!playMusic.value || !playMusic.value.id) {
|
||||||
console.log('没有正在播放的歌曲,无法打开歌词窗口');
|
console.log('没有正在播放的歌曲,无法打开歌词窗口');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('Opening lyric window with current song:', playMusic.value?.name);
|
||||||
|
|
||||||
isLyricWindowOpen.value = !isLyricWindowOpen.value;
|
isLyricWindowOpen.value = !isLyricWindowOpen.value;
|
||||||
if (isLyricWindowOpen.value) {
|
if (isLyricWindowOpen.value) {
|
||||||
|
// 立即打开窗口
|
||||||
window.api.openLyric();
|
window.api.openLyric();
|
||||||
|
|
||||||
// 先发"加载中"占位, 防止窗口启动期间显示"无歌词"
|
// 确保有歌词数据,如果没有,则使用默认的"无歌词"提示
|
||||||
if (!lrcArray.value || lrcArray.value.length === 0) {
|
if (!lrcArray.value || lrcArray.value.length === 0) {
|
||||||
|
// 如果当前播放的歌曲有ID但没有歌词,则尝试加载歌词
|
||||||
|
console.log('尝试加载歌词数据...');
|
||||||
|
// 发送默认的"无歌词"数据
|
||||||
const emptyLyricData = {
|
const emptyLyricData = {
|
||||||
type: 'empty',
|
type: 'empty',
|
||||||
nowIndex: 0,
|
nowIndex: 0,
|
||||||
@@ -893,15 +879,12 @@ export const openLyric = async () => {
|
|||||||
playMusic: playMusic.value
|
playMusic: playMusic.value
|
||||||
};
|
};
|
||||||
window.api.sendLyric(JSON.stringify(emptyLyricData));
|
window.api.sendLyric(JSON.stringify(emptyLyricData));
|
||||||
|
|
||||||
// 关键: 主动加载歌词, 不依赖 watcher
|
|
||||||
// (重启场景下 playerCore.playMusic 整体替换可能未触发 lyric watcher)
|
|
||||||
await ensureLyricsLoaded(true);
|
|
||||||
} else {
|
} else {
|
||||||
|
// 发送完整歌词数据
|
||||||
sendLyricToWin();
|
sendLyricToWin();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 延迟重发, 防窗口加载慢丢消息
|
// 延迟重发一次,以防窗口加载略慢
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (isLyricWindowOpen.value) {
|
if (isLyricWindowOpen.value) {
|
||||||
sendLyricToWin();
|
sendLyricToWin();
|
||||||
@@ -1023,13 +1006,11 @@ export const initAudioListeners = async () => {
|
|||||||
window.api.onLyricWindowClosed(() => {
|
window.api.onLyricWindowClosed(() => {
|
||||||
isLyricWindowOpen.value = false;
|
isLyricWindowOpen.value = false;
|
||||||
});
|
});
|
||||||
window.api.onLyricWindowReady(async () => {
|
// 歌词窗口 Vue 加载完成后,发送完整歌词数据
|
||||||
if (!isLyricWindowOpen.value) return;
|
window.api.onLyricWindowReady(() => {
|
||||||
// 窗口加载完成时再兜底加载一次, 防止 openLyric 阶段 lyric 字段尚未到位
|
if (isLyricWindowOpen.value) {
|
||||||
if (lrcArray.value.length === 0 && playMusic.value?.id) {
|
|
||||||
await ensureLyricsLoaded(true);
|
|
||||||
}
|
|
||||||
sendLyricToWin();
|
sendLyricToWin();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,76 +0,0 @@
|
|||||||
import { onBeforeUnmount, ref } from 'vue';
|
|
||||||
|
|
||||||
import { textColors } from '@/hooks/MusicHook';
|
|
||||||
import { animateGradient, getHoverBackgroundColor, getTextColors } from '@/utils/linearColor';
|
|
||||||
|
|
||||||
type UseLyricBackgroundOptions = {
|
|
||||||
/**
|
|
||||||
* 可选:返回需要写入 --bg-color CSS 变量的颜色字符串。
|
|
||||||
* - 不提供:完全不写 --bg-color(桌面全屏场景)
|
|
||||||
* - 提供:有背景分支调用以取值,undefined 时落回 DEFAULT_BG_COLOR;
|
|
||||||
* 空背景分支固定写入 DEFAULT_BG_COLOR(与移动端原有行为一致)
|
|
||||||
*/
|
|
||||||
writeBgColor?: () => string | undefined;
|
|
||||||
};
|
|
||||||
|
|
||||||
const DEFAULT_BG_COLOR = 'rgba(25, 25, 25, 1)';
|
|
||||||
|
|
||||||
export function useLyricBackground(options: UseLyricBackgroundOptions = {}) {
|
|
||||||
const currentBackground = ref('');
|
|
||||||
const animationFrame = ref<number | null>(null);
|
|
||||||
const isDark = ref(false);
|
|
||||||
|
|
||||||
const { writeBgColor } = options;
|
|
||||||
const root = document.documentElement;
|
|
||||||
|
|
||||||
const applyBackground = (background: string) => {
|
|
||||||
if (!background) {
|
|
||||||
textColors.value = getTextColors();
|
|
||||||
root.style.setProperty('--hover-bg-color', getHoverBackgroundColor(false));
|
|
||||||
root.style.setProperty('--text-color-primary', textColors.value.primary);
|
|
||||||
root.style.setProperty('--text-color-active', textColors.value.active);
|
|
||||||
if (writeBgColor) {
|
|
||||||
root.style.setProperty('--bg-color', DEFAULT_BG_COLOR);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
textColors.value = getTextColors(background);
|
|
||||||
isDark.value = textColors.value.active === '#000000';
|
|
||||||
|
|
||||||
root.style.setProperty('--hover-bg-color', getHoverBackgroundColor(isDark.value));
|
|
||||||
root.style.setProperty('--text-color-primary', textColors.value.primary);
|
|
||||||
root.style.setProperty('--text-color-active', textColors.value.active);
|
|
||||||
|
|
||||||
if (writeBgColor) {
|
|
||||||
const bg = writeBgColor();
|
|
||||||
root.style.setProperty('--bg-color', bg || DEFAULT_BG_COLOR);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentBackground.value) {
|
|
||||||
if (animationFrame.value) {
|
|
||||||
cancelAnimationFrame(animationFrame.value);
|
|
||||||
}
|
|
||||||
const result = animateGradient(currentBackground.value, background, (gradient) => {
|
|
||||||
currentBackground.value = gradient;
|
|
||||||
});
|
|
||||||
if (typeof result === 'number') {
|
|
||||||
animationFrame.value = result;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
currentBackground.value = background;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
|
||||||
if (animationFrame.value) {
|
|
||||||
cancelAnimationFrame(animationFrame.value);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
isDark,
|
|
||||||
currentBackground,
|
|
||||||
applyBackground
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -9,10 +9,7 @@ import { usePlayerStore } from '@/store/modules/player';
|
|||||||
export function useVolumeControl() {
|
export function useVolumeControl() {
|
||||||
const playerStore = usePlayerStore();
|
const playerStore = usePlayerStore();
|
||||||
|
|
||||||
/** 是否静音 */
|
/** 音量滑块值 (0-100) */
|
||||||
const isMuted = computed(() => playerStore.isMuted);
|
|
||||||
|
|
||||||
/** 音量滑块值 (0-100),静音时仍展示原始音量 */
|
|
||||||
const volumeSlider = computed({
|
const volumeSlider = computed({
|
||||||
get: () => playerStore.volume * 100,
|
get: () => playerStore.volume * 100,
|
||||||
set: (value: number) => {
|
set: (value: number) => {
|
||||||
@@ -22,17 +19,21 @@ export function useVolumeControl() {
|
|||||||
|
|
||||||
/** 音量图标 class */
|
/** 音量图标 class */
|
||||||
const volumeIcon = computed(() => {
|
const volumeIcon = computed(() => {
|
||||||
if (playerStore.isMuted || playerStore.volume === 0) return 'ri-volume-mute-line';
|
if (playerStore.volume === 0) return 'ri-volume-mute-line';
|
||||||
if (playerStore.volume <= 0.5) return 'ri-volume-down-line';
|
if (playerStore.volume <= 0.5) return 'ri-volume-down-line';
|
||||||
return 'ri-volume-up-line';
|
return 'ri-volume-up-line';
|
||||||
});
|
});
|
||||||
|
|
||||||
/** 切换静音(保留静音前的音量) */
|
/** 静音切换 (0 ↔ 30%) */
|
||||||
const mute = () => {
|
const mute = () => {
|
||||||
playerStore.toggleMute();
|
if (volumeSlider.value === 0) {
|
||||||
|
volumeSlider.value = 30;
|
||||||
|
} else {
|
||||||
|
volumeSlider.value = 0;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 鼠标滚轮调整音量 ±5%;静音时向上滚轮会自动解除静音 */
|
/** 鼠标滚轮调整音量 ±5% */
|
||||||
const handleVolumeWheel = (e: WheelEvent) => {
|
const handleVolumeWheel = (e: WheelEvent) => {
|
||||||
const delta = e.deltaY < 0 ? 5 : -5;
|
const delta = e.deltaY < 0 ? 5 : -5;
|
||||||
const newValue = Math.min(Math.max(volumeSlider.value + delta, 0), 100);
|
const newValue = Math.min(Math.max(volumeSlider.value + delta, 0), 100);
|
||||||
@@ -40,7 +41,6 @@ export function useVolumeControl() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isMuted,
|
|
||||||
volumeSlider,
|
volumeSlider,
|
||||||
volumeIcon,
|
volumeIcon,
|
||||||
mute,
|
mute,
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
|
|
||||||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||||
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
|
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
|
||||||
<link rel="manifest" href="/manifest.json" />
|
|
||||||
|
|
||||||
<!-- 资源预加载 -->
|
<!-- 资源预加载 -->
|
||||||
<link rel="preload" href="./assets/icon/iconfont.css" as="style" />
|
<link rel="preload" href="./assets/icon/iconfont.css" as="style" />
|
||||||
|
|||||||
@@ -605,6 +605,13 @@ class AudioService {
|
|||||||
|
|
||||||
public async getAudioOutputDevices(): Promise<AudioOutputDevice[]> {
|
public async getAudioOutputDevices(): Promise<AudioOutputDevice[]> {
|
||||||
try {
|
try {
|
||||||
|
try {
|
||||||
|
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
||||||
|
stream.getTracks().forEach((track) => track.stop());
|
||||||
|
} catch {
|
||||||
|
// Continue even if permission denied
|
||||||
|
}
|
||||||
|
|
||||||
const devices = await navigator.mediaDevices.enumerateDevices();
|
const devices = await navigator.mediaDevices.enumerateDevices();
|
||||||
const audioOutputs = devices.filter((d) => d.kind === 'audiooutput');
|
const audioOutputs = devices.filter((d) => d.kind === 'audiooutput');
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ export const usePlayerStore = defineStore('player', () => {
|
|||||||
musicFull,
|
musicFull,
|
||||||
playbackRate,
|
playbackRate,
|
||||||
volume,
|
volume,
|
||||||
isMuted,
|
|
||||||
userPlayIntent,
|
userPlayIntent,
|
||||||
isFmPlaying
|
isFmPlaying
|
||||||
} = storeToRefs(playerCore);
|
} = storeToRefs(playerCore);
|
||||||
@@ -98,7 +97,6 @@ export const usePlayerStore = defineStore('player', () => {
|
|||||||
musicFull,
|
musicFull,
|
||||||
playbackRate,
|
playbackRate,
|
||||||
volume,
|
volume,
|
||||||
isMuted,
|
|
||||||
userPlayIntent,
|
userPlayIntent,
|
||||||
isFmPlaying,
|
isFmPlaying,
|
||||||
|
|
||||||
@@ -115,8 +113,6 @@ export const usePlayerStore = defineStore('player', () => {
|
|||||||
getVolume: playerCore.getVolume,
|
getVolume: playerCore.getVolume,
|
||||||
increaseVolume: playerCore.increaseVolume,
|
increaseVolume: playerCore.increaseVolume,
|
||||||
decreaseVolume: playerCore.decreaseVolume,
|
decreaseVolume: playerCore.decreaseVolume,
|
||||||
setMuted: playerCore.setMuted,
|
|
||||||
toggleMute: playerCore.toggleMute,
|
|
||||||
handlePause: playerCore.handlePause,
|
handlePause: playerCore.handlePause,
|
||||||
|
|
||||||
// ========== 播放列表管理 (Playlist) ==========
|
// ========== 播放列表管理 (Playlist) ==========
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ export const usePlayerCoreStore = defineStore(
|
|||||||
const musicFull = ref(false);
|
const musicFull = ref(false);
|
||||||
const playbackRate = ref(1.0);
|
const playbackRate = ref(1.0);
|
||||||
const volume = ref(1);
|
const volume = ref(1);
|
||||||
const isMuted = ref(false);
|
|
||||||
const userPlayIntent = ref(false); // 用户是否想要播放
|
const userPlayIntent = ref(false); // 用户是否想要播放
|
||||||
const isFmPlaying = ref(false); // 是否正在播放私人FM
|
const isFmPlaying = ref(false); // 是否正在播放私人FM
|
||||||
|
|
||||||
@@ -66,27 +65,7 @@ export const usePlayerCoreStore = defineStore(
|
|||||||
const setVolume = (newVolume: number) => {
|
const setVolume = (newVolume: number) => {
|
||||||
const normalizedVolume = Math.max(0, Math.min(1, newVolume));
|
const normalizedVolume = Math.max(0, Math.min(1, newVolume));
|
||||||
volume.value = normalizedVolume;
|
volume.value = normalizedVolume;
|
||||||
// 用户调高音量时自动解除静音
|
audioService.setVolume(normalizedVolume);
|
||||||
if (isMuted.value && normalizedVolume > 0) {
|
|
||||||
isMuted.value = false;
|
|
||||||
}
|
|
||||||
audioService.setVolume(isMuted.value ? 0 : normalizedVolume);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置静音状态(不改变 volume,仅控制音频输出)
|
|
||||||
*/
|
|
||||||
const setMuted = (value: boolean) => {
|
|
||||||
if (isMuted.value === value) return;
|
|
||||||
isMuted.value = value;
|
|
||||||
audioService.setVolume(isMuted.value ? 0 : volume.value);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 切换静音
|
|
||||||
*/
|
|
||||||
const toggleMute = () => {
|
|
||||||
setMuted(!isMuted.value);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -190,7 +169,6 @@ export const usePlayerCoreStore = defineStore(
|
|||||||
musicFull,
|
musicFull,
|
||||||
playbackRate,
|
playbackRate,
|
||||||
volume,
|
volume,
|
||||||
isMuted,
|
|
||||||
userPlayIntent,
|
userPlayIntent,
|
||||||
isFmPlaying,
|
isFmPlaying,
|
||||||
audioOutputDeviceId,
|
audioOutputDeviceId,
|
||||||
@@ -209,8 +187,6 @@ export const usePlayerCoreStore = defineStore(
|
|||||||
getVolume,
|
getVolume,
|
||||||
increaseVolume,
|
increaseVolume,
|
||||||
decreaseVolume,
|
decreaseVolume,
|
||||||
setMuted,
|
|
||||||
toggleMute,
|
|
||||||
handlePause,
|
handlePause,
|
||||||
refreshAudioDevices,
|
refreshAudioDevices,
|
||||||
setAudioOutputDevice,
|
setAudioOutputDevice,
|
||||||
@@ -221,15 +197,7 @@ export const usePlayerCoreStore = defineStore(
|
|||||||
persist: {
|
persist: {
|
||||||
key: 'player-core-store',
|
key: 'player-core-store',
|
||||||
storage: localStorage,
|
storage: localStorage,
|
||||||
pick: [
|
pick: ['playMusic', 'playMusicUrl', 'playbackRate', 'volume', 'isPlay', 'audioOutputDeviceId']
|
||||||
'playMusic',
|
|
||||||
'playMusicUrl',
|
|
||||||
'playbackRate',
|
|
||||||
'volume',
|
|
||||||
'isMuted',
|
|
||||||
'isPlay',
|
|
||||||
'audioOutputDeviceId'
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -424,55 +424,8 @@ export const usePlaylistStore = defineStore(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* 私人FM:拉取下一首并播放(FM 列表始终只保留当前一首)
|
|
||||||
*/
|
|
||||||
const _nextFmPlay = async () => {
|
|
||||||
const playerCore = usePlayerCoreStore();
|
|
||||||
try {
|
|
||||||
const { getPersonalFM } = await import('@/api/home');
|
|
||||||
const res = await getPersonalFM();
|
|
||||||
const songs = res.data?.data;
|
|
||||||
if (!Array.isArray(songs) || songs.length === 0) {
|
|
||||||
playerCore.setIsPlay(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const song = songs[0];
|
|
||||||
const fmSong = {
|
|
||||||
id: song.id,
|
|
||||||
name: song.name,
|
|
||||||
picUrl: song.al?.picUrl || song.album?.picUrl,
|
|
||||||
ar: song.artists || song.ar,
|
|
||||||
al: song.al || song.album,
|
|
||||||
source: 'netease' as const,
|
|
||||||
song,
|
|
||||||
...song,
|
|
||||||
playLoading: false
|
|
||||||
} as any;
|
|
||||||
await setPlayList([fmSong], false, false);
|
|
||||||
playerCore.isFmPlaying = true;
|
|
||||||
const { playTrack } = await import('@/services/playbackController');
|
|
||||||
await playTrack(fmSong, true);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('FM切换下一首失败:', error);
|
|
||||||
playerCore.setIsPlay(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const _nextPlay = async (retryCount: number = 0, autoEnd: boolean = false) => {
|
const _nextPlay = async (retryCount: number = 0, autoEnd: boolean = false) => {
|
||||||
try {
|
try {
|
||||||
const playerCore = usePlayerCoreStore();
|
|
||||||
|
|
||||||
// 私人FM模式:忽略 playMode 与列表长度,直接拉取新的 FM 歌曲
|
|
||||||
if (playerCore.isFmPlaying) {
|
|
||||||
if (retryCount === 0) {
|
|
||||||
cancelRetryTimer();
|
|
||||||
consecutiveFailCount.value = 0;
|
|
||||||
}
|
|
||||||
await _nextFmPlay();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (playList.value.length === 0) return;
|
if (playList.value.length === 0) return;
|
||||||
|
|
||||||
// User-initiated (retryCount=0): reset state
|
// User-initiated (retryCount=0): reset state
|
||||||
@@ -481,6 +434,7 @@ export const usePlaylistStore = defineStore(
|
|||||||
consecutiveFailCount.value = 0;
|
consecutiveFailCount.value = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const playerCore = usePlayerCoreStore();
|
||||||
const sleepTimerStore = useSleepTimerStore();
|
const sleepTimerStore = useSleepTimerStore();
|
||||||
|
|
||||||
if (consecutiveFailCount.value >= MAX_CONSECUTIVE_FAILS) {
|
if (consecutiveFailCount.value >= MAX_CONSECUTIVE_FAILS) {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { onMounted, onUnmounted } from 'vue';
|
import { onMounted, onUnmounted } from 'vue';
|
||||||
|
|
||||||
import i18n from '@/../i18n/renderer';
|
import i18n from '@/../i18n/renderer';
|
||||||
import { audioService } from '@/services/audioService';
|
|
||||||
import { usePlayerStore, useSettingsStore } from '@/store';
|
import { usePlayerStore, useSettingsStore } from '@/store';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -38,26 +37,6 @@ const onUpdateAppShortcuts = (_event: unknown, shortcuts: unknown) => {
|
|||||||
updateAppShortcuts(shortcuts);
|
updateAppShortcuts(shortcuts);
|
||||||
};
|
};
|
||||||
|
|
||||||
const onMprisSeekOrSetPosition = (_event: unknown, position: number) => {
|
|
||||||
if (audioService) {
|
|
||||||
audioService.seek(position);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const onMprisPlay = async () => {
|
|
||||||
const playerStore = usePlayerStore();
|
|
||||||
if (!playerStore.play && playerStore.playMusic?.id) {
|
|
||||||
await playerStore.setPlay({ ...playerStore.playMusic });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const onMprisPause = async () => {
|
|
||||||
const playerStore = usePlayerStore();
|
|
||||||
if (playerStore.play) {
|
|
||||||
await playerStore.handlePause();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
function shouldSkipAction(action: ShortcutAction): boolean {
|
function shouldSkipAction(action: ShortcutAction): boolean {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
const lastTimestamp = actionTimestamps.get(action) ?? 0;
|
const lastTimestamp = actionTimestamps.get(action) ?? 0;
|
||||||
@@ -213,10 +192,6 @@ export function initAppShortcuts() {
|
|||||||
|
|
||||||
window.electron.ipcRenderer.on('global-shortcut', onGlobalShortcut);
|
window.electron.ipcRenderer.on('global-shortcut', onGlobalShortcut);
|
||||||
window.electron.ipcRenderer.on('update-app-shortcuts', onUpdateAppShortcuts);
|
window.electron.ipcRenderer.on('update-app-shortcuts', onUpdateAppShortcuts);
|
||||||
window.electron.ipcRenderer.on('mpris-seek', onMprisSeekOrSetPosition);
|
|
||||||
window.electron.ipcRenderer.on('mpris-set-position', onMprisSeekOrSetPosition);
|
|
||||||
window.electron.ipcRenderer.on('mpris-play', onMprisPlay);
|
|
||||||
window.electron.ipcRenderer.on('mpris-pause', onMprisPause);
|
|
||||||
|
|
||||||
const storedShortcuts = window.electron.ipcRenderer.sendSync('get-store-value', 'shortcuts');
|
const storedShortcuts = window.electron.ipcRenderer.sendSync('get-store-value', 'shortcuts');
|
||||||
updateAppShortcuts(storedShortcuts);
|
updateAppShortcuts(storedShortcuts);
|
||||||
@@ -236,10 +211,6 @@ export function cleanupAppShortcuts() {
|
|||||||
|
|
||||||
window.electron.ipcRenderer.removeListener('global-shortcut', onGlobalShortcut);
|
window.electron.ipcRenderer.removeListener('global-shortcut', onGlobalShortcut);
|
||||||
window.electron.ipcRenderer.removeListener('update-app-shortcuts', onUpdateAppShortcuts);
|
window.electron.ipcRenderer.removeListener('update-app-shortcuts', onUpdateAppShortcuts);
|
||||||
window.electron.ipcRenderer.removeListener('mpris-seek', onMprisSeekOrSetPosition);
|
|
||||||
window.electron.ipcRenderer.removeListener('mpris-set-position', onMprisSeekOrSetPosition);
|
|
||||||
window.electron.ipcRenderer.removeListener('mpris-play', onMprisPlay);
|
|
||||||
window.electron.ipcRenderer.removeListener('mpris-pause', onMprisPause);
|
|
||||||
|
|
||||||
document.removeEventListener('keydown', handleKeyDown);
|
document.removeEventListener('keydown', handleKeyDown);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -915,16 +915,16 @@ const saveDownloadSettings = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const initDownloadSettings = async () => {
|
const initDownloadSettings = async () => {
|
||||||
const path = window.electron.ipcRenderer.sendSync('get-store-value', 'set.downloadPath');
|
const path = await window.electron.ipcRenderer.invoke('get-store-value', 'set.downloadPath');
|
||||||
const nameFormat = window.electron.ipcRenderer.sendSync(
|
const nameFormat = await window.electron.ipcRenderer.invoke(
|
||||||
'get-store-value',
|
'get-store-value',
|
||||||
'set.downloadNameFormat'
|
'set.downloadNameFormat'
|
||||||
);
|
);
|
||||||
const separator = window.electron.ipcRenderer.sendSync(
|
const separator = await window.electron.ipcRenderer.invoke(
|
||||||
'get-store-value',
|
'get-store-value',
|
||||||
'set.downloadSeparator'
|
'set.downloadSeparator'
|
||||||
);
|
);
|
||||||
const saveLyric = window.electron.ipcRenderer.sendSync(
|
const saveLyric = await window.electron.ipcRenderer.invoke(
|
||||||
'get-store-value',
|
'get-store-value',
|
||||||
'set.downloadSaveLyric'
|
'set.downloadSaveLyric'
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -341,7 +341,6 @@ const displayMode = computed(() => lyricSetting.value.displayMode);
|
|||||||
const showTranslation = computed(() => lyricSetting.value.showTranslation);
|
const showTranslation = computed(() => lyricSetting.value.showTranslation);
|
||||||
|
|
||||||
let hideControlsTimer: number | null = null;
|
let hideControlsTimer: number | null = null;
|
||||||
let removeMousePresenceListener: (() => void) | null = null;
|
|
||||||
|
|
||||||
const isHovering = ref(false);
|
const isHovering = ref(false);
|
||||||
|
|
||||||
@@ -401,7 +400,6 @@ watch(
|
|||||||
// 锁定时自动关闭主题色面板
|
// 锁定时自动关闭主题色面板
|
||||||
showThemeColorPanel.value = false;
|
showThemeColorPanel.value = false;
|
||||||
}
|
}
|
||||||
windowData.electron.ipcRenderer.send('set-lyric-lock-state', newLock);
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -784,27 +782,10 @@ onMounted(() => {
|
|||||||
|
|
||||||
// 通知主窗口歌词窗口已就绪,请求发送完整歌词数据
|
// 通知主窗口歌词窗口已就绪,请求发送完整歌词数据
|
||||||
windowData.electron.ipcRenderer.send('lyric-ready');
|
windowData.electron.ipcRenderer.send('lyric-ready');
|
||||||
|
|
||||||
removeMousePresenceListener = window.ipcRenderer.on(
|
|
||||||
'lyric-mouse-presence',
|
|
||||||
(isInside: boolean) => {
|
|
||||||
isHovering.value = isInside;
|
|
||||||
|
|
||||||
if (lyricSetting.value.isLock) {
|
|
||||||
windowData.electron.ipcRenderer.send('set-ignore-mouse', !isInside);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
windowData.electron.ipcRenderer.send('set-lyric-lock-state', lyricSetting.value.isLock);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
window.removeEventListener('resize', updateContainerHeight);
|
window.removeEventListener('resize', updateContainerHeight);
|
||||||
if (removeMousePresenceListener) {
|
|
||||||
removeMousePresenceListener();
|
|
||||||
removeMousePresenceListener = null;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const checkTheme = () => {
|
const checkTheme = () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user