fix: 修复任务栏歌词窗口偶尔漂移到屏幕顶部 - #261
Open
abkkkbb wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
改动类型
是否包含破坏性变更
是(请在「改动说明」中详细描述)
否
是(请在「改动说明」中详细描述)
否
改动说明
修复任务栏歌词窗口偶尔「漂到屏幕顶部」并永久停在那里的问题。
现象:开启任务栏歌词后,歌词窗口偶尔会出现在屏幕顶部(水平位置与宽高仍是任务栏空余区域那组值),且不会再回到任务栏,只有把「任务栏歌词」开关关开一次才恢复。
根因:歌词窗口靠
SetParent嵌入任务栏,其位置坐标是「相对任务栏」的——原生侧返回的布局矩形里y恒为 0(即任务栏顶边),applyLayout原样交给win.setBounds()。父关系一旦被外部解除(例如SetParent(hwnd, NULL)),同一组数字会被按屏幕坐标解释,窗口就精确落在屏幕顶部;而此后每次布局仍然传y=0,等于反复把它按在顶部,因此不会自行恢复。原实现只在窗口
ready-to-show时嵌入一次,之后没有任何地方校验「窗口是否还挂在任务栏上」,所以一旦失效就是永久的。改动:
native/taskbar-lyric/src/lib.rs:新增probeWindow(hwndPtr) -> { alive, embedded }——用IsWindow判断句柄是否仍有效,用GetAncestor(GA_PARENT)与当前 explorer 的Shell_TrayWnd比对判断是否仍嵌在任务栏上;electron/main/window/taskbarLyric.ts:记住嵌入时的 HWND,每 500ms 校验一次;父关系被解除则「隐藏 → 重新SetParent→ 重放布局(setBounds+setShape)」,HWND 变化时用新句柄重新嵌入;HWND 已失效(explorer 重启)时不对窗口做任何操作;electron/main/window/taskbarLyricEmbed.ts(新增):判定逻辑抽为纯函数并补充单测。范围:不改变窗口样式与嵌入方式、不引入新日志、不处理「窗口被销毁后重建」(explorer 重启后的恢复维持现状)。
关联 Issue
无
测试情况
平台:Windows 11 25H2(内部版本 26200)
pnpm test通过(node 40/40、vitest 57/57)。SetParent(hwnd, NULL),模拟「父关系被外部解除」这一失效场景:rect=(715,816) 570×48,父窗口 =Shell_TrayWnd);pnpm format、pnpm typecheck(node + web)、pnpm lint、cargo test --workspace均通过。复现/验收方法(Windows,普通权限即可)
该问题依赖「窗口父关系被外部解除」这一时机,我也是使用过程偶然发生过几次,靠碰运气很难复现,因此用下面的片段主动制造该场景:找到嵌在任务栏里的歌词窗口,把它从任务栏上摘下来(
SetParent(hwnd, NULL)),即可在修复前稳定复现「跳到屏幕顶部且不再恢复」,修复后应在 1 秒内自愈。截图 / 录屏
自查清单
pnpm format,并确认pnpm typecheck、pnpm lint通过pnpm build:native验证;未手写native/*/index.d.tsdev分支提交