feat: 优化 tray 标题长度

This commit is contained in:
alger
2025-11-08 17:37:27 +08:00
parent 452e1d1129
commit 56adac0d4e
2 changed files with 11 additions and 2 deletions

2
.gitignore vendored
View File

@@ -30,6 +30,8 @@ resources/android/**/*
android/app/release
.cursor
.windsurf
.auto-imports.d.ts
.components.d.ts

View File

@@ -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'
},