@@ -4,19 +4,26 @@ import type EventEmitter from "node:events";
44import { useStore } from "../store" ;
55import { getMainTray } from "../tray" ;
66import mainWindow from "../windows/main-window" ;
7- import taskbarLyricWindow from "../windows /taskbar-lyric-window " ;
7+ import taskbarLyricManager from "../utils /taskbar-lyric-manager " ;
88
99let cachedIsPlaying = false ;
1010
1111const getTaskbarConfig = ( ) : TaskbarConfig => {
1212 const store = useStore ( ) ;
1313 return {
14+ mode : store . get ( "taskbar.mode" , "taskbar" ) ,
1415 maxWidth : store . get ( "taskbar.maxWidth" , 300 ) ,
1516 position : store . get ( "taskbar.position" , "automatic" ) ,
1617 autoShrink : store . get ( "taskbar.autoShrink" , false ) ,
1718 margin : store . get ( "taskbar.margin" , 10 ) ,
1819 minWidth : store . get ( "taskbar.minWidth" , 10 ) ,
1920 enabled : store . get ( "taskbar.enabled" , false ) ,
21+ floatingAlign : store . get ( "taskbar.floatingAlign" , "right" ) ,
22+ floatingAutoWidth : store . get ( "taskbar.floatingAutoWidth" , true ) ,
23+ floatingWidth : store . get ( "taskbar.floatingWidth" , 300 ) ,
24+ floatingHeight : store . get ( "taskbar.floatingHeight" , 48 ) ,
25+ floatingAlwaysOnTop : store . get ( "taskbar.floatingAlwaysOnTop" , false ) ,
26+
2027 showWhenPaused : store . get ( "taskbar.showWhenPaused" , true ) ,
2128 showCover : store . get ( "taskbar.showCover" , true ) ,
2229 themeMode : store . get ( "taskbar.themeMode" , "auto" ) ,
@@ -40,11 +47,11 @@ const updateWindowVisibility = (config: TaskbarConfig) => {
4047
4148 const shouldBeVisible = config . enabled && ( cachedIsPlaying || config . showWhenPaused ) ;
4249
43- taskbarLyricWindow . setVisibility ( shouldBeVisible ) ;
50+ taskbarLyricManager . setVisibility ( shouldBeVisible ) ;
4451} ;
4552
4653const updateWindowLayout = ( animate : boolean = true ) => {
47- taskbarLyricWindow . updateLayout ( animate ) ;
54+ taskbarLyricManager . updateLayout ( animate ) ;
4855} ;
4956
5057const initTaskbarIpc = ( ) => {
@@ -53,10 +60,14 @@ const initTaskbarIpc = () => {
5360
5461 const initialConfig = getTaskbarConfig ( ) ;
5562 if ( initialConfig . enabled ) {
56- taskbarLyricWindow . create ( ) ;
63+ taskbarLyricManager . create ( initialConfig . mode ) ;
5764 updateWindowVisibility ( initialConfig ) ;
5865 }
5966
67+ ipcMain . on ( "taskbar:set-width" , ( _event , width : number ) => {
68+ taskbarLyricManager . setContentWidth ( width ) ;
69+ } ) ;
70+
6071 ipcMain . on (
6172 TASKBAR_IPC_CHANNELS . UPDATE_CONFIG ,
6273 ( _event , partialConfig : Partial < TaskbarConfig > ) => {
@@ -68,30 +79,53 @@ const initTaskbarIpc = () => {
6879
6980 const newConfig = getTaskbarConfig ( ) ;
7081
71- if ( newConfig . enabled && ! oldConfig . enabled ) {
72- taskbarLyricWindow . create ( ) ;
82+ const modeChanged = newConfig . mode !== oldConfig . mode ;
83+
84+ if ( modeChanged ) {
85+ taskbarLyricManager . close ( false ) ;
86+ }
87+
88+ if ( newConfig . enabled && ( ! oldConfig . enabled || modeChanged ) ) {
89+ taskbarLyricManager . create ( newConfig . mode ) ;
7390 }
7491
7592 if (
7693 newConfig . enabled !== oldConfig . enabled ||
77- newConfig . showWhenPaused !== oldConfig . showWhenPaused
94+ newConfig . showWhenPaused !== oldConfig . showWhenPaused ||
95+ modeChanged
7896 ) {
7997 updateWindowVisibility ( newConfig ) ;
8098 }
8199
82100 if ( newConfig . enabled ) {
83- if (
84- newConfig . maxWidth !== oldConfig . maxWidth ||
85- newConfig . position !== oldConfig . position ||
86- newConfig . autoShrink !== oldConfig . autoShrink ||
87- newConfig . margin !== oldConfig . margin ||
88- newConfig . minWidth !== oldConfig . minWidth
89- ) {
90- updateWindowLayout ( true ) ;
101+ if ( newConfig . mode === "taskbar" ) {
102+ if (
103+ newConfig . maxWidth !== oldConfig . maxWidth ||
104+ newConfig . position !== oldConfig . position ||
105+ newConfig . autoShrink !== oldConfig . autoShrink ||
106+ newConfig . margin !== oldConfig . margin ||
107+ newConfig . minWidth !== oldConfig . minWidth
108+ ) {
109+ updateWindowLayout ( true ) ;
110+ }
111+ } else {
112+ const floatingWidthChanged =
113+ newConfig . floatingAutoWidth === false && newConfig . floatingWidth !== oldConfig . floatingWidth ;
114+ if (
115+ newConfig . maxWidth !== oldConfig . maxWidth ||
116+ newConfig . floatingAlign !== oldConfig . floatingAlign ||
117+ newConfig . floatingAutoWidth !== oldConfig . floatingAutoWidth ||
118+ floatingWidthChanged ||
119+ newConfig . floatingHeight !== oldConfig . floatingHeight ||
120+ newConfig . floatingAlwaysOnTop !== oldConfig . floatingAlwaysOnTop ||
121+ modeChanged
122+ ) {
123+ updateWindowLayout ( false ) ;
124+ }
91125 }
92126 }
93127
94- taskbarLyricWindow . send ( TASKBAR_IPC_CHANNELS . SYNC_STATE , {
128+ taskbarLyricManager . send ( TASKBAR_IPC_CHANNELS . SYNC_STATE , {
95129 type : "config-update" ,
96130 data : partialConfig ,
97131 } as SyncStatePayload ) ;
@@ -111,11 +145,11 @@ const initTaskbarIpc = () => {
111145 updateWindowVisibility ( getTaskbarConfig ( ) ) ;
112146 }
113147
114- taskbarLyricWindow . send ( TASKBAR_IPC_CHANNELS . SYNC_STATE , payload ) ;
148+ taskbarLyricManager . send ( TASKBAR_IPC_CHANNELS . SYNC_STATE , payload ) ;
115149 } ) ;
116150
117151 ipcMain . on ( TASKBAR_IPC_CHANNELS . SYNC_TICK , ( _event , payload ) => {
118- taskbarLyricWindow . send ( TASKBAR_IPC_CHANNELS . SYNC_TICK , payload ) ;
152+ taskbarLyricManager . send ( TASKBAR_IPC_CHANNELS . SYNC_TICK , payload ) ;
119153 } ) ;
120154
121155 ipcMain . on ( TASKBAR_IPC_CHANNELS . REQUEST_DATA , ( ) => {
@@ -124,27 +158,28 @@ const initTaskbarIpc = () => {
124158 mainWin . webContents . send ( TASKBAR_IPC_CHANNELS . REQUEST_DATA ) ;
125159 }
126160
127- taskbarLyricWindow . updateLayout ( false ) ;
161+ taskbarLyricManager . updateLayout ( false ) ;
128162
129163 const isDark = nativeTheme . shouldUseDarkColors ;
130- taskbarLyricWindow . send ( TASKBAR_IPC_CHANNELS . SYNC_STATE , {
164+ taskbarLyricManager . send ( TASKBAR_IPC_CHANNELS . SYNC_STATE , {
131165 type : "system-theme" ,
132166 data : { isDark } ,
133167 } as SyncStatePayload ) ;
134168 } ) ;
135169
136170 ipcMain . on ( "taskbar:fade-done" , ( ) => {
137- taskbarLyricWindow . handleFadeDone ( ) ;
171+ taskbarLyricManager . handleFadeDone ( ) ;
138172 } ) ;
139173
140174 // 把事件发射到 app 里不太好,但是我觉得也没有必要为了这一个事件创建一个事件总线
141175 // TODO: 如果有了事件总线,通过那个事件总线发射这个事件
142176 ( app as EventEmitter ) . on ( "explorer-restarted" , ( ) => {
143177 const currentEnabled = store . get ( "taskbar.enabled" ) ;
144- if ( currentEnabled ) {
145- taskbarLyricWindow . close ( false ) ;
178+ const currentMode = store . get ( "taskbar.mode" , "taskbar" ) ;
179+ if ( currentEnabled && currentMode === "taskbar" ) {
180+ taskbarLyricManager . close ( false ) ;
146181 setTimeout ( ( ) => {
147- taskbarLyricWindow . create ( ) ;
182+ taskbarLyricManager . create ( "taskbar" ) ;
148183 } , 500 ) ;
149184 }
150185 } ) ;
0 commit comments