Skip to content

fix(clipboard): add universal nativeImage fallback for unrecognized clipboard format names#395

Closed
monotykamary wants to merge 1 commit into
SuperCmdLabs:mainfrom
monotykamary:fix/clipboard-universal-image-fallback
Closed

fix(clipboard): add universal nativeImage fallback for unrecognized clipboard format names#395
monotykamary wants to merge 1 commit into
SuperCmdLabs:mainfrom
monotykamary:fix/clipboard-universal-image-fallback

Conversation

@monotykamary
Copy link
Copy Markdown
Contributor

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 1349d14 refactored getClipboardImageFingerprint() to use format-name matching (looksLikeClipboardImageFormat) before attempting to read the image. The native clipboard.readImage() fallback was placed inside the if (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:

  1. Fast path (inside if (formats.some(looksLikeClipboardImageFormat))) — tries raw format buffers (GIF → PNG → JPEG → WebP → HEIC → TIFF) for fingerprinting without toPNG(). Falls back to clipboard.readImage() for any matched-but-unreadable format.

  2. 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), and clipboard.readImage() on an empty clipboard returns immediately via isEmpty().

Changes

  • src/main/clipboard-manager.tsgetClipboardImageFingerprint(): moved the format-name guard to only gate the fast buffer path; added a universal clipboard.readImage() fallback that runs unconditionally.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 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".

Comment on lines 642 to 644
const image = clipboard.readImage();
if (!image.isEmpty()) {
return {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@shobhit99
Copy link
Copy Markdown
Contributor

Hey @monotykamary this already got fixed 😄 it was some regression in last release.
#391
#394

@monotykamary
Copy link
Copy Markdown
Contributor Author

oh totally forgot to see those, just had this on my fork for a while after testing

carry on carry on 🫡

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.

2 participants