mirror of
https://github.com/finos/SymphonyElectron.git
synced 2025-02-25 18:55:29 -06:00
Merge pull request #292 from KiranNiranjan/ELECTRON-228
Electron-228 (Fixes Screen Snippet Reload Issue)
This commit is contained in:
@@ -16,6 +16,7 @@ const cmds = keyMirror({
|
||||
registerProtocolHandler: null,
|
||||
registerActivityDetection: null,
|
||||
showNotificationSettings: null,
|
||||
sanitize: null
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
|
||||
110
js/mainApiMgr.js
110
js/mainApiMgr.js
@@ -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 sanitize(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.
|
||||
@@ -60,49 +80,57 @@ electron.ipcMain.on(apiName, (event, arg) => {
|
||||
return;
|
||||
}
|
||||
|
||||
if (arg.cmd === apiCmds.isOnline && typeof arg.isOnline === 'boolean') {
|
||||
windowMgr.setIsOnline(arg.isOnline);
|
||||
return;
|
||||
switch(arg.cmd) {
|
||||
case apiCmds.isOnline:
|
||||
if (typeof arg.isOnline === 'boolean') {
|
||||
windowMgr.setIsOnline(arg.isOnline);
|
||||
}
|
||||
break;
|
||||
case apiCmds.setBadgeCount:
|
||||
if (typeof arg.count === 'number') {
|
||||
badgeCount.show(arg.count);
|
||||
}
|
||||
break;
|
||||
case apiCmds.registerProtocolHandler:
|
||||
protocolHandler.setProtocolWindow(event.sender);
|
||||
protocolHandler.checkProtocolAction();
|
||||
break;
|
||||
case apiCmds.badgeDataUrl:
|
||||
if (typeof arg.dataUrl === 'string' && typeof arg.count === 'number') {
|
||||
badgeCount.setDataUrl(arg.dataUrl, arg.count);
|
||||
}
|
||||
break;
|
||||
case apiCmds.activate:
|
||||
if (typeof arg.windowName === 'string') {
|
||||
windowMgr.activate(arg.windowName);
|
||||
}
|
||||
break;
|
||||
case apiCmds.registerBoundsChange:
|
||||
windowMgr.setBoundsChangeWindow(event.sender);
|
||||
break;
|
||||
case apiCmds.registerLogger:
|
||||
// renderer window that has a registered logger from JS.
|
||||
log.setLogWindow(event.sender);
|
||||
break;
|
||||
case apiCmds.registerActivityDetection:
|
||||
if (typeof arg.period === 'number') {
|
||||
// renderer window that has a registered activity detection from JS.
|
||||
activityDetection.setActivityWindow(arg.period, event.sender);
|
||||
}
|
||||
break;
|
||||
case apiCmds.showNotificationSettings:
|
||||
if (typeof arg.windowName === 'string') {
|
||||
configureNotification.openConfigurationWindow(arg.windowName);
|
||||
}
|
||||
break;
|
||||
case apiCmds.sanitize:
|
||||
if (typeof arg.windowName === 'string') {
|
||||
sanitize(arg.windowName);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
if (arg.cmd === apiCmds.setBadgeCount && typeof arg.count === 'number') {
|
||||
badgeCount.show(arg.count);
|
||||
return;
|
||||
}
|
||||
|
||||
if (arg.cmd === apiCmds.registerProtocolHandler) {
|
||||
protocolHandler.setProtocolWindow(event.sender);
|
||||
protocolHandler.checkProtocolAction();
|
||||
}
|
||||
|
||||
if (arg.cmd === apiCmds.badgeDataUrl && typeof arg.dataUrl === 'string' &&
|
||||
typeof arg.count === 'number') {
|
||||
badgeCount.setDataUrl(arg.dataUrl, arg.count);
|
||||
return;
|
||||
}
|
||||
|
||||
if (arg.cmd === apiCmds.activate && typeof arg.windowName === 'string') {
|
||||
windowMgr.activate(arg.windowName);
|
||||
return;
|
||||
}
|
||||
|
||||
if (arg.cmd === apiCmds.registerBoundsChange) {
|
||||
windowMgr.setBoundsChangeWindow(event.sender);
|
||||
}
|
||||
|
||||
if (arg.cmd === apiCmds.registerLogger) {
|
||||
// renderer window that has a registered logger from JS.
|
||||
log.setLogWindow(event.sender);
|
||||
}
|
||||
|
||||
if (arg.cmd === apiCmds.registerActivityDetection) {
|
||||
// renderer window that has a registered activity detection from JS.
|
||||
activityDetection.setActivityWindow(arg.period, event.sender);
|
||||
}
|
||||
|
||||
if (arg.cmd === apiCmds.showNotificationSettings && typeof arg.windowName === 'string') {
|
||||
configureNotification.openConfigurationWindow(arg.windowName);
|
||||
}
|
||||
});
|
||||
|
||||
// expose these methods primarily for testing...
|
||||
|
||||
@@ -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 sanitize() {
|
||||
local.ipcRenderer.send(apiName, {
|
||||
cmd: apiCmds.setBadgeCount,
|
||||
count: 0
|
||||
cmd: apiCmds.sanitize,
|
||||
windowName: window.name
|
||||
});
|
||||
}
|
||||
|
||||
window.addEventListener('offline', updateOnlineStatus, false);
|
||||
window.addEventListener('online', updateOnlineStatus, false);
|
||||
window.addEventListener('beforeunload', resetBadgeCount, false);
|
||||
window.addEventListener('beforeunload', sanitize, false);
|
||||
|
||||
updateOnlineStatus();
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user