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

@@ -16,6 +16,7 @@ const cmds = keyMirror({
registerProtocolHandler: null,
registerActivityDetection: null,
showNotificationSettings: null,
reload: null
});
module.exports = {

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

View File

@@ -367,17 +367,17 @@ function createAPI() {
});
}
// reset the badge count whenever an user refreshes the electron client
function resetBadgeCount() {
// Invoked whenever the app is reloaded/navigated
function reload() {
local.ipcRenderer.send(apiName, {
cmd: apiCmds.setBadgeCount,
count: 0
cmd: apiCmds.reload,
windowName: window.name
});
}
window.addEventListener('offline', updateOnlineStatus, false);
window.addEventListener('online', updateOnlineStatus, false);
window.addEventListener('beforeunload', resetBadgeCount, false);
window.addEventListener('beforeunload', reload, false);
updateOnlineStatus();
}

View File

@@ -181,6 +181,14 @@ function createWarn(msg) {
}
/* eslint-enable class-methods-use-this */
// terminates the screen snippet process wherever the
// main window is reloaded/navigated
eventEmitter.on('killScreenSnippet', function () {
if (child) {
child.kill();
}
});
module.exports = {
ScreenSnippet: ScreenSnippet,
// note: readResult only exposed for testing purposes