@@ -38,8 +38,11 @@ let themeRegWatcher: RegistryWatcher | null = null;
3838let uiaWatcher : UiaWatcher | null = null ;
3939let trayWatcher : TrayWatcher | null = null ;
4040
41- /** 传给 Rust 的 lyric_width:Win10 据此从 tasklist 划空间,Win11 忽略 */
42- const currentWidth = 300 ;
41+ /** 从设置读取当前歌词宽度(Win10 据此从 tasklist 划空间,Win11 忽略) */
42+ const resolveLyricWidth = ( ) : number => {
43+ const width = store . get ( "taskbarLyric.maxWidth" ) ;
44+ return typeof width === "number" && width > 0 ? width : 400 ;
45+ } ;
4346
4447/**
4548 * 初始窗口尺寸——故意设大,覆盖任何可能的任务栏宽度/高度。
@@ -120,7 +123,7 @@ const applyLayout = (layout: JsTaskbarLayout): void => {
120123
121124/** Watcher 回调——任何任务栏相关变化都回到这里重算布局 */
122125const onLayoutChange = ( ) : void => {
123- service ?. update ( currentWidth ) ;
126+ service ?. update ( resolveLyricWidth ( ) ) ;
124127} ;
125128
126129/** 安全创建原生 watcher,失败只 warn 不中断启动 */
@@ -198,7 +201,7 @@ export const createTaskbarLyricWindow = (): BrowserWindow | null => {
198201 const hwndPtr = Number ( win . getNativeWindowHandle ( ) . readBigUInt64LE ( 0 ) ) ;
199202 taskbarLog . info ( `嵌入窗口 hwnd=${ hwndPtr } ` ) ;
200203 svc . embedWindowByPtr ( hwndPtr ) ;
201- svc . update ( currentWidth ) ;
204+ svc . update ( resolveLyricWidth ( ) ) ;
202205
203206 advancedRegWatcher = tryStart (
204207 "RegistryWatcher(Advanced)" ,
@@ -239,27 +242,24 @@ const cleanupWatchers = (): void => {
239242 service = null ;
240243} ;
241244
242- /** 关闭任务栏歌词窗口并清理所有资源 */
245+ /** 请求关闭任务栏歌词窗口,实际清理由 "closed" 事件统一处理 */
243246export const closeTaskbarLyricWindow = ( ) : void => {
244247 if ( taskbarLyricWindow && ! taskbarLyricWindow . isDestroyed ( ) ) {
245248 taskbarLyricWindow . close ( ) ;
246249 }
247- taskbarLyricWindow = null ;
248- cleanupWatchers ( ) ;
249- setTrayTaskbarLyric ( false ) ;
250- broadcast ( "taskbarLyric:visibilityChange" , false ) ;
251250} ;
252251
253- /** 切换任务栏歌词窗口显隐 */
254- export const toggleTaskbarLyricWindow = ( ) : void => {
252+ /** 切换任务栏歌词窗口显隐,返回切换后是否打开 */
253+ export const toggleTaskbarLyricWindow = ( ) : boolean => {
255254 if ( taskbarLyricWindow && ! taskbarLyricWindow . isDestroyed ( ) ) {
256255 closeTaskbarLyricWindow ( ) ;
257- } else {
258- createTaskbarLyricWindow ( ) ;
256+ return false ;
259257 }
258+ createTaskbarLyricWindow ( ) ;
259+ return true ;
260260} ;
261261
262- /** 触发一次布局重算 */
262+ /** 触发一次布局重算(配置变更后调用) */
263263export const applyTaskbarLyricLayout = ( ) : void => {
264- service ?. update ( currentWidth ) ;
264+ service ?. update ( resolveLyricWidth ( ) ) ;
265265} ;
0 commit comments