From 1225f508129a379f74dead0df2ab03991e56f3a7 Mon Sep 17 00:00:00 2001 From: Kiran Niranjan Date: Fri, 12 Jul 2019 15:19:10 +0530 Subject: [PATCH] ELECTRON-1380 - Fix pop-up menu position for native title bar (#724) --- src/app/window-handler.ts | 2 +- src/app/window-utils.ts | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/app/window-handler.ts b/src/app/window-handler.ts index 4b40b057..dce1ec5d 100644 --- a/src/app/window-handler.ts +++ b/src/app/window-handler.ts @@ -67,6 +67,7 @@ export class WindowHandler { public url: string | undefined; public willQuitApp: boolean = false; public spellchecker: SpellChecker | undefined; + public isCustomTitleBar: boolean; private readonly contextIsolation: boolean; private readonly backgroundThrottling: boolean; @@ -75,7 +76,6 @@ export class WindowHandler { private readonly config: IConfig; // Window reference private readonly windows: object; - private readonly isCustomTitleBar: boolean; private loadFailError: string | undefined; private mainWindow: ICustomBrowserWindow | null = null; diff --git a/src/app/window-utils.ts b/src/app/window-utils.ts index 02df7a52..850f8c87 100644 --- a/src/app/window-utils.ts +++ b/src/app/window-utils.ts @@ -5,6 +5,7 @@ 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'; @@ -250,8 +251,9 @@ export const updateLocale = (locale: LocaleType): void => { */ export const showPopupMenu = (opts: Electron.PopupOptions): void => { const mainWindow = windowHandler.getMainWindow(); - if (mainWindow && !mainWindow.isDestroyed() && isValidWindow(mainWindow)) { - const { x, y } = mainWindow.isFullScreen() ? { x: 0, y: 0 } : { x: 20, y: 15 }; + if (mainWindow && windowExists(mainWindow) && isValidWindow(mainWindow) && mainWindow.winName === apiName.mainWindowName) { + 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 }; const appMenu = windowHandler.appMenu; if (appMenu) {