SDA-3094: Listen to copy image event (#2026)

This commit is contained in:
NguyenTranHoangSym 2024-01-31 16:46:26 +07:00 committed by GitHub
parent 756516ca87
commit 31ebada917
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 27 additions and 1 deletions

View File

@ -379,7 +379,10 @@ export class ContextMenuBuilder {
const target = this.getWebContents();
const copyImage = new MenuItem({
label: this.stringTable.copyImage(),
click: () => target.copyImageAt(menuInfo.x, menuInfo.y),
click: (_e) => {
logger.info('Context-Menu-Builder: Copy Image to clipboard');
target.send('copy-to-clipboard', menuInfo.srcURL);
},
});
menu.append(copyImage);

View File

@ -14,6 +14,7 @@ export enum apiCmds {
sendLogs = 'send-logs',
addLogs = 'add-logs',
registerAnalyticsHandler = 'register-analytics-handler',
registerWriteImageToClipboard = 'register-write-image-to-clipboard',
registerActivityDetection = 'register-activity-detection',
showNotificationSettings = 'show-notification-settings',
sanitize = 'sanitize',

View File

@ -68,6 +68,7 @@ if (ssfWindow.ssf) {
sendLogs: ssfWindow.ssf.sendLogs,
addLogs: ssfWindow.ssf.addLogs,
registerAnalyticsEvent: ssfWindow.ssf.registerAnalyticsEvent,
registerWriteImageToClipboard: ssfWindow.ssf.registerWriteImageToClipboard,
ScreenSnippet: ssfWindow.ssf.ScreenSnippet,
openScreenSnippet: ssfWindow.ssf.openScreenSnippet,
closeScreenSnippet: ssfWindow.ssf.closeScreenSnippet,

View File

@ -66,6 +66,7 @@ export interface ILocalObject {
c9MessageCallback?: (status: IShellStatus) => void;
updateMyPresenceCallback?: (presence: EPresenceStatusCategory) => void;
phoneNumberCallback?: (arg: string) => void;
writeImageToClipboard?: (blob: string) => void;
}
const local: ILocalObject = {
@ -384,6 +385,17 @@ export class SSFApi {
}
}
/**
* Register Event to expose callback when Copy Image is clicked
*
* @param analyticsEventHandler
*/
public registerWriteImageToClipboard(callback): void {
if (typeof callback === 'function') {
local.writeImageToClipboard = callback;
}
}
/**
* Expose old screen snippet api to support backward compatibility
*
@ -1025,6 +1037,15 @@ local.ipcRenderer.on(
},
);
local.ipcRenderer.on(
'copy-to-clipboard',
async (_event: Event, arg: string) => {
if (typeof local.writeImageToClipboard === 'function') {
local.writeImageToClipboard(arg);
}
},
);
/**
* An event triggered by the main process
* when the snippet is complete