Typescript - Fix main window position calculation logic (#643)

This commit is contained in:
Kiran Niranjan 2019-05-13 12:25:13 +05:30 committed by Vishwas Shashidhar
parent 5adc162b2e
commit 5e5455157a
3 changed files with 6 additions and 6 deletions

View File

@ -39,7 +39,7 @@ export interface IConfig {
permissions: IPermission;
customFlags: ICustomFlag;
crashReporter: ICrashReporter;
mainWinPos: ICustomRectangle;
mainWinPos?: ICustomRectangle;
}
export interface IPermission {
@ -69,7 +69,7 @@ export interface INotificationSetting {
display: string;
}
export interface ICustomRectangle extends Electron.Rectangle {
export interface ICustomRectangle extends Partial<Electron.Rectangle> {
isMaximized: boolean;
isFullScreen: boolean;
}

View File

@ -232,7 +232,7 @@ export class WindowHandler {
...this.windowOpts, ...getBounds(this.config.mainWinPos, DEFAULT_WIDTH, DEFAULT_HEIGHT),
}) as ICustomBrowserWindow;
this.mainWindow.winName = apiName.mainWindowName;
const { isFullScreen, isMaximized } = this.config.mainWinPos;
const { isFullScreen, isMaximized } = this.config.mainWinPos ? this.config.mainWinPos : { isFullScreen: false, isMaximized: false };
if (isMaximized) {
this.mainWindow.maximize();
}

View File

@ -11,7 +11,7 @@ import { i18n, LocaleType } from '../common/i18n';
import { logger } from '../common/logger';
import { getGuid } from '../common/utils';
import { whitelistHandler } from '../common/whitelist-handler';
import { config } from './config-handler';
import { config, ICustomRectangle } from './config-handler';
import { screenSnippet } from './screen-snippet-handler';
import { ICustomBrowserWindow, windowHandler } from './window-handler';
@ -286,8 +286,8 @@ export const sanitize = async (windowName: string): Promise<void> => {
* @param defaultHeight
* @return {x?: Number, y?: Number, width: Number, height: Number}
*/
export const getBounds = (winPos: Electron.Rectangle, defaultWidth: number, defaultHeight: number): Partial<Electron.Rectangle> => {
if (!winPos) {
export const getBounds = (winPos: ICustomRectangle | Electron.Rectangle | undefined, defaultWidth: number, defaultHeight: number): Partial<Electron.Rectangle> => {
if (!winPos || !winPos.x || !winPos.y || !winPos.width || !winPos.height) {
return { width: defaultWidth, height: defaultHeight };
}
const displays = electron.screen.getAllDisplays();