Skip to content

fix: 每次刷新 shell 浏览器列表,修复首次右键位置错误 - #400

Open
ybhgl wants to merge 1 commit into
std-microblock:masterfrom
ybhgl:fix/stale-shell-browser-cache
Open

ybhgl wants to merge 1 commit into
std-microblock:masterfrom
ybhgl:fix/stale-shell-browser-cache

Conversation

@ybhgl

@ybhgl ybhgl commented Nov 13, 2026

Copy link
Copy Markdown

概述

  • GetIShellBrowserRecursive 每次调用都新鲜枚举 shell 窗口,不再用 static
    缓存。
  • 修复新开资源管理器窗口后首次右键被识别成桌面或上一个位置的问题。

原因

  • static auto browsers = GetIShellBrowsers() 只初始化一次;仅当 DFS 完全失败
    时才重新扫描。
  • 随着资源管理器窗口开/关、HWND 被回收复用,缓存里过期的 IShellBrowser 会
    匹配到错误窗口,导致插件读到桌面/上一个位置,要第二次右键才正确。
  • 日志佐证:某文件夹窗口首次右键落到桌面浏览器,第二次右键才匹配到正确浏览器。

改动

  • 去掉 static,让 browsers 每次调用都从 IShellWindows 重新构建。

验证

  • 新开资源管理器 → 进入目录 → 首次右键即报告正确位置。
  • 桌面右键仍正常;日志中无 Failed to get IShellBrowser 兜底。
  • 无性能回升:GetIShellBrowserRecursive ~4-9ms,menu_render::create
    ~40-45ms。

`GetIShellBrowserRecursive` 原先用 `static` 缓存 `GetIShellBrowsers()`,
只在 DFS 完全失败时重扫。资源管理器窗口开关、HWND 回收复用会让缓存匹配到
错误窗口,首次右键读到桌面/上一个位置。改为每次调用新鲜枚举。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant