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

131 lines
4.6 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 { 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 { windowHandler } from './window-handler';
import {
isValidWindow,
sanitize,
setDataUrl,
showBadgeCount,
showPopupMenu,
updateLocale,
} 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
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;
2018-12-04 19:35:58 +05:30
case apiCmds.registerActivityDetection:
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);
}
break;
2018-12-04 19:35:58 +05:30
/*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') {
windowHandler.createScreenPickerWindow(event.sender, arg.sources, arg.id);
}
break;
2018-12-03 23:16:47 +05:30
case apiCmds.popupMenu: {
const browserWin = BrowserWindow.fromWebContents(event.sender);
if (browserWin && !browserWin.isDestroyed()) {
showPopupMenu({ window: 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') {
updateLocale(arg.locale as LocaleType);
}
break;
/*case ApiCmds.keyPress:
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);
break;
case apiCmds.closeWindow:
windowHandler.closeWindow(arg.windowType);
break;
default:
}
});