From 56adac0d4eb21efe07176286ba17db4960da047b Mon Sep 17 00:00:00 2001 From: alger Date: Sat, 8 Nov 2025 17:37:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=20tray=20=20?= =?UTF-8?q?=E6=A0=87=E9=A2=98=E9=95=BF=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ src/main/modules/tray.ts | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index abd2a97..666f77d 100644 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,8 @@ resources/android/**/* android/app/release .cursor +.windsurf + .auto-imports.d.ts .components.d.ts diff --git a/src/main/modules/tray.ts b/src/main/modules/tray.ts index 4871f3c..be21578 100644 --- a/src/main/modules/tray.ts +++ b/src/main/modules/tray.ts @@ -59,6 +59,13 @@ function getSongTitle(song: SongInfo | null): string { return artistStr ? `${song.name} - ${artistStr}` : song.name; } +// 截断歌曲标题,防止菜单中显示过长 +function getTruncatedSongTitle(song: SongInfo | null, maxLength: number = 14): string { + const fullTitle = getSongTitle(song); + if (fullTitle.length <= maxLength) return fullTitle; + return fullTitle.slice(0, maxLength) + '...'; +} + // 更新当前播放的音乐信息 export function updateCurrentSong(song: SongInfo | null) { currentSong = song; @@ -143,7 +150,7 @@ export function updateTrayMenu(mainWindow: BrowserWindow) { if (currentSong) { menu.append( new MenuItem({ - label: getSongTitle(currentSong), + label: getTruncatedSongTitle(currentSong), enabled: false, type: 'normal' }) @@ -250,7 +257,7 @@ export function updateTrayMenu(mainWindow: BrowserWindow) { ...((currentSong ? [ { - label: getSongTitle(currentSong), + label: getTruncatedSongTitle(currentSong), enabled: false, type: 'normal' },