fix: SDA-1657 Maximized SDA saves co-ordinates (#844)

* sda-1657 printout of main windows position

* sda-1657 Save height, width, x, y for full screen/maximized

* sda-1657 Change from workArea to bounds because full screen use entire screen

* sda-1657 remove save of position and size as before

* sda-1657 keep track of the original position/size of window before it is maximized or full screen

* Fit in middle of immediate display

* Use the new width and height
This commit is contained in:
Johan Kwarnmark 2020-01-09 05:55:12 +01:00 committed by Vishwas Shashidhar
parent c63a2682e3
commit 068e6b5d44
3 changed files with 48 additions and 7 deletions

View File

@ -26,8 +26,8 @@ const saveWindowSettings = async (): Promise<void> => {
const mainWindow = windowHandler.getMainWindow();
if (browserWindow && windowExists(browserWindow)) {
const [ x, y ] = browserWindow.getPosition();
const [ width, height ] = browserWindow.getSize();
let [ x, y ] = browserWindow.getPosition();
let [ width, height ] = browserWindow.getSize();
if (x && y && width && height) {
// Only send bound changes over to client for pop-out windows
if (browserWindow.winName !== apiName.mainWindowName && mainWindow && windowExists(mainWindow)) {
@ -39,7 +39,18 @@ const saveWindowSettings = async (): Promise<void> => {
const isMaximized = browserWindow.isMaximized();
const isFullScreen = browserWindow.isFullScreen();
const { mainWinPos } = config.getUserConfigFields([ 'mainWinPos' ]);
await config.updateUserConfig({ mainWinPos: { ...mainWinPos, ...{ x, y, width, height, isMaximized, isFullScreen } } });
if (isMaximized || isFullScreen) {
// Keep the original size and position when window is maximized or full screen
if (mainWinPos !== undefined && mainWinPos.x !== undefined && mainWinPos.y !== undefined && mainWinPos.width !== undefined && mainWinPos.height !== undefined) {
x = mainWinPos.x;
y = mainWinPos.y;
width = mainWinPos.width;
height = mainWinPos.height;
}
}
await config.updateUserConfig({ mainWinPos: { ...mainWinPos, ...{ height, width, x, y, isMaximized, isFullScreen } } });
}
}
}

View File

@ -145,16 +145,20 @@ export class WindowHandler {
this.spellchecker = new SpellChecker();
logger.info(`window-handler: initialized spellchecker module with locale ${this.spellchecker.locale}`);
logger.info('window-handler: createApplication mainWinPos: ' + JSON.stringify(this.config.mainWinPos));
// set window opts with additional config
this.mainWindow = new BrowserWindow({
...this.windowOpts, ...getBounds(this.config.mainWinPos, DEFAULT_WIDTH, DEFAULT_HEIGHT),
}) as ICustomBrowserWindow;
this.mainWindow.winName = apiName.mainWindowName;
const {isFullScreen, isMaximized} = this.config.mainWinPos ? this.config.mainWinPos : {isFullScreen: false, isMaximized: false};
if (isMaximized) {
this.mainWindow.maximize();
logger.info(`window-handler: window is maximized!`);
}
if (isFullScreen) {
logger.info(`window-handler: window is in full screen!`);
this.mainWindow.setFullScreen(true);

View File

@ -301,19 +301,45 @@ export const sanitize = async (windowName: string): Promise<void> => {
* @return {x?: Number, y?: Number, width: Number, height: Number}
*/
export const getBounds = (winPos: ICustomRectangle | Electron.Rectangle | undefined, defaultWidth: number, defaultHeight: number): Partial<Electron.Rectangle> => {
logger.info('window-utils: getBounds, winPos: ' + JSON.stringify(winPos));
if (!winPos || !winPos.x || !winPos.y || !winPos.width || !winPos.height) {
return { width: defaultWidth, height: defaultHeight };
}
const displays = electron.screen.getAllDisplays();
for (let i = 0, len = displays.length; i < len; i++) {
const workArea = displays[ i ].workArea;
if (winPos.x >= workArea.x && winPos.y >= workArea.y &&
((winPos.x + winPos.width) <= (workArea.x + workArea.width)) &&
((winPos.y + winPos.height) <= (workArea.y + workArea.height))) {
const bounds = displays[ i ].bounds;
logger.info('window-utils: getBounds, bounds: ' + JSON.stringify(bounds));
if (winPos.x >= bounds.x && winPos.y >= bounds.y &&
((winPos.x + winPos.width) <= (bounds.x + bounds.width)) &&
((winPos.y + winPos.height) <= (bounds.y + bounds.height))) {
return winPos;
}
}
// Fit in the middle of immediate display
const display = electron.screen.getDisplayMatching(winPos as electron.Rectangle);
if (display) {
// Check that defaultWidth fits
let windowWidth = defaultWidth;
if (display.workArea.width < defaultWidth) {
windowWidth = display.workArea.width;
}
// Check that defaultHeight fits
let windowHeight = defaultHeight;
if (display.workArea.height < defaultHeight) {
windowHeight = display.workArea.height;
}
const windowX = display.workArea.x + display.workArea.width / 2 - windowWidth / 2;
const windowY = display.workArea.y + display.workArea.height / 2 - windowHeight / 2;
return { x: windowX, y: windowY, width: windowWidth, height: windowHeight };
}
return { width: defaultWidth, height: defaultHeight };
};