From b8e993708395b7089691dd2de5a733690c390eac Mon Sep 17 00:00:00 2001 From: lyswhut Date: Mon, 15 Jul 2024 19:42:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=98=E7=9B=98=E5=9B=BE=E6=A0=87=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=BD=93=E5=89=8D=E6=92=AD=E6=94=BE=E6=AD=8C=E6=9B=B2?= =?UTF-8?q?=E5=90=8D=E5=AD=97=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- publish/changeLog.md | 1 + src/main/modules/tray.ts | 29 +++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/publish/changeLog.md b/publish/changeLog.md index db0fe97e..0c23339c 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -5,6 +5,7 @@ ### 优化 - 优化侧栏图标显示,修复图标可能被裁切的问题(#1960) +- 托盘图标添加当前播放歌曲名字显示 ### 修复 diff --git a/src/main/modules/tray.ts b/src/main/modules/tray.ts index f52d2b8e..63a62320 100644 --- a/src/main/modules/tray.ts +++ b/src/main/modules/tray.ts @@ -70,6 +70,8 @@ const messages = { show_statusbar_lyric: 'Show statusbar lyric', hide_statusbar_lyric: 'Hide statusbar lyric', exit: 'Exit', + music_name: 'Name: ', + music_singer: 'Artist: ', }, 'zh-cn': { collect: '收藏', @@ -89,6 +91,8 @@ const messages = { show_statusbar_lyric: '显示状态栏歌词', hide_statusbar_lyric: '隐藏状态栏歌词', exit: '退出', + music_name: '歌曲名: ', + music_singer: '艺术家: ', }, 'zh-tw': { collect: '收藏', @@ -108,6 +112,8 @@ const messages = { show_statusbar_lyric: '顯示狀態列歌詞', hide_statusbar_lyric: '隱藏狀態列歌詞', exit: '退出', + music_name: '歌曲名: ', + music_singer: '藝術家: ', }, } as const type Messages = typeof messages @@ -137,8 +143,8 @@ export const createTray = () => { // 托盘 tray = new Tray(nativeImage.createFromPath(getIconPath(global.lx.appSetting['tray.themeId']))) - tray.setToolTip('LX Music') - createMenu() + // tray.setToolTip('LX Music') + // createMenu() tray.setIgnoreDoubleClickEvents(true) tray.on('click', () => { showMainWindow() @@ -294,6 +300,22 @@ const setLyric = (lyricLineText?: string) => { } } +const defaultTip = 'LX Music' +const setTip = () => { + if (!tray) return + + let name = global.lx.player_status.name + let tip: string + if (name) { + if (name.length > 20) name = name.substring(0, 20) + '...' + let singer = global.lx.player_status.singer + if (singer?.length > 20) singer = singer.substring(0, 20) + '...' + + tip = `${defaultTip}\n${i18n.getMessage('music_name')}${name}${singer ? `\n${i18n.getMessage('music_singer')}${singer}` : ''}` + } else tip = defaultTip + tray.setToolTip(tip) +} + const init = () => { if (themeId != global.lx.appSetting['tray.themeId']) { themeId = global.lx.appSetting['tray.themeId'] @@ -311,6 +333,7 @@ const init = () => { tray?.setTitle('') } } + setTip() createMenu() } @@ -378,6 +401,8 @@ export default () => { } else { setLyric(status.lyricLineText) } + if (status.name != null) setTip() + if (status.singer != null) setTip() if (status.collect != null) { playerState.collect = status.collect updated = true