From 6125fd99a2d39276eb7fa649ff631b92fb37ec2b Mon Sep 17 00:00:00 2001 From: Kiran Niranjan Date: Tue, 14 Jan 2020 14:14:52 +0530 Subject: [PATCH] fix: SDA-1284 (Add logic to close screen snippet tool) (#847) * SDA-1284 - Add support to cancel screen snippet window * SDA-1284 - Early exit is not running on windows --- src/app/screen-snippet-handler.ts | 27 ++++++++++++++++++--------- src/renderer/ssf-api.ts | 2 -- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/app/screen-snippet-handler.ts b/src/app/screen-snippet-handler.ts index 7c29b5e4..68aa96e6 100644 --- a/src/app/screen-snippet-handler.ts +++ b/src/app/screen-snippet-handler.ts @@ -65,22 +65,16 @@ class ScreenSnippet { // only allow one screen capture at a time. if (this.child) { logger.info(`screen-snippet-handler: Child screen capture exists, killing it and keeping only 1 instance!`); - this.child.kill(); + this.killChildProcess(); } try { await this.execCmd(this.captureUtil, this.captureUtilArgs); const { message, data, type }: IScreenSnippet = await this.convertFileToData(); logger.info(`screen-snippet-handler: Snippet captured! Sending data to SFE`); webContents.send('screen-snippet-data', { message, data, type }); - if (this.shouldUpdateAlwaysOnTop) { - await updateAlwaysOnTop(true, false); - this.shouldUpdateAlwaysOnTop = false; - } + await this.verifyAndUpdateAlwaysOnTop(); } catch (error) { - if (this.shouldUpdateAlwaysOnTop) { - await updateAlwaysOnTop(true, false); - this.shouldUpdateAlwaysOnTop = false; - } + await this.verifyAndUpdateAlwaysOnTop(); logger.error(`screen-snippet-handler: screen capture failed with error: ${error}!`); } } @@ -89,12 +83,17 @@ class ScreenSnippet { * Cancels a screen capture and closes the snippet window */ public async cancelCapture() { + if (!isWindowsOS) { + return; + } logger.info(`screen-snippet-handler: Cancel screen capture!`); this.focusedWindow = BrowserWindow.getFocusedWindow(); try { await this.execCmd(this.captureUtil, []); + await this.verifyAndUpdateAlwaysOnTop(); } catch (error) { + await this.verifyAndUpdateAlwaysOnTop(); logger.error(`screen-snippet-handler: screen capture cancel failed with error: ${error}!`); } } @@ -174,6 +173,16 @@ class ScreenSnippet { } } } + + /** + * Verify and updates always on top + */ + private async verifyAndUpdateAlwaysOnTop(): Promise { + if (this.shouldUpdateAlwaysOnTop) { + await updateAlwaysOnTop(true, false); + this.shouldUpdateAlwaysOnTop = false; + } + } } const screenSnippet = new ScreenSnippet(); diff --git a/src/renderer/ssf-api.ts b/src/renderer/ssf-api.ts index 4907fd94..6b82c436 100644 --- a/src/renderer/ssf-api.ts +++ b/src/renderer/ssf-api.ts @@ -336,8 +336,6 @@ export class SSFApi { /** * Cancel a screen capture in progress - * - * @param screenSnippetCallback {function} */ public closeScreenSnippet(): void { local.ipcRenderer.send(apiName.symphonyApi, {