@@ -164,13 +164,20 @@ const dragState = reactive({
164164const lyricDragStart = async (_position : Position , event : PointerEvent ) => {
165165 if (lyricConfig .isLock ) return ;
166166 dragState .isDragging = true ;
167- const { x, y, width, height } = await window .electron .ipcRenderer .invoke (" get-window-bounds" );
167+ const { x, y } = await window .electron .ipcRenderer .invoke (" get-window-bounds" );
168+ const { width, height } = await window .api .store .get (" lyric" );
169+ // 直接限制最大宽高
170+ window .electron .ipcRenderer .send (" toggle-fixed-max-size" , {
171+ width ,
172+ height ,
173+ fixed: true ,
174+ });
168175 dragState .startX = event ?.screenX ?? 0 ;
169176 dragState .startY = event ?.screenY ?? 0 ;
170177 dragState .startWinX = x ;
171178 dragState .startWinY = y ;
172- dragState .winWidth = width ;
173- dragState .winHeight = height ;
179+ dragState .winWidth = width ?? 0 ;
180+ dragState .winHeight = height ?? 0 ;
174181};
175182
176183/**
@@ -209,17 +216,26 @@ useDraggable(desktopLyricRef, {
209216 onMove : (position , event ) => {
210217 lyricDragMove (position , event );
211218 },
212- onEnd : async () => {
213- const { width, height } = await window .electron .ipcRenderer .invoke (" get-window-bounds" );
214- // 若不等于初始宽高
215- if (width !== dragState .winWidth || height !== dragState .winHeight ) {
219+ onEnd : () => {
220+ // 关闭拖拽状态
221+ dragState .isDragging = false ;
222+ requestAnimationFrame (() => {
223+ // 恢复拖拽前宽高
216224 window .electron .ipcRenderer .send (
217225 " update-lyric-size" ,
218226 dragState .winWidth ,
219227 dragState .winHeight ,
220228 );
221- }
222- dragState .isDragging = false ;
229+ // 根据字体大小恢复一次高度
230+ const height = fontSizeToHeight (lyricConfig .fontSize );
231+ if (height ) pushWindowHeight (height );
232+ // 恢复最大宽高
233+ window .electron .ipcRenderer .send (" toggle-fixed-max-size" , {
234+ width: dragState .winWidth ,
235+ height: dragState .winHeight ,
236+ fixed: false ,
237+ });
238+ });
223239 },
224240});
225241
@@ -247,6 +263,7 @@ watch(
247263 computedFontSize ,
248264 (size ) => {
249265 if (! Number .isFinite (size )) return ;
266+ if (dragState .isDragging ) return ;
250267 if (size === lyricConfig .fontSize ) return ;
251268 const next = { fontSize: size };
252269 window .electron .ipcRenderer .send (" update-desktop-lyric-option" , next , true );
@@ -272,6 +289,7 @@ const fontSizeToHeight = (size: number) => {
272289// 防抖推送窗口高度更新,避免频繁抖动
273290const pushWindowHeight = useDebounceFn ((nextHeight : number ) => {
274291 if (! Number .isFinite (nextHeight )) return ;
292+ if (dragState .isDragging ) return ;
275293 window .electron .ipcRenderer .send (" update-window-height" , nextHeight );
276294}, 100 );
277295
@@ -302,6 +320,9 @@ onMounted(() => {
302320 });
303321 window .electron .ipcRenderer .on (" update-desktop-lyric-option" , (_event , config : LyricConfig ) => {
304322 Object .assign (lyricConfig , config );
323+ // 根据文字大小改变一次高度
324+ const height = fontSizeToHeight (config .fontSize );
325+ if (height ) pushWindowHeight (height );
305326 });
306327 // 请求歌词数据及配置
307328 window .electron .ipcRenderer .send (" request-desktop-lyric-data" );
0 commit comments