mirror of
https://github.com/finos/SymphonyElectron.git
synced 2024-12-27 01:11:13 -06:00
Typescript - Add login to close screen snippet
This commit is contained in:
parent
b70777bd81
commit
7771ea5b41
@ -5,7 +5,14 @@ import { LocaleType } from '../common/i18n';
|
||||
import { logger } from '../common/logger';
|
||||
import { activityDetection } from './activity-detection';
|
||||
import { screenSnippet } from './screen-snippet';
|
||||
import { isValidWindow, setDataUrl, showBadgeCount, showPopupMenu, updateLocale } from './window-utils';
|
||||
import {
|
||||
isValidWindow,
|
||||
sanitize,
|
||||
setDataUrl,
|
||||
showBadgeCount,
|
||||
showPopupMenu,
|
||||
updateLocale,
|
||||
} from './window-utils';
|
||||
|
||||
/**
|
||||
* Handle API related ipc messages from renderers. Only messages from windows
|
||||
@ -64,12 +71,12 @@ ipcMain.on(apiName.symphonyApi, (event: Electron.Event, arg: IApiArgs) => {
|
||||
configureNotification.openConfigurationWindow(arg.windowName);
|
||||
}
|
||||
break;
|
||||
case ApiCmds.sanitize:
|
||||
*/case apiCmds.sanitize:
|
||||
if (typeof arg.windowName === 'string') {
|
||||
sanitize(arg.windowName);
|
||||
}
|
||||
break;
|
||||
case ApiCmds.bringToFront:
|
||||
/*case ApiCmds.bringToFront:
|
||||
// validates the user bring to front config and activates the wrapper
|
||||
if (typeof arg.reason === 'string' && arg.reason === 'notification') {
|
||||
bringToFront(arg.windowName, arg.reason);
|
||||
|
@ -55,7 +55,7 @@ class ScreenSnippet {
|
||||
// only allow one screen capture at a time.
|
||||
if (this.child) this.child.kill();
|
||||
try {
|
||||
this.child = await this.execCmd(this.captureUtil, this.captureUtilArgs);
|
||||
await this.execCmd(this.captureUtil, this.captureUtilArgs);
|
||||
const { message, data, type } = await this.convertFileToData();
|
||||
webContents.send('screen-snippet-data', { message, data, type });
|
||||
} catch (error) {
|
||||
@ -63,6 +63,15 @@ class ScreenSnippet {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Kills the child process when the application is reloaded
|
||||
*/
|
||||
public killChildProcess(): void {
|
||||
if (this.child && typeof this.child.kill === 'function') {
|
||||
this.child.kill();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the given command via a child process
|
||||
*
|
||||
@ -76,7 +85,7 @@ class ScreenSnippet {
|
||||
*/
|
||||
private execCmd(captureUtil: string, captureUtilArgs: ReadonlyArray<string>): Promise<ChildProcess> {
|
||||
return new Promise<ChildProcess>((resolve, reject) => {
|
||||
return execFile(captureUtil, captureUtilArgs, (error: ExecException | null) => {
|
||||
return this.child = execFile(captureUtil, captureUtilArgs, (error: ExecException | null) => {
|
||||
if (this.isAlwaysOnTop) updateAlwaysOnTop(true, false);
|
||||
if (error && error.killed) {
|
||||
// processs was killed, just resolve with no data.
|
||||
|
@ -5,6 +5,7 @@ import * as url from 'url';
|
||||
import { isMac, isWindowsOS } from '../common/env';
|
||||
import { i18n, LocaleType } from '../common/i18n';
|
||||
import { logger } from '../common/logger';
|
||||
import { screenSnippet } from './screen-snippet';
|
||||
import { ICustomBrowserWindow, windowHandler } from './window-handler';
|
||||
|
||||
const checkValidWindow = true;
|
||||
@ -217,4 +218,27 @@ export const showPopupMenu = (opts: Electron.PopupOptions): void => {
|
||||
const appMenu = windowHandler.appMenu;
|
||||
if (appMenu) appMenu.popupMenu({ ...popupOpts, ...opts });
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Method that is invoked when the application is reloaded/navigated
|
||||
* window.addEventListener('beforeunload')
|
||||
*
|
||||
* @param windowName {string}
|
||||
*/
|
||||
export const sanitize = (windowName: string): void => {
|
||||
// To make sure the reload event is from the main window
|
||||
const mainWindow = windowHandler.getMainWindow();
|
||||
if (mainWindow && windowName === mainWindow.winName) {
|
||||
// reset the badge count whenever an user refreshes the electron client
|
||||
showBadgeCount(0);
|
||||
|
||||
// Terminates the screen snippet process on reload
|
||||
if (!isMac) {
|
||||
screenSnippet.killChildProcess();
|
||||
}
|
||||
// TODO: write method to clean up child window
|
||||
// Closes all the child windows
|
||||
// windowMgr.cleanUpChildWindows();
|
||||
}
|
||||
};
|
@ -150,4 +150,18 @@ ipcRenderer.on('activity', (_event: Event, arg: IActivityDetection) => {
|
||||
if (typeof arg === 'object' && typeof local.activityDetection === 'function') {
|
||||
local.activityDetection(arg);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Invoked whenever the app is reloaded/navigated
|
||||
const sanitize = (): void => {
|
||||
local.ipcRenderer.send(apiName, {
|
||||
cmd: apiCmds.sanitize,
|
||||
windowName: window.name || 'main',
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Window Events
|
||||
*/
|
||||
|
||||
window.addEventListener('beforeunload', sanitize, false);
|
Loading…
Reference in New Issue
Block a user