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
This commit is contained in:
Kiran Niranjan 2020-01-14 14:14:52 +05:30 committed by Vishwas Shashidhar
parent 84ec8758b6
commit 6125fd99a2
2 changed files with 18 additions and 11 deletions

View File

@ -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<void> {
if (this.shouldUpdateAlwaysOnTop) {
await updateAlwaysOnTop(true, false);
this.shouldUpdateAlwaysOnTop = false;
}
}
}
const screenSnippet = new ScreenSnippet();

View File

@ -336,8 +336,6 @@ export class SSFApi {
/**
* Cancel a screen capture in progress
*
* @param screenSnippetCallback {function}
*/
public closeScreenSnippet(): void {
local.ipcRenderer.send(apiName.symphonyApi, {