Files
SymphonyElectron/src/browser/main-api-handler.ts
T

118 lines
4.4 KiB
TypeScript
Raw Normal View History

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';
/**
* 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))) {
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:
if (typeof arg.count === 'number') {
2018-12-01 15:16:55 +05:30
console.log(arg.count);
showBadgeCount(arg.count);
}
break;
2018-12-01 15:16:55 +05:30
/*case ApiCmds.registerProtocolHandler:
protocolHandler.setProtocolWindow(event.sender);
protocolHandler.checkProtocolAction();
2018-12-01 15:16:55 +05:30
break;*/
case apiCmds.badgeDataUrl:
if (typeof arg.dataUrl === 'string' && typeof arg.count === 'number') {
2018-12-01 15:16:55 +05:30
setDataUrl(arg.dataUrl, arg.count);
}
break;
2018-12-01 15:16:55 +05:30
/*case ApiCmds.activate:
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:
// 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);
if (browserWin && !browserWin.isDestroyed()) {
2018-12-03 23:16:47 +05:30
const appMenu = windowHandler.getApplicationMenu();
if (appMenu) appMenu.popupMenu(browserWin);
}
break;
}
2018-12-03 23:16:47 +05:30
/*case ApiCmds.optimizeMemoryConsumption:
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:
}
});