Skip to content

fix(desktop): 拖动窗口图标时不再崩溃 (#3573)#3616

Merged
esengine merged 1 commit into
esengine:main-v2from
Li-Charles-One:fix/3573-drag-icon-error
Jun 9, 2026
Merged

fix(desktop): 拖动窗口图标时不再崩溃 (#3573)#3616
esengine merged 1 commit into
esengine:main-v2from
Li-Charles-One:fix/3573-drag-icon-error

Conversation

@Li-Charles-One

@Li-Charles-One Li-Charles-One commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Bug

拖动窗口左上角的蓝色 Reasonix 图标到窗口本身时,应用崩溃并显示:

[window.error]
TypeError: Failed to post a message: additional File object is not a file on the disk.
    at Object.Re [as ResolveFilePaths] (http://wails.localhost/wails/runtime.js:2:7400)
    at U (http://wails.localhost/wails/runtime.js:2:7058)

根因

main.goDragAndDrop: &options.DragAndDrop{EnableFileDrop: true} 全局开启了文件拖拽。当用户拖动窗口图标(不是磁盘上的文件)时,Wails 内部的 ResolveFilePaths 尝试将其解析为文件路径,失败后抛出未捕获的错误,导致整个应用崩溃。

可选方案

方案 A:CSS 阻止拖拽(最简单)

给窗口图标加 pointer-events: none-webkit-app-region: no-drag

  • 优点:一行 CSS
  • 缺点:图标失去交互能力,可能影响其他功能

方案 B:关闭全局拖拽 + 局部处理(最彻底)

main.goEnableFileDrop 改为 false,在 composer 区域用 HTML5 onDrop 自己处理文件。

  • 优点:从根源解决,不再依赖 Wails 的全局拖拽
  • 缺点:需要重构拖拽逻辑,改动较大,需要全面测试

方案 C:错误拦截(本 PR 采用,折中方案)

bridge.tsonFilesDropped 中注册全局 errorunhandledrejection 拦截器,精准吞掉该错误。

  • 优点:改动最小(~20 行),不影响现有逻辑,真实文件拖拽不受影响
  • 缺点:治标不治本,Wails 上游如果修复了可以移除

修复内容

本 PR 采用方案 C。如果后续决定采用方案 B 彻底重构,这个拦截器也可以随时移除。

Wails 的 EnableFileDrop 全局开启后,拖动窗口左上角图标
(非磁盘文件)会触发 ResolveFilePaths 抛出未捕获错误,
导致整个应用崩溃。

在 onFilesDropped 中注册全局 error/unhandledrejection 拦截器,
吞掉 'additional File object is not a file on the disk' 错误,
仅允许真实的文件拖拽到达回调。
@github-actions github-actions Bot added v2 Go rewrite (1.x) — main-v2 branch, active development desktop Wails desktop app (desktop/**) labels Jun 9, 2026

@esengine esengine left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the diff: the fix is correct, focused, and CI is green. Approving for merge.

@esengine esengine merged commit 7c7285d into esengine:main-v2 Jun 9, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

desktop Wails desktop app (desktop/**) v2 Go rewrite (1.x) — main-v2 branch, active development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants