Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(context-menu): add "Copy Image to Clipboard" functionality to image context menu #470

Merged
merged 2 commits into from
Mar 17, 2025

Conversation

itowhid06
Copy link
Contributor

What is this PR

This PR adds a new "Copy Image to Clipboard" feature to the context menu for images in our Electron app. This enhancement complements the existing functionality that allows users to save images or copy image URLs by providing a more direct way to capture image content for pasting elsewhere.

The feature was requested as an enhancement to improve user workflow when working with images, particularly for users who need to quickly transfer image content between applications without saving files to disk first.

Fixes: #200

How does it work

The implementation uses Electron's native APIs to fetch and process images:

  1. Added a new menu item between "Save Image" and "Copy Image URL" options in the image context menu
  2. When selected, the feature:
    • Uses fetch() to retrieve the image data from the source URL
    • Converts the response to an array buffer
    • Creates a native image object using Electron's nativeImage.createFromBuffer()
    • Writes the image to the system clipboard using clipboard.writeImage()
    • Includes error handling to gracefully handle failed image fetching attempts

This approach ensures compatibility with various image types and sources while maintaining the existing menu structure and user experience.

Test instructions

  1. Setup:

    • Run the Electron application in development mode
    • Navigate to a page that contains images
  2. Testing the feature:

    • Right-click on any image to open the context menu
    • Verify the "Copy Image to Clipboard" option appears between "Save Image" and "Copy Image URL"
    • Click on the "Copy Image to Clipboard" option
  3. Verifying functionality:

    • Open any application that accepts image pastes (e.g., Paint, Photoshop, Google Docs)
    • Use Ctrl+V (or Cmd+V on Mac) to paste
    • Confirm that the image from the application is correctly pasted
  4. Regression testing:

    • Verify the existing "Save Image" and "Copy Image URL" options still work correctly
    • Confirm the overall context menu behavior remains consistent

@magne4000
Copy link
Member

magne4000 commented Mar 13, 2025

@itowhid06 Have you tried using copyImageAt? Using fetch will not work properly in multiple cases, like trying to fetch an image in an authenticated page. It also avoids triggering another request.

@itowhid06 itowhid06 requested a review from magne4000 March 16, 2025 00:05
@magne4000 magne4000 merged commit c1400d6 into getstation:main Mar 17, 2025
3 checks 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.

copy images to clipboard
2 participants