mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-04-25 08:47:22 +08:00
feat: 优化 tray 标题长度
This commit is contained in:
@@ -30,6 +30,8 @@ resources/android/**/*
|
|||||||
android/app/release
|
android/app/release
|
||||||
|
|
||||||
.cursor
|
.cursor
|
||||||
|
.windsurf
|
||||||
|
|
||||||
|
|
||||||
.auto-imports.d.ts
|
.auto-imports.d.ts
|
||||||
.components.d.ts
|
.components.d.ts
|
||||||
|
|||||||
@@ -59,6 +59,13 @@ function getSongTitle(song: SongInfo | null): string {
|
|||||||
return artistStr ? `${song.name} - ${artistStr}` : song.name;
|
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) {
|
export function updateCurrentSong(song: SongInfo | null) {
|
||||||
currentSong = song;
|
currentSong = song;
|
||||||
@@ -143,7 +150,7 @@ export function updateTrayMenu(mainWindow: BrowserWindow) {
|
|||||||
if (currentSong) {
|
if (currentSong) {
|
||||||
menu.append(
|
menu.append(
|
||||||
new MenuItem({
|
new MenuItem({
|
||||||
label: getSongTitle(currentSong),
|
label: getTruncatedSongTitle(currentSong),
|
||||||
enabled: false,
|
enabled: false,
|
||||||
type: 'normal'
|
type: 'normal'
|
||||||
})
|
})
|
||||||
@@ -250,7 +257,7 @@ export function updateTrayMenu(mainWindow: BrowserWindow) {
|
|||||||
...((currentSong
|
...((currentSong
|
||||||
? [
|
? [
|
||||||
{
|
{
|
||||||
label: getSongTitle(currentSong),
|
label: getTruncatedSongTitle(currentSong),
|
||||||
enabled: false,
|
enabled: false,
|
||||||
type: 'normal'
|
type: 'normal'
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user