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';
|
2018-12-04 12:16:38 +05:30
|
|
|
import { LocaleType } from '../common/i18n';
|
2018-11-20 21:52:35 +05:30
|
|
|
import { logger } from '../common/logger';
|
2018-12-04 19:35:58 +05:30
|
|
|
import { activityDetection } from './activity-detection';
|
2018-12-05 21:35:27 +05:30
|
|
|
import { screenSnippet } from './screen-snippet';
|
|
|
|
|
import { isValidWindow, setDataUrl, showBadgeCount, showPopupMenu, updateLocale } 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;
|
2018-12-04 19:35:58 +05:30
|
|
|
case apiCmds.registerActivityDetection:
|
2018-10-06 23:39:01 +05:30
|
|
|
if (typeof arg.period === 'number') {
|
|
|
|
|
// renderer window that has a registered activity detection from JS.
|
2018-12-04 19:35:58 +05:30
|
|
|
activityDetection.setWindowAndThreshold(event.sender, arg.period);
|
2018-10-06 23:39:01 +05:30
|
|
|
}
|
|
|
|
|
break;
|
2018-12-04 19:35:58 +05:30
|
|
|
/*case ApiCmds.showNotificationSettings:
|
2018-10-06 23:39:01 +05:30
|
|
|
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-04 15:57:23 +05:30
|
|
|
showPopupMenu({ window: 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);
|
|
|
|
|
}
|
2018-12-04 12:16:38 +05:30
|
|
|
break;*/
|
|
|
|
|
case apiCmds.setLocale:
|
2018-10-06 23:39:01 +05:30
|
|
|
if (typeof arg.locale === 'string') {
|
2018-12-04 12:16:38 +05:30
|
|
|
updateLocale(arg.locale as LocaleType);
|
2018-10-06 23:39:01 +05:30
|
|
|
}
|
|
|
|
|
break;
|
2018-12-04 12:16:38 +05:30
|
|
|
/*case ApiCmds.keyPress:
|
2018-10-06 23:39:01 +05:30
|
|
|
if (typeof arg.keyCode === 'number') {
|
|
|
|
|
windowMgr.handleKeyPress(arg.keyCode);
|
|
|
|
|
}
|
|
|
|
|
break;*/
|
2018-12-05 21:35:27 +05:30
|
|
|
case apiCmds.openScreenSnippet:
|
|
|
|
|
screenSnippet.capture(event.sender);
|
2018-10-06 23:39:01 +05:30
|
|
|
default:
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|