@@ -22,15 +22,31 @@ function setupContextMenu($image) {
2222 command : "copyImageReferenceToClipboard" ,
2323 uiIcon : "bx bx-empty"
2424 } ,
25- { title : "Copy image to clipboard" , command : "copyImageToClipboard" , uiIcon : "bx bx-empty" } ,
25+ { title : "Copy image to clipboard" , command : "copyImageToClipboard" , uiIcon : "bx bx-empty" } ,
2626 ] ,
27- selectMenuItemHandler : ( { command} ) => {
27+ selectMenuItemHandler : async ( { command } ) => {
2828 if ( command === 'copyImageReferenceToClipboard' ) {
2929 imageService . copyImageReferenceToClipboard ( $image ) ;
3030 } else if ( command === 'copyImageToClipboard' ) {
31- const webContents = utils . dynamicRequire ( '@electron/remote' ) . getCurrentWebContents ( ) ;
32- utils . dynamicRequire ( 'electron' ) ;
33- webContents . copyImageAt ( e . pageX , e . pageY ) ;
31+ try {
32+ const nativeImage = utils . dynamicRequire ( 'electron' ) . nativeImage ;
33+ const clipboard = utils . dynamicRequire ( 'electron' ) . clipboard ;
34+
35+ const response = await fetch (
36+ $image . attr ( 'src' )
37+ ) ;
38+ const blob = await response . blob ( ) ;
39+
40+ clipboard . writeImage (
41+ nativeImage . createFromBuffer (
42+ Buffer . from (
43+ await blob . arrayBuffer ( )
44+ )
45+ )
46+ ) ;
47+ } catch ( error ) {
48+ console . error ( 'Failed to copy image to clipboard:' , error ) ;
49+ }
3450 } else {
3551 throw new Error ( `Unrecognized command '${ command } '` ) ;
3652 }
@@ -41,4 +57,4 @@ function setupContextMenu($image) {
4157
4258export default {
4359 setupContextMenu
44- } ;
60+ } ;
0 commit comments