Skip to content

fix(composer): attach native files dropped into desktop - #76

Merged
Jaxton07 merged 3 commits into
Jaxton07:mainfrom
YIKUAIBANZI:fix/native-file-drop
Sep 22, 2026
Merged

Jaxton07 merged 3 commits into
Jaxton07:mainfrom
YIKUAIBANZI:fix/native-file-drop

Conversation

@YIKUAIBANZI

Copy link
Copy Markdown
Contributor

Closes #62.

The desktop composer accepted image paste and file-picker attachments, but did not handle a native OS file drop. This adds a preload bridge around Electron webUtils.getPathForFile, then routes dropped paths through the existing composer attachment flow. Invalid or repeated paths are ignored.

Validation:

  • npm run typecheck
  • npm run lint
  • npm run test (including two new focused drop-path tests)
  • npm run build

I verified the code path and tests on macOS; I could not run the Windows desktop drag-and-drop interaction locally, so I would appreciate a Windows smoke test from a maintainer or contributor.

@Jaxton07 Jaxton07 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.

发现 1 个需要修正的正确性问题:

  • packages/desktop/src/renderer/src/components/composer/drop-files.ts:12:不要对 webUtils.getPathForFile() 返回的原生路径调用 trim()。macOS/Linux 允许文件名以空格开头或结尾;当前实现会把路径改成另一个不存在的路径,也可能把两个不同文件错误去重。这里应保留原字符串,只用空字符串判断(例如 if (path.length > 0) paths.add(path)),并补一个保留首尾空格的测试。

非阻塞项:本 PR 给 PiApi 新增了一个表外成员,docs/INDEX.md 中“手写成员只有 on*/platform”的描述已过时;请一并更新索引。

其余实现方向合理:采用 Electron 官方 webUtils.getPathForFile preload bridge,并复用现有附件草稿管线。CI 已通过;本地复核通过 typecheck、lint 和新增的 2 个单测。

@Jaxton07 Jaxton07 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.

维护者修复已补充:保留 Electron 返回的原生路径原值,新增尾随空格路径回归测试,并同步更新 PiApi/项目索引说明。

本地 typecheck、全部测试、lint 通过;远端 CI 通过。

@Jaxton07
Jaxton07 merged commit f7a3ff6 into Jaxton07:main Sep 22, 2026
1 check passed
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.

拖放文件到窗口无反应(sandbox: true 下未使用 webUtils.getPathForFile 取路径)

2 participants