ELECTRON-1401 - Fix issues with pop-out window restore (#738)

This commit is contained in:
Kiran Niranjan 2019-07-18 21:48:05 +05:30 committed by Vishwas Shashidhar
parent e5d86dc6d7
commit f47b606f9f
2 changed files with 37 additions and 2 deletions

View File

@ -8,7 +8,12 @@ import { logger } from '../common/logger';
import { getGuid } from '../common/utils';
import { whitelistHandler } from '../common/whitelist-handler';
import { config } from './config-handler';
import { handlePermissionRequests, monitorWindowActions, removeWindowEventListener } from './window-actions';
import {
handlePermissionRequests,
monitorWindowActions,
removeWindowEventListener,
sendInitialBoundChanges,
} from './window-actions';
import { ICustomBrowserWindow, windowHandler } from './window-handler';
import {
getBounds,
@ -163,6 +168,10 @@ export const handleChildWindow = (webContents: WebContents): void => {
// Monitor window actions
monitorWindowActions(browserWin);
// Update initial bound changes
sendInitialBoundChanges(browserWin);
// Remove all attached event listeners
browserWin.on('close', () => {
logger.info(`child-window-handler: close event occurred for window with url ${newWinUrl}!`);

View File

@ -23,12 +23,16 @@ const PERMISSIONS_NAMESPACE = 'Permissions';
const saveWindowSettings = async (): Promise<void> => {
const browserWindow = BrowserWindow.getFocusedWindow() as ICustomBrowserWindow;
const mainWindow = windowHandler.getMainWindow();
if (browserWindow && windowExists(browserWindow)) {
const [ x, y ] = browserWindow.getPosition();
const [ width, height ] = browserWindow.getSize();
if (x && y && width && height) {
browserWindow.webContents.send('boundsChange', { x, y, width, height, windowName: browserWindow.winName } as IBoundsChange);
// Only send bound changes over to client for pop-out windows
if (browserWindow.winName !== apiName.mainWindowName && mainWindow && windowExists(mainWindow)) {
mainWindow.webContents.send('boundsChange', { x, y, width, height, windowName: browserWindow.winName } as IBoundsChange);
}
// Update the config file
if (browserWindow.winName === apiName.mainWindowName) {
@ -64,6 +68,28 @@ const throttledWindowRestore = throttle(async () => {
notification.moveNotificationToTop();
}, 1000);
/**
* Sends initial bound changes for pop-out windows
*
* @param childWindow {BrowserWindow} - window created via new-window event
*/
export const sendInitialBoundChanges = (childWindow: BrowserWindow): void => {
logger.info(`window-actions: Sending initial bounds`);
const mainWindow = windowHandler.getMainWindow();
if (!mainWindow || !windowExists(mainWindow)) {
return;
}
if (!childWindow || !windowExists(childWindow)) {
logger.error(`window-actions: child window has already been destroyed - not sending bound change`);
return;
}
const { x, y, width, height } = childWindow.getBounds();
const windowName = (childWindow as ICustomBrowserWindow).winName;
mainWindow.webContents.send('boundsChange', { x, y, width, height, windowName } as IBoundsChange);
logger.info(`window-actions: Initial bounds sent for ${(childWindow as ICustomBrowserWindow).winName}`, { x, y, width, height });
};
/**
* Tries finding a window we have created with given name. If found, then
* brings to front and gives focus.