Repository navigation
Conversation
Images in a chat answer could not be copied. A local markdown image only opened the file manager, and generated results offered download and reveal but no copy, so getting a picture into another app meant saving it and finding the file first. Loaded images now carry Copy image and Download image, reached from a right-click menu on markdown images and on generated result cards and the viewer, plus a copy button and Cmd/Ctrl+C in the viewer. Copy writes PNG bytes (JPEG/WebP are re-encoded) through the async clipboard API. The viewer is a modal dialog, so its menu portals into the dialog and reports copy inline instead of through a hidden toast.
muzimu217
left a comment
There was a problem hiding this comment.
Verified the two claims in the description that could have failed silently.
No IPC change is needed, and the reason is documented. installLiveMicrophonePermissionHandlers installs the request/check handlers on session.defaultSession (electron/main/index.ts:1027-1033), which is the session the main renderer uses. Its non-media branch grants everything (microphone-permissions.ts:50-58), and the comment there says why: installing a handler replaces the platform default for every permission on that session, and denying the rest "silently broke the app's own copy buttons, which need clipboard-sanitized-write". So navigator.clipboard.write works today, and this PR would break the moment that policy narrowed — worth remembering, because the failure mode is a silent no-op rather than an exception at the call site.
The portal target is handled correctly. portalToContainer wraps the node in visiblePortalContent before createPortal (components/ContextMenu.tsx), matching what portalToBody does (lib/portal-visibility.tsx:20-28), so the visibility context survives when the menu renders inside the <dialog> instead of body. A bare createPortal would have lost it.
PNG passthrough before any conversion is the right call — Chromium's async clipboard only accepts image/png, and re-encoding a PNG would be a lossy-looking step for no reason. The test pins it byte-for-byte, and the JPEG/WebP re-encode path is covered separately.
Two small things, neither blocking:
SUPPORTED_IMAGE_DATA_URLaccepts onlypng|jpeg|webp.image/jpgis a common alias and would fail the match, so a copy from such a source reports "copy failed" instead of working. Normalizing the subtype before the match (or acceptingjpe?g) costs nothing.downloadMarkdownImagederives the file name withreference.split(/[\\/]/).pop(), which keeps a query string or fragment when the reference is a URL (photo.png?w=800).decodeURIComponentplus stripping[?#]before the split would give the same name the browser would.
Sources often label JPEG data as image/jpg, which the clipboard helper rejected and then reported as a copy failure. Downloading an image shown from a URL also kept its query or fragment in the saved file name (photo.png?w=800). Local paths keep their last segment verbatim, since `#` and `%` are legal there.
|
Thanks for the review. Both points are fixed in fae60ff:
Noted on the I also merged the latest |
|
After the merge with the latest |
|
这个问题描述的是新增能力:当前点击打开本地图片、右键复制文件路径,与现有交互一致;PR 想新增把图片内容写入剪贴板的操作。我没有找到既有产品约定或回归证据能证明这是代码缺陷。谢谢你补齐复制、下载和 MIME/文件名边界;但按当前仓库的外部 PR 范围,这项新能力属于 feat,不能作为 fix 合入。后续限制解除后可按 feature 重新提交。 |
Images in a reply could only be opened or have their path copied, so getting the picture itself into another app meant a detour through the file manager. Generated images and Markdown images now offer Copy image and Download image on right-click; the generated-image viewer also has a copy button and Cmd/Ctrl+C. Copy writes PNG to the clipboard (JPEG, JPG and WebP are re-encoded). Download names come from the URL path without its query or fragment; local paths keep their file name verbatim. Refs vastsa#1917, supersedes vastsa#1918.
Images in a reply could only be opened or have their path copied, so getting the picture itself into another app meant a detour through the file manager. Generated images and Markdown images now offer Copy image and Download image on right-click; the generated-image viewer also has a copy button and Cmd/Ctrl+C. Copy writes PNG to the clipboard (JPEG, JPG and WebP are re-encoded). Download names come from the URL path without its query or fragment; local paths keep their file name verbatim. Refs #1917, supersedes #1918.
问题
修复 #1917:回复里的图片没法直接复制。点击 Markdown 本地图片只会打开文件管理器,右键也只有复制路径;生成图片的卡片和查看器同样没有复制操作。
改动
<dialog>,挂在 body 上的菜单和 toast 会被它挡住,所以菜单渲染进 dialog 内部(ContextMenu新增可选的container参数),复制结果直接在查看器里提示。apps/desktop/src/lib/image-clipboard.ts,PNG 原样写入;JPEG/WebP 先转成 PNG,再通过navigator.clipboard.write+ClipboardItem写入剪贴板。主进程的权限处理本来就允许 clipboard 写入,没有改 IPC。settings.copyGeneratedImage、settings.downloadImage,9 种语言都有。21-image-generation.md、08-component-spec.md、E2E-IMAGES-result-download、E2E-187。截图
验证
pnpm --filter @pi-desktop/desktop typecheck通过node --test test/*.test.mjs:4434 个测试,0 失败(新增image-clipboard.test.mjs、generated-image-context-menu.test.mjs,并在chat-file-open-with-menu.test.mjs中补了断言)check-architecture、style tokens、git diff --check均通过fixes #1917