Skip to content

Commit

Permalink
SDA-3094: Listen to copy image event (finos#2026)
Browse files Browse the repository at this point in the history
  • Loading branch information
NguyenTranHoangSym authored Jan 31, 2024
1 parent 756516c commit 31ebada
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/app/context-menu-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/common/api-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions src/renderer/preload-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 21 additions & 0 deletions src/renderer/ssf-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 31ebada

Please sign in to comment.