fix(clipboard): add universal nativeImage fallback for unrecognized clipboard format names#395
Conversation
…lipboard format names
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 26ee9483c9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const image = clipboard.readImage(); | ||
| if (!image.isEmpty()) { | ||
| return { |
There was a problem hiding this comment.
Cache native fallback fingerprints to avoid per-poll PNG encoding
When the clipboard image is exposed only through an unrecognized format name, this fallback recomputes the fingerprint by calling image.toPNG() on every 1-second poll before lastClipboardImageHash can be compared. For large screenshots or TIFF/HEIC-like images this means repeated decode/PNG-encode work for an unchanged clipboard item, which regresses the CPU optimization this code is trying to preserve; consider caching this fallback result or fingerprinting the available raw pasteboard buffers before encoding.
Useful? React with 👍 / 👎.
|
Hey @monotykamary this already got fixed 😄 it was some regression in last release. |
|
oh totally forgot to see those, just had this on my fork for a while after testing carry on carry on 🫡 |
Problem
When copying images to the clipboard, they do not appear in SuperCmd's clipboard history. Copying any image (screenshot, browser image, etc.) and opening the clipboard panel shows nothing.
Root Cause
Commit
1349d14refactoredgetClipboardImageFingerprint()to use format-name matching (looksLikeClipboardImageFormat) before attempting to read the image. The nativeclipboard.readImage()fallback was placed inside theif (formats.some(looksLikeClipboardImageFormat))guard.If Electron exposes format names that don't match our list (e.g. dynamic UTIs like
dyn.ah62d4rv4gu8yc6c, legacy NSPasteboard types, or any format name not in the allowlist), the function returns{ fingerprint: "" }immediately —clipboard.readImage()is never called, and the image is silently skipped.Fix
Restructured
getClipboardImageFingerprint()with two fallback paths:Fast path (inside
if (formats.some(looksLikeClipboardImageFormat))) — tries raw format buffers (GIF → PNG → JPEG → WebP → HEIC → TIFF) for fingerprinting withouttoPNG(). Falls back toclipboard.readImage()for any matched-but-unreadable format.Universal fallback (outside the format-name guard) — tries
clipboard.readImage()regardless of format names. Catches dynamic UTIs, legacy types, or any unrecognized format name.The CPU optimization is preserved:
toPNG()only runs once per new image (hash comparison prevents re-processing), andclipboard.readImage()on an empty clipboard returns immediately viaisEmpty().Changes
src/main/clipboard-manager.ts—getClipboardImageFingerprint(): moved the format-name guard to only gate the fast buffer path; added a universalclipboard.readImage()fallback that runs unconditionally.