@@ -102,10 +102,11 @@ function createMenuTemplate(win) {
102102// 添加左键支持
103103// 2022.05.17
104104class YPMTrayLinuxImpl {
105- constructor ( tray , win , emitter ) {
105+ constructor ( tray , win , emitter , store ) {
106106 this . tray = tray ;
107107 this . win = win ;
108108 this . emitter = emitter ;
109+ this . store = store ;
109110 this . template = undefined ;
110111 this . initTemplate ( ) ;
111112 this . contextMenu = Menu . buildFromTemplate ( this . template ) ;
@@ -146,14 +147,37 @@ class YPMTrayLinuxImpl {
146147 this . contextMenu . getMenuItemById ( 'unlike' ) . visible = isLiked ;
147148 this . tray . setContextMenu ( this . contextMenu ) ;
148149 } ) ;
150+ this . emitter . on ( 'updateIcon' , ( ) => {
151+ this . updateIcon ( ) ;
152+ } ) ;
153+ }
154+
155+ updateIcon ( ) {
156+ let trayIconSetting = this . store . get ( 'settings.trayIconTheme' ) || 'auto' ;
157+ let iconTheme ;
158+ if ( trayIconSetting === 'auto' ) {
159+ iconTheme = nativeTheme . shouldUseDarkColors ? 'light' : 'dark' ;
160+ } else {
161+ iconTheme = trayIconSetting ;
162+ }
163+
164+ let icon = nativeImage
165+ . createFromPath ( path . join ( __static , `img/icons/menu-${ iconTheme } @88.png` ) )
166+ . resize ( {
167+ height : 20 ,
168+ width : 20 ,
169+ } ) ;
170+
171+ this . tray . setImage ( icon ) ;
149172 }
150173}
151174
152175class YPMTrayWindowsImpl {
153- constructor ( tray , win , emitter ) {
176+ constructor ( tray , win , emitter , store ) {
154177 this . tray = tray ;
155178 this . win = win ;
156179 this . emitter = emitter ;
180+ this . store = store ;
157181 this . template = createMenuTemplate ( win ) ;
158182 this . contextMenu = Menu . buildFromTemplate ( this . template ) ;
159183
@@ -193,12 +217,39 @@ class YPMTrayWindowsImpl {
193217 isPlaying => ( this . isPlaying = isPlaying )
194218 ) ;
195219 this . emitter . on ( 'updateLikeState' , isLiked => ( this . isLiked = isLiked ) ) ;
220+ this . emitter . on ( 'updateIcon' , ( ) => {
221+ this . updateIcon ( ) ;
222+ } ) ;
223+ }
224+
225+ updateIcon ( ) {
226+ let trayIconSetting = this . store . get ( 'settings.trayIconTheme' ) || 'auto' ;
227+ let iconTheme ;
228+ if ( trayIconSetting === 'auto' ) {
229+ iconTheme = nativeTheme . shouldUseDarkColors ? 'light' : 'dark' ;
230+ } else {
231+ iconTheme = trayIconSetting ;
232+ }
233+
234+ let icon = nativeImage
235+ . createFromPath ( path . join ( __static , `img/icons/menu-${ iconTheme } @88.png` ) )
236+ . resize ( {
237+ height : 20 ,
238+ width : 20 ,
239+ } ) ;
240+
241+ this . tray . setImage ( icon ) ;
196242 }
197243}
198244
199- export function createTray ( win , eventEmitter ) {
200- // 感觉图标颜色应该不属于界面主题范畴,只需要跟随系统主题
201- let iconTheme = nativeTheme . shouldUseDarkColors ? 'light' : 'dark' ;
245+ export function createTray ( win , eventEmitter , store ) {
246+ let trayIconSetting = store . get ( 'settings.trayIconTheme' ) || 'auto' ;
247+ let iconTheme ;
248+ if ( trayIconSetting === 'auto' ) {
249+ iconTheme = nativeTheme . shouldUseDarkColors ? 'light' : 'dark' ;
250+ } else {
251+ iconTheme = trayIconSetting ;
252+ }
202253
203254 let icon = nativeImage
204255 . createFromPath ( path . join ( __static , `img/icons/menu-${ iconTheme } @88.png` ) )
@@ -211,6 +262,6 @@ export function createTray(win, eventEmitter) {
211262 tray . setToolTip ( 'YesPlayMusic' ) ;
212263
213264 return isLinux
214- ? new YPMTrayLinuxImpl ( tray , win , eventEmitter )
215- : new YPMTrayWindowsImpl ( tray , win , eventEmitter ) ;
265+ ? new YPMTrayLinuxImpl ( tray , win , eventEmitter , store )
266+ : new YPMTrayWindowsImpl ( tray , win , eventEmitter , store ) ;
216267}
0 commit comments