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(),
showPopupMenu: jest.fn(),
updateLocale: jest.fn(),
windowExists: jest.fn( () => true),
};
});
@ -243,6 +244,7 @@ describe('main api handler', () => {
it('should call `popupMenu` correctly', () => {
const fromWebContentsMocked = {
isDestroyed: jest.fn(),
winName: apiName.mainWindowName,
};
const spy = jest.spyOn(utils, 'showPopupMenu');
const value = {

View File

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

View File

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

View File

@ -5,7 +5,6 @@ import * as filesize from 'filesize';
import * as fs from 'fs';
import * as path from 'path';
import { format, parse } from 'url';
import { apiName } from '../common/api-interface';
import { isDevEnv, isMac } from '../common/env';
import { i18n, LocaleType } from '../common/i18n';
@ -252,7 +251,7 @@ export const updateLocale = (locale: LocaleType): void => {
*/
export const showPopupMenu = (opts: Electron.PopupOptions): void => {
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 { x, y } = mainWindow.isFullScreen() ? { x: 0, y: 0 } : coordinates;
const popupOpts = { window: mainWindow, x, y };