Merge pull request #2109 from NguyenTranHoangSym/SDA-4481

SDA-4481: Add Fix to image cannot be copied
This commit is contained in:
NguyenTranHoangSym 2024-04-04 16:44:29 +07:00 committed by GitHub
commit 668e68ec90
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,6 +1,8 @@
import { BrowserWindow, clipboard, Menu, MenuItem, shell } from 'electron';
import { apiName } from '../common/api-interface';
import { isDevEnv } from '../common/env';
import { logger } from '../common/logger';
import { ICustomBrowserWindow } from './window-handler';
interface IContextMenuStringTable {
copyMail: () => string;
@ -376,12 +378,19 @@ export class ContextMenuBuilder {
* Adds "Copy Image" and "Copy Image URL" items when `src` is valid.
*/
public addImageItems(menu, menuInfo) {
const target = this.getWebContents();
const current = this.getWebContents();
const focusedWindow =
BrowserWindow.getFocusedWindow() as ICustomBrowserWindow;
const copyImage = new MenuItem({
label: this.stringTable.copyImage(),
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');
target.send('copy-to-clipboard', menuInfo.srcURL);
},
});