2018-12-01 15:16:55 +05:30
|
|
|
import { BrowserWindow, ipcMain } from 'electron';
|
2018-10-05 17:34:19 +05:30
|
|
|
|
2018-11-20 21:52:35 +05:30
|
|
|
import { apiCmds, apiName, IApiArgs } from '../common/api-interface';
|
|
|
|
|
import { logger } from '../common/logger';
|
2018-12-01 15:16:55 +05:30
|
|
|
import { windowHandler } from './window-handler';
|
2018-12-03 23:16:47 +05:30
|
|
|
import { isValidWindow, setDataUrl, showBadgeCount } from './window-utils';
|
2018-10-06 23:39:01 +05:30
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handle API related ipc messages from renderers. Only messages from windows
|
|
|
|
|
* we have created are allowed.
|
|
|
|
|
*/
|
|
|
|
|
ipcMain.on(apiName.symphonyApi, (event: Electron.Event, arg: IApiArgs) => {
|
2018-12-03 23:16:47 +05:30
|
|
|
if (!isValidWindow(BrowserWindow.fromWebContents(event.sender))) {
|
2018-10-06 23:39:01 +05:30
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!arg) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (arg.cmd) {
|
|
|
|
|
/*case ApiCmds.isOnline:
|
|
|
|
|
if (typeof arg.isOnline === 'boolean') {
|
|
|
|
|
windowMgr.setIsOnline(arg.isOnline);
|
|
|
|
|
}
|
2018-12-01 15:16:55 +05:30
|
|
|
break;*/
|
|
|
|
|
case apiCmds.setBadgeCount:
|
2018-10-06 23:39:01 +05:30
|
|
|
if (typeof arg.count === 'number') {
|
2018-12-01 15:16:55 +05:30
|
|
|
console.log(arg.count);
|
|
|
|
|
showBadgeCount(arg.count);
|
2018-10-06 23:39:01 +05:30
|
|
|
}
|
|
|
|
|
break;
|
2018-12-01 15:16:55 +05:30
|
|
|
/*case ApiCmds.registerProtocolHandler:
|
2018-10-06 23:39:01 +05:30
|
|
|
protocolHandler.setProtocolWindow(event.sender);
|
|
|
|
|
protocolHandler.checkProtocolAction();
|
2018-12-01 15:16:55 +05:30
|
|
|
break;*/
|
|
|
|
|
case apiCmds.badgeDataUrl:
|
2018-10-06 23:39:01 +05:30
|
|
|
if (typeof arg.dataUrl === 'string' && typeof arg.count === 'number') {
|
2018-12-01 15:16:55 +05:30
|
|
|
setDataUrl(arg.dataUrl, arg.count);
|
2018-10-06 23:39:01 +05:30
|
|
|
}
|
|
|
|
|
break;
|
2018-12-01 15:16:55 +05:30
|
|
|
/*case ApiCmds.activate:
|
2018-10-06 23:39:01 +05:30
|
|
|
if (typeof arg.windowName === 'string') {
|
|
|
|
|
windowMgr.activate(arg.windowName);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case ApiCmds.registerBoundsChange:
|
|
|
|
|
windowMgr.setBoundsChangeWindow(event.sender);
|
|
|
|
|
break;*/
|
2018-11-20 21:52:35 +05:30
|
|
|
case apiCmds.registerLogger:
|
2018-10-06 23:39:01 +05:30
|
|
|
// renderer window that has a registered logger from JS.
|
|
|
|
|
logger.setLoggerWindow(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;
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case ApiCmds.openScreenPickerWindow:
|
|
|
|
|
if (Array.isArray(arg.sources) && typeof arg.id === 'number') {
|
|
|
|
|
openScreenPickerWindow(event.sender, arg.sources, arg.id);
|
|
|
|
|
}
|
2018-12-03 23:16:47 +05:30
|
|
|
break;*/
|
|
|
|
|
case apiCmds.popupMenu: {
|
|
|
|
|
const browserWin = BrowserWindow.fromWebContents(event.sender);
|
2018-10-06 23:39:01 +05:30
|
|
|
if (browserWin && !browserWin.isDestroyed()) {
|
2018-12-03 23:16:47 +05:30
|
|
|
const appMenu = windowHandler.getApplicationMenu();
|
|
|
|
|
if (appMenu) appMenu.popupMenu(browserWin);
|
2018-10-06 23:39:01 +05:30
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2018-12-03 23:16:47 +05:30
|
|
|
/*case ApiCmds.optimizeMemoryConsumption:
|
2018-10-06 23:39:01 +05:30
|
|
|
if (typeof arg.memory === 'object'
|
|
|
|
|
&& typeof arg.cpuUsage === 'object'
|
|
|
|
|
&& typeof arg.memory.workingSetSize === 'number') {
|
|
|
|
|
setPreloadMemoryInfo(arg.memory, arg.cpuUsage);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case ApiCmds.optimizeMemoryRegister:
|
|
|
|
|
setPreloadWindow(event.sender);
|
|
|
|
|
break;
|
|
|
|
|
case ApiCmds.setIsInMeeting:
|
|
|
|
|
if (typeof arg.isInMeeting === 'boolean') {
|
|
|
|
|
setIsInMeeting(arg.isInMeeting);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case ApiCmds.setLocale:
|
|
|
|
|
if (typeof arg.locale === 'string') {
|
|
|
|
|
let browserWin = electron.BrowserWindow.fromWebContents(event.sender);
|
|
|
|
|
windowMgr.setLocale(browserWin, { language: arg.locale });
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case ApiCmds.keyPress:
|
|
|
|
|
if (typeof arg.keyCode === 'number') {
|
|
|
|
|
windowMgr.handleKeyPress(arg.keyCode);
|
|
|
|
|
}
|
|
|
|
|
break;*/
|
|
|
|
|
default:
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|