feat: 实现托盘菜单 (#1538)

* 从 v1 添加托盘相关图标

* feat: ipcRenderer事件

* feat: 托盘菜单实现

* 修复合并后的错误

* fix: 托盘图标的like

* 将 tray 相关的 ipc 放入ipcMain.ts

* update

* update

* feat: 设置托盘Tooltip

* fix

* fix: tray play/pause fade

* fix: 暂时将tray like与tooltip的设置移入Player组件中

useUserLikedTracksIDs 会在重新聚焦而不是切换track时触发,导致托盘无法实时更新数据

基于以上一点,在Player组件中有了一个用于设置tray数据的useEffect,故将tray tooltip的设置也放入其中,使tray的数据尽可能简单的和player数据保持一致

* 将部分ipcRenderer调用挪到单独的IpcRendererReact组件

* 移除SetTrayPlayState,复用已有channel

* update
This commit is contained in:
memorydream 2022-04-20 20:25:20 +08:00 committed by GitHub
parent b1fd51233a
commit ffdf66b57e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 392 additions and 19 deletions

View file

@ -1,4 +1,5 @@
import { APIs } from './CacheAPIs'
import { RepeatMode } from './playerDataTypes'
export const enum IpcChannels {
ClearAPICache = 'clear-api-cache',
@ -9,8 +10,19 @@ export const enum IpcChannels {
GetApiCacheSync = 'get-api-cache-sync',
DevDbExportJson = 'dev-db-export-json',
CacheCoverColor = 'cache-cover-color',
SetTrayTooltip = 'set-tray-tooltip',
SetTrayLikeState = 'set-tray-like-state',
// 准备三个播放相关channel, 为 mpris 预留接口
Play = 'play',
Pause = 'pause',
PlayOrPause = 'play-or-pause',
Next = 'next',
Previous = 'previous',
Like = 'like',
Repeat = 'repeat',
}
// ipcMain.on params
export interface IpcChannelsParams {
[IpcChannels.ClearAPICache]: void
[IpcChannels.Minimize]: void
@ -26,8 +38,26 @@ export interface IpcChannelsParams {
id: number
color: string
}
[IpcChannels.SetTrayTooltip]: {
text: string
}
[IpcChannels.SetTrayLikeState]: {
isLiked: boolean
}
[IpcChannels.Play]: void
[IpcChannels.Pause]: void
[IpcChannels.PlayOrPause]: void
[IpcChannels.Next]: void
[IpcChannels.Previous]: void
[IpcChannels.Like]: {
isLiked: boolean
}
[IpcChannels.Repeat]: {
mode: RepeatMode
}
}
// ipcRenderer.on params
export interface IpcChannelsReturns {
[IpcChannels.ClearAPICache]: void
[IpcChannels.Minimize]: void
@ -37,4 +67,13 @@ export interface IpcChannelsReturns {
[IpcChannels.GetApiCacheSync]: any
[IpcChannels.DevDbExportJson]: void
[IpcChannels.CacheCoverColor]: void
[IpcChannels.SetTrayTooltip]: void
[IpcChannels.SetTrayLikeState]: void
[IpcChannels.Play]: void
[IpcChannels.Pause]: void
[IpcChannels.PlayOrPause]: void
[IpcChannels.Next]: void
[IpcChannels.Previous]: void
[IpcChannels.Like]: void
[IpcChannels.Repeat]: RepeatMode
}