From d3d53dc2d169df92594b217ca0c74982108d7f64 Mon Sep 17 00:00:00 2001 From: Mattias Gustavsson Date: Thu, 12 Dec 2019 09:13:31 +0100 Subject: [PATCH] Added a closeScreenSnippet command --- src/app/main-api-handler.ts | 3 +++ src/app/screen-snippet-handler.ts | 16 ++++++++++++++++ src/common/api-interface.ts | 1 + src/demo/index.html | 12 ++++++++++++ src/renderer/app-bridge.ts | 3 +++ src/renderer/screen-snippet-bc-handler.ts | 10 ++++++++++ src/renderer/ssf-api.ts | 11 +++++++++++ 7 files changed, 56 insertions(+) diff --git a/src/app/main-api-handler.ts b/src/app/main-api-handler.ts index fd274b1e..32701add 100644 --- a/src/app/main-api-handler.ts +++ b/src/app/main-api-handler.ts @@ -117,6 +117,9 @@ ipcMain.on(apiName.symphonyApi, (event: Electron.IpcMainEvent, arg: IApiArgs) => case apiCmds.openScreenSnippet: screenSnippet.capture(event.sender); break; + case apiCmds.closeScreenSnippet: + screenSnippet.cancelCapture(); + break; case apiCmds.closeWindow: windowHandler.closeWindow(arg.windowType, arg.winKey); break; diff --git a/src/app/screen-snippet-handler.ts b/src/app/screen-snippet-handler.ts index 71914fc7..d6057411 100644 --- a/src/app/screen-snippet-handler.ts +++ b/src/app/screen-snippet-handler.ts @@ -67,6 +67,22 @@ class ScreenSnippet { } } + /** + * Cancels a screen capture and closes the snippet window + * + * @param webContents {Electron.webContents} + */ + public async cancelCapture() { + logger.info(`screen-snippet-handler: Cancel screen capture!`); + this.focusedWindow = BrowserWindow.getFocusedWindow(); + + try { + await this.execCmd(this.captureUtil, []); + } catch (error) { + logger.error(`screen-snippet-handler: screen capture cancedl failed with error: ${error}!`); + } + } + /** * Kills the child process when the application is reloaded */ diff --git a/src/common/api-interface.ts b/src/common/api-interface.ts index 3c469158..35ead385 100644 --- a/src/common/api-interface.ts +++ b/src/common/api-interface.ts @@ -19,6 +19,7 @@ export enum apiCmds { setIsInMeeting = 'set-is-in-meeting', setLocale = 'set-locale', openScreenSnippet = 'open-screen-snippet', + closeScreenSnippet = 'close-screen-snippet', keyPress = 'key-press', closeWindow = 'close-window', openScreenSharingIndicator = 'open-screen-sharing-indicator', diff --git a/src/demo/index.html b/src/demo/index.html index f6aafe78..801a8ea2 100644 --- a/src/demo/index.html +++ b/src/demo/index.html @@ -124,6 +124,7 @@

snippet output:

+

Window activate:

@@ -187,6 +188,7 @@ setIsInMeeting: 'set-is-in-meeting', setLocale: 'set-locale', openScreenSnippet: 'open-screen-snippet', + closeScreenSnippet: 'close-screen-snippet', keyPress: 'key-press', closeWindow: 'close-window', openScreenSharingIndicator: 'open-screen-sharing-indicator', @@ -310,6 +312,16 @@ } }); + const cancelSnippetButton = document.getElementById('cancel-snippet'); + cancelSnippetButton.addEventListener('click', () => { + if (window.ssf) { + const screenSnippet = new window.ssf.ScreenSnippet(); + screenSnippet.cancelCapture(); + } else { + postMessage(apiCmds.closeScreenSnippet) + } + }); + let win; const openWinButton = document.getElementById('open-win'); diff --git a/src/renderer/app-bridge.ts b/src/renderer/app-bridge.ts index dbb991e8..5c3c952f 100644 --- a/src/renderer/app-bridge.ts +++ b/src/renderer/app-bridge.ts @@ -114,6 +114,9 @@ export class AppBridge { case apiCmds.openScreenSnippet: ssf.openScreenSnippet(this.callbackHandlers.onScreenSnippetCallback); break; + case apiCmds.closeScreenSnippet: + ssf.closeScreenSnippet(); + break; case apiCmds.registerBoundsChange: ssf.registerBoundsChange(this.callbackHandlers.onRegisterBoundsChangeCallback); break; diff --git a/src/renderer/screen-snippet-bc-handler.ts b/src/renderer/screen-snippet-bc-handler.ts index cf2ee2a0..ace1dea8 100644 --- a/src/renderer/screen-snippet-bc-handler.ts +++ b/src/renderer/screen-snippet-bc-handler.ts @@ -24,4 +24,14 @@ export class ScreenSnippetBcHandler { }); }); } + /** + * cancel capture method to support backward compatibility + * + * @deprecated user closeScreenSnippet instead + */ + public cancel() { + ipcRenderer.send(apiName.symphonyApi, { + cmd: apiCmds.closeScreenSnippet, + }); + } } diff --git a/src/renderer/ssf-api.ts b/src/renderer/ssf-api.ts index 7d698a89..0c86f3e5 100644 --- a/src/renderer/ssf-api.ts +++ b/src/renderer/ssf-api.ts @@ -302,6 +302,17 @@ export class SSFApi { } } + /** + * Cancel a screen capture in progress + * + * @param screenSnippetCallback {function} + */ + public closeScreenSnippet(): void { + local.ipcRenderer.send(apiName.symphonyApi, { + cmd: apiCmds.closeScreenSnippet, + }); + } + /** * Sets the count on the tray icon to the given number. *