From 31ebada91740e8bfa889981c08c173e7b6e5c2de Mon Sep 17 00:00:00 2001 From: NguyenTranHoangSym <97150869+NguyenTranHoangSym@users.noreply.github.com> Date: Wed, 31 Jan 2024 16:46:26 +0700 Subject: [PATCH] SDA-3094: Listen to copy image event (#2026) --- src/app/context-menu-builder.ts | 5 ++++- src/common/api-interface.ts | 1 + src/renderer/preload-main.ts | 1 + src/renderer/ssf-api.ts | 21 +++++++++++++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/app/context-menu-builder.ts b/src/app/context-menu-builder.ts index 54f98504..4925926b 100644 --- a/src/app/context-menu-builder.ts +++ b/src/app/context-menu-builder.ts @@ -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); diff --git a/src/common/api-interface.ts b/src/common/api-interface.ts index ebd117b5..62b94e45 100644 --- a/src/common/api-interface.ts +++ b/src/common/api-interface.ts @@ -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', diff --git a/src/renderer/preload-main.ts b/src/renderer/preload-main.ts index 923e8fa3..f761a111 100644 --- a/src/renderer/preload-main.ts +++ b/src/renderer/preload-main.ts @@ -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, diff --git a/src/renderer/ssf-api.ts b/src/renderer/ssf-api.ts index a75de2e8..563db016 100644 --- a/src/renderer/ssf-api.ts +++ b/src/renderer/ssf-api.ts @@ -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