SDA-4481: Add Fix to image cannot be copied

This commit is contained in:
NguyenTranHoangSym 2024-03-11 16:57:01 +07:00 committed by nguyen.tranhoang
parent 897c6172cd
commit 87e27efb2d

View File

@ -1,6 +1,8 @@
import { BrowserWindow, clipboard, Menu, MenuItem, shell } from 'electron'; import { BrowserWindow, clipboard, Menu, MenuItem, shell } from 'electron';
import { apiName } from '../common/api-interface';
import { isDevEnv } from '../common/env'; import { isDevEnv } from '../common/env';
import { logger } from '../common/logger'; import { logger } from '../common/logger';
import { ICustomBrowserWindow } from './window-handler';
interface IContextMenuStringTable { interface IContextMenuStringTable {
copyMail: () => string; copyMail: () => string;
@ -376,12 +378,19 @@ export class ContextMenuBuilder {
* Adds "Copy Image" and "Copy Image URL" items when `src` is valid. * Adds "Copy Image" and "Copy Image URL" items when `src` is valid.
*/ */
public addImageItems(menu, menuInfo) { public addImageItems(menu, menuInfo) {
const target = this.getWebContents(); const current = this.getWebContents();
const focusedWindow =
BrowserWindow.getFocusedWindow() as ICustomBrowserWindow;
const copyImage = new MenuItem({ const copyImage = new MenuItem({
label: this.stringTable.copyImage(), label: this.stringTable.copyImage(),
click: (_e) => { click: (_e) => {
if (focusedWindow && focusedWindow.winName === apiName.mainWindowName) {
current?.send('copy-to-clipboard', menuInfo.srcURL);
} else {
current.copyImageAt(menuInfo.x, menuInfo.y);
}
logger.info('Context-Menu-Builder: Copy Image to clipboard'); logger.info('Context-Menu-Builder: Copy Image to clipboard');
target.send('copy-to-clipboard', menuInfo.srcURL);
}, },
}); });