Added a closeScreenSnippet command

This commit is contained in:
Mattias Gustavsson 2019-12-12 09:13:31 +01:00
parent 21af4338b9
commit d3d53dc2d1
7 changed files with 56 additions and 0 deletions

View File

@ -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;

View File

@ -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
*/

View File

@ -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',

View File

@ -124,6 +124,7 @@
<button id='snippet'>get snippet</button>
<p>snippet output:</p>
<image id='snippet-img'/>
<button id='cancel-snippet'>cancel snippet</button>
<hr>
<p>Window activate:</p>
@ -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');

View File

@ -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;

View File

@ -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,
});
}
}

View File

@ -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.
*