mirror of
https://github.com/finos/SymphonyElectron.git
synced 2024-12-31 19:27:00 -06:00
Electron-228 - Changed the event name and optimized code
This commit is contained in:
parent
20e1f0b6ca
commit
ad700f2d82
@ -16,7 +16,7 @@ const cmds = keyMirror({
|
|||||||
registerProtocolHandler: null,
|
registerProtocolHandler: null,
|
||||||
registerActivityDetection: null,
|
registerActivityDetection: null,
|
||||||
showNotificationSettings: null,
|
showNotificationSettings: null,
|
||||||
reload: null
|
sanitize: null
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -54,7 +54,7 @@ function isValidWindow(event) {
|
|||||||
* window.addEventListener('beforeunload')
|
* window.addEventListener('beforeunload')
|
||||||
* @param windowName
|
* @param windowName
|
||||||
*/
|
*/
|
||||||
function reload(windowName) {
|
function sanitize(windowName) {
|
||||||
// To make sure the reload event is from the main window
|
// To make sure the reload event is from the main window
|
||||||
if (windowMgr.getMainWindow() && windowName === windowMgr.getMainWindow().winName) {
|
if (windowMgr.getMainWindow() && windowName === windowMgr.getMainWindow().winName) {
|
||||||
// reset the badge count whenever an user refreshes the electron client
|
// reset the badge count whenever an user refreshes the electron client
|
||||||
@ -80,53 +80,57 @@ electron.ipcMain.on(apiName, (event, arg) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arg.cmd === apiCmds.isOnline && typeof arg.isOnline === 'boolean') {
|
switch(arg.cmd) {
|
||||||
windowMgr.setIsOnline(arg.isOnline);
|
case apiCmds.isOnline:
|
||||||
return;
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (arg.cmd === apiCmds.reload && typeof arg.windowName === 'string') {
|
|
||||||
reload(arg.windowName);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// expose these methods primarily for testing...
|
// expose these methods primarily for testing...
|
||||||
|
@ -368,16 +368,16 @@ function createAPI() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Invoked whenever the app is reloaded/navigated
|
// Invoked whenever the app is reloaded/navigated
|
||||||
function reload() {
|
function sanitize() {
|
||||||
local.ipcRenderer.send(apiName, {
|
local.ipcRenderer.send(apiName, {
|
||||||
cmd: apiCmds.reload,
|
cmd: apiCmds.sanitize,
|
||||||
windowName: window.name
|
windowName: window.name
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener('offline', updateOnlineStatus, false);
|
window.addEventListener('offline', updateOnlineStatus, false);
|
||||||
window.addEventListener('online', updateOnlineStatus, false);
|
window.addEventListener('online', updateOnlineStatus, false);
|
||||||
window.addEventListener('beforeunload', reload, false);
|
window.addEventListener('beforeunload', sanitize, false);
|
||||||
|
|
||||||
updateOnlineStatus();
|
updateOnlineStatus();
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user