Electron-228 - Added an event to terminate screen snippet process whenever the main window is reloaded/navigated

This commit is contained in:
kiranniranjan
2018-01-18 12:53:27 +05:30
parent 665f35b08e
commit 20e1f0b6ca
4 changed files with 38 additions and 5 deletions

View File

@@ -13,6 +13,8 @@ const activityDetection = require('./activityDetection');
const badgeCount = require('./badgeCount.js');
const protocolHandler = require('./protocolHandler');
const configureNotification = require('./notify/settings/configure-notification-position');
const eventEmitter = require('./eventEmitter');
const { isMac } = require('./utils/misc');
const apiEnums = require('./enums/api.js');
const apiCmds = apiEnums.cmds;
@@ -47,6 +49,24 @@ function isValidWindow(event) {
return result;
}
/**
* Method that is invoked when the application is reloaded/navigated
* window.addEventListener('beforeunload')
* @param windowName
*/
function reload(windowName) {
// To make sure the reload event is from the main window
if (windowMgr.getMainWindow() && windowName === windowMgr.getMainWindow().winName) {
// reset the badge count whenever an user refreshes the electron client
badgeCount.show(0);
// Terminates the screen snippet process on reload
if (!isMac) {
eventEmitter.emit('killScreenSnippet');
}
}
}
/**
* Handle API related ipc messages from renderers. Only messages from windows
* we have created are allowed.
@@ -103,6 +123,10 @@ electron.ipcMain.on(apiName, (event, arg) => {
if (arg.cmd === apiCmds.showNotificationSettings && typeof arg.windowName === 'string') {
configureNotification.openConfigurationWindow(arg.windowName);
}
if (arg.cmd === apiCmds.reload && typeof arg.windowName === 'string') {
reload(arg.windowName);
}
});
// expose these methods primarily for testing...