[MM-38607] Ensure window is inside one of the screen bounds before rendering (#1769)
This commit is contained in:
parent
a48c469005
commit
a3d7f0518e
|
@ -6,7 +6,7 @@ import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
|
|
||||||
import {app, BrowserWindow, BrowserWindowConstructorOptions, globalShortcut, ipcMain} from 'electron';
|
import {app, BrowserWindow, BrowserWindowConstructorOptions, globalShortcut, ipcMain, screen} from 'electron';
|
||||||
import log from 'electron-log';
|
import log from 'electron-log';
|
||||||
|
|
||||||
import {CombinedConfig} from 'types/config';
|
import {CombinedConfig} from 'types/config';
|
||||||
|
@ -32,6 +32,10 @@ function saveWindowState(file: string, window: BrowserWindow) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isInsideRectangle(container: Electron.Rectangle, rect: Electron.Rectangle) {
|
||||||
|
return container.x <= rect.x && container.y <= rect.y && container.width >= rect.width && container.height >= rect.height;
|
||||||
|
}
|
||||||
|
|
||||||
function isFramelessWindow() {
|
function isFramelessWindow() {
|
||||||
return os.platform() === 'darwin' || (os.platform() === 'win32' && os.release().startsWith('10'));
|
return os.platform() === 'darwin' || (os.platform() === 'win32' && os.release().startsWith('10'));
|
||||||
}
|
}
|
||||||
|
@ -46,6 +50,10 @@ function createMainWindow(config: CombinedConfig, options: {linuxAppIcon: string
|
||||||
if (!savedWindowState) {
|
if (!savedWindowState) {
|
||||||
throw new Error('Provided bounds info file does not validate, using defaults instead.');
|
throw new Error('Provided bounds info file does not validate, using defaults instead.');
|
||||||
}
|
}
|
||||||
|
const matchingScreen = screen.getDisplayMatching(savedWindowState);
|
||||||
|
if (!(matchingScreen && (isInsideRectangle(matchingScreen.bounds, savedWindowState) || savedWindowState.maximized))) {
|
||||||
|
throw new Error('Provided bounds info are outside the bounds of your screen, using defaults instead.');
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Follow Electron's defaults, except for window dimensions which targets 1024x768 screen resolution.
|
// Follow Electron's defaults, except for window dimensions which targets 1024x768 screen resolution.
|
||||||
savedWindowState = {width: DEFAULT_WINDOW_WIDTH, height: DEFAULT_WINDOW_HEIGHT};
|
savedWindowState = {width: DEFAULT_WINDOW_WIDTH, height: DEFAULT_WINDOW_HEIGHT};
|
||||||
|
|
Loading…
Reference in a new issue