fix: ELECTRON-1380 (Show pop-up menu only on main window) (#732)

* ELECTRON-1380 - Show pop-up menu only on main window

* ELECTRON-1380 - Fix unit tests
This commit is contained in:
Kiran Niranjan 2019-07-16 10:59:50 +05:30 committed by Vishwas Shashidhar
parent 2c207e9aeb
commit 7a1ded34b2
4 changed files with 9 additions and 7 deletions

View File

@ -55,6 +55,7 @@ jest.mock('../src/app/window-utils', () => {
showBadgeCount: jest.fn(), showBadgeCount: jest.fn(),
showPopupMenu: jest.fn(), showPopupMenu: jest.fn(),
updateLocale: jest.fn(), updateLocale: jest.fn(),
windowExists: jest.fn( () => true),
}; };
}); });
@ -243,6 +244,7 @@ describe('main api handler', () => {
it('should call `popupMenu` correctly', () => { it('should call `popupMenu` correctly', () => {
const fromWebContentsMocked = { const fromWebContentsMocked = {
isDestroyed: jest.fn(), isDestroyed: jest.fn(),
winName: apiName.mainWindowName,
}; };
const spy = jest.spyOn(utils, 'showPopupMenu'); const spy = jest.spyOn(utils, 'showPopupMenu');
const value = { const value = {

View File

@ -10,7 +10,7 @@ import { memoryMonitor } from './memory-monitor';
import { protocolHandler } from './protocol-handler'; import { protocolHandler } from './protocol-handler';
import { screenSnippet } from './screen-snippet-handler'; import { screenSnippet } from './screen-snippet-handler';
import { activate, handleKeyPress } from './window-actions'; import { activate, handleKeyPress } from './window-actions';
import { windowHandler } from './window-handler'; import { ICustomBrowserWindow, windowHandler } from './window-handler';
import { import {
downloadManagerAction, downloadManagerAction,
isValidWindow, isValidWindow,
@ -19,6 +19,7 @@ import {
showBadgeCount, showBadgeCount,
showPopupMenu, showPopupMenu,
updateLocale, updateLocale,
windowExists,
} from './window-utils'; } from './window-utils';
/** /**
@ -94,8 +95,8 @@ ipcMain.on(apiName.symphonyApi, (event: Electron.Event, arg: IApiArgs) => {
} }
break; break;
case apiCmds.popupMenu: { case apiCmds.popupMenu: {
const browserWin = BrowserWindow.fromWebContents(event.sender); const browserWin = BrowserWindow.fromWebContents(event.sender) as ICustomBrowserWindow;
if (browserWin && !browserWin.isDestroyed()) { if (browserWin && windowExists(browserWin) && browserWin.winName === apiName.mainWindowName) {
showPopupMenu({ window: browserWin }); showPopupMenu({ window: browserWin });
} }
break; break;

View File

@ -149,8 +149,8 @@ export const handleKeyPress = (key: number): void => {
if (isMac) { if (isMac) {
return; return;
} }
const browserWin = BrowserWindow.getFocusedWindow(); const browserWin = BrowserWindow.getFocusedWindow() as ICustomBrowserWindow;
if (browserWin && !browserWin.isDestroyed()) { if (browserWin && windowExists(browserWin) && browserWin.winName === apiName.mainWindowName) {
logger.info(`window-actions: popping up menu by alt key action`); logger.info(`window-actions: popping up menu by alt key action`);
showPopupMenu({ window: browserWin }); showPopupMenu({ window: browserWin });
} }

View File

@ -5,7 +5,6 @@ import * as filesize from 'filesize';
import * as fs from 'fs'; import * as fs from 'fs';
import * as path from 'path'; import * as path from 'path';
import { format, parse } from 'url'; import { format, parse } from 'url';
import { apiName } from '../common/api-interface';
import { isDevEnv, isMac } from '../common/env'; import { isDevEnv, isMac } from '../common/env';
import { i18n, LocaleType } from '../common/i18n'; import { i18n, LocaleType } from '../common/i18n';
@ -252,7 +251,7 @@ export const updateLocale = (locale: LocaleType): void => {
*/ */
export const showPopupMenu = (opts: Electron.PopupOptions): void => { export const showPopupMenu = (opts: Electron.PopupOptions): void => {
const mainWindow = windowHandler.getMainWindow(); const mainWindow = windowHandler.getMainWindow();
if (mainWindow && windowExists(mainWindow) && isValidWindow(mainWindow) && mainWindow.winName === apiName.mainWindowName) { if (mainWindow && windowExists(mainWindow) && isValidWindow(mainWindow)) {
const coordinates = windowHandler.isCustomTitleBar ? { x: 20, y: 15 } : { x: 10, y: -20 }; const coordinates = windowHandler.isCustomTitleBar ? { x: 20, y: 15 } : { x: 10, y: -20 };
const { x, y } = mainWindow.isFullScreen() ? { x: 0, y: 0 } : coordinates; const { x, y } = mainWindow.isFullScreen() ? { x: 0, y: 0 } : coordinates;
const popupOpts = { window: mainWindow, x, y }; const popupOpts = { window: mainWindow, x, y };