From 9266f675959aa45077d7d048335e7c1d3af5725a Mon Sep 17 00:00:00 2001 From: Towhidul I Chowdhury Date: Thu, 13 Mar 2025 13:16:35 +0600 Subject: [PATCH 1/2] feat(context-menu): add "Copy Image to Clipboard" functionality to image context menu Fixes: https://github.com/getstation/desktop-app/issues/200 --- packages/app/src/context-menu.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/app/src/context-menu.ts b/packages/app/src/context-menu.ts index cd2ad8a5..cae1c1ef 100644 --- a/packages/app/src/context-menu.ts +++ b/packages/app/src/context-menu.ts @@ -113,6 +113,23 @@ export default class ContextMenu extends EventEmitter { } }, }, + { + id: 'copyImage', + label: 'Copy Image to Clipboard', + click() { + // Fetch the image and copy to clipboard + fetch(props.srcURL) + .then(response => response.arrayBuffer()) + .then(buffer => { + const { nativeImage } = require('electron'); + const image = nativeImage.createFromBuffer(Buffer.from(buffer)); + clipboard.writeImage(image); + }) + .catch(error => { + console.error('Failed to copy image to clipboard:', error); + }); + }, + }, { id: 'copyImageUrl', label: 'Copy Image URL', From af593d9825fa2b8457578288dac377226b10ee34 Mon Sep 17 00:00:00 2001 From: Towhidul I Chowdhury Date: Sun, 16 Mar 2025 06:04:49 +0600 Subject: [PATCH 2/2] feat(context-menu): Use copyImageAt instead of fetch Fixes: https://github.com/getstation/desktop-app/issues/200 --- packages/app/src/context-menu.ts | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/packages/app/src/context-menu.ts b/packages/app/src/context-menu.ts index cae1c1ef..c291906a 100644 --- a/packages/app/src/context-menu.ts +++ b/packages/app/src/context-menu.ts @@ -117,17 +117,9 @@ export default class ContextMenu extends EventEmitter { id: 'copyImage', label: 'Copy Image to Clipboard', click() { - // Fetch the image and copy to clipboard - fetch(props.srcURL) - .then(response => response.arrayBuffer()) - .then(buffer => { - const { nativeImage } = require('electron'); - const image = nativeImage.createFromBuffer(Buffer.from(buffer)); - clipboard.writeImage(image); - }) - .catch(error => { - console.error('Failed to copy image to clipboard:', error); - }); + if (webContents) { + webContents.copyImageAt(props.x, props.y); + } }, }, {