@@ -19,12 +19,14 @@ type PlayState = "play" | "pause" | "loading";
19
19
let playMode : PlayMode = "repeat" ;
20
20
let playState : PlayState = "pause" ;
21
21
let playName : string = "未播放歌曲" ;
22
+ let likeSong : boolean = false ;
22
23
let desktopLyricShow : boolean = false ;
23
24
let desktopLyricLock : boolean = false ;
24
25
25
26
export interface MainTray {
26
27
setTitle ( title : string ) : void ;
27
28
setPlayMode ( mode : PlayMode ) : void ;
29
+ setLikeState ( like : boolean ) : void ;
28
30
setPlayState ( state : PlayState ) : void ;
29
31
setPlayName ( name : string ) : void ;
30
32
setDesktopLyricShow ( show : boolean ) : void ;
@@ -34,11 +36,11 @@ export interface MainTray {
34
36
35
37
// 托盘图标
36
38
const trayIcon = ( filename : string ) => {
37
- // const rootPath = isDev
38
- // ? join(__dirname, "../../public/icons/tray")
39
- // : join(app.getAppPath(), "../../public/icons/tray");
40
- // return nativeImage.createFromPath(join(rootPath, filename));
41
- return nativeImage . createFromPath ( join ( __dirname , `../../public/icons/tray/${ filename } ` ) ) ;
39
+ const rootPath = isDev
40
+ ? join ( __dirname , "../../public/icons/tray" )
41
+ : join ( app . getAppPath ( ) , "../../public/icons/tray" ) ;
42
+ return nativeImage . createFromPath ( join ( rootPath , filename ) ) ;
43
+ // return nativeImage.createFromPath(join(__dirname, `../../public/icons/tray/${filename}`));
42
44
} ;
43
45
44
46
// 托盘菜单
@@ -60,7 +62,6 @@ const createTrayMenu = (
60
62
id : "name" ,
61
63
label : playName ,
62
64
icon : showIcon ( "music" ) ,
63
- accelerator : "CmdOrCtrl+Alt+S" ,
64
65
click : ( ) => {
65
66
win . show ( ) ;
66
67
win . focus ( ) ;
@@ -71,19 +72,10 @@ const createTrayMenu = (
71
72
} ,
72
73
{
73
74
id : "toogleLikeSong" ,
74
- label : "添加到我喜欢" ,
75
- icon : showIcon ( "unlike" ) ,
76
- accelerator : "CmdOrCtrl+Alt+L" ,
75
+ label : likeSong ? "从我喜欢中移除" : "添加到我喜欢" ,
76
+ icon : showIcon ( likeSong ? "like" : "unlike" ) ,
77
77
click : ( ) => win . webContents . send ( "toogleLikeSong" ) ,
78
78
} ,
79
- {
80
- id : "unLike" ,
81
- label : "从我喜欢中移除" ,
82
- icon : showIcon ( "like" ) ,
83
- visible : false ,
84
- accelerator : "CmdOrCtrl+Alt+L" ,
85
- click : ( ) => win . webContents . send ( "unlike-song" ) ,
86
- } ,
87
79
{
88
80
id : "changeMode" ,
89
81
label :
@@ -123,21 +115,18 @@ const createTrayMenu = (
123
115
id : "playNext" ,
124
116
label : "上一曲" ,
125
117
icon : showIcon ( "prev" ) ,
126
- accelerator : "CmdOrCtrl+Left" ,
127
118
click : ( ) => win . webContents . send ( "playPrev" ) ,
128
119
} ,
129
120
{
130
121
id : "playOrPause" ,
131
122
label : playState === "pause" ? "播放" : "暂停" ,
132
123
icon : showIcon ( playState === "pause" ? "play" : "pause" ) ,
133
- accelerator : "CmdOrCtrl+Space" ,
134
124
click : ( ) => win . webContents . send ( playState === "pause" ? "play" : "pause" ) ,
135
125
} ,
136
126
{
137
127
id : "playNext" ,
138
128
label : "下一曲" ,
139
129
icon : showIcon ( "next" ) ,
140
- accelerator : "CmdOrCtrl+Right" ,
141
130
click : ( ) => win . webContents . send ( "playNext" ) ,
142
131
} ,
143
132
{
@@ -176,7 +165,6 @@ const createTrayMenu = (
176
165
id : "exit" ,
177
166
label : "退出" ,
178
167
icon : showIcon ( "power" ) ,
179
- accelerator : "CmdOrCtrl+Alt+Q" ,
180
168
click : ( ) => {
181
169
win . close ( ) ;
182
170
// app.exit(0);
@@ -255,6 +243,12 @@ class CreateTray implements MainTray {
255
243
// 更新菜单
256
244
this . initTrayMenu ( ) ;
257
245
}
246
+ // 设置喜欢状态
247
+ setLikeState ( like : boolean ) {
248
+ likeSong = like ;
249
+ // 更新菜单
250
+ this . initTrayMenu ( ) ;
251
+ }
258
252
// 桌面歌词开关
259
253
setDesktopLyricShow ( show : boolean ) {
260
254
desktopLyricShow = show ;
0 commit comments