[MM-14135] allow negative window app positions (#1124)
* [MM-14135] allow negative positions to enable having the app on a monitor on the left of primary * remove logging
This commit is contained in:
29
src/main.js
29
src/main.js
@@ -1013,23 +1013,22 @@ function clearAppCache() {
|
||||
}
|
||||
}
|
||||
|
||||
function getValidWindowPosition(state, screen) {
|
||||
function isWithinDisplay(state, display) {
|
||||
// given a display, check if window is within it
|
||||
return (state.x > display.maxX || state.y > display.maxY || state.x < display.minX || state.y < display.minY);
|
||||
}
|
||||
|
||||
function getValidWindowPosition(state) {
|
||||
// Check if the previous position is out of the viewable area
|
||||
// (e.g. because the screen has been plugged off)
|
||||
const displays = screen.getAllDisplays();
|
||||
let minX = 0;
|
||||
let maxX = 0;
|
||||
let minY = 0;
|
||||
let maxY = 0;
|
||||
for (let i = 0; i < displays.length; i++) {
|
||||
const display = displays[i];
|
||||
maxX = Math.max(maxX, display.bounds.x + display.bounds.width);
|
||||
maxY = Math.max(maxY, display.bounds.y + display.bounds.height);
|
||||
minX = Math.min(minX, display.bounds.x);
|
||||
minY = Math.min(minY, display.bounds.y);
|
||||
}
|
||||
const boundaries = Utils.getDisplayBoundaries();
|
||||
const isDisplayed = boundaries.reduce(
|
||||
(prev, display) => {
|
||||
return prev || isWithinDisplay(state, display);
|
||||
},
|
||||
false);
|
||||
|
||||
if (state.x > maxX || state.y > maxY || state.x < minX || state.y < minY) {
|
||||
if (isDisplayed) {
|
||||
Reflect.deleteProperty(state, 'x');
|
||||
Reflect.deleteProperty(state, 'y');
|
||||
Reflect.deleteProperty(state, 'width');
|
||||
@@ -1048,7 +1047,7 @@ function resizeScreen(screen, browserWindow) {
|
||||
y: position[1],
|
||||
width: size[0],
|
||||
height: size[1],
|
||||
}, screen);
|
||||
});
|
||||
browserWindow.setPosition(validPosition.x || 0, validPosition.y || 0);
|
||||
}
|
||||
|
||||
|
@@ -7,9 +7,6 @@ import Utils from '../utils/util';
|
||||
const defaultOptions = {
|
||||
stripUnknown: true,
|
||||
};
|
||||
|
||||
const defaultMinWindowXPos = -100;
|
||||
const defaultMinWindowYPos = -100;
|
||||
const defaultWindowWidth = 1000;
|
||||
const defaultWindowHeight = 700;
|
||||
const minWindowWidth = 400;
|
||||
@@ -25,8 +22,8 @@ const argsSchema = Joi.object({
|
||||
});
|
||||
|
||||
const boundsInfoSchema = Joi.object({
|
||||
x: Joi.number().integer().min(defaultMinWindowXPos).default(0),
|
||||
y: Joi.number().integer().min(defaultMinWindowYPos).default(0),
|
||||
x: Joi.number().integer().default(0),
|
||||
y: Joi.number().integer().default(0),
|
||||
width: Joi.number().integer().min(minWindowWidth).required().default(defaultWindowWidth),
|
||||
height: Joi.number().integer().min(minWindowHeight).required().default(defaultWindowHeight),
|
||||
maximized: Joi.boolean().default(false),
|
||||
|
@@ -3,6 +3,7 @@
|
||||
// See LICENSE.txt for license information.
|
||||
import url from 'url';
|
||||
|
||||
import electron from 'electron';
|
||||
import {isUri, isHttpUri, isHttpsUri} from 'valid-url';
|
||||
|
||||
function getDomain(inputURL) {
|
||||
@@ -33,9 +34,27 @@ function isInternalURL(targetURL, currentURL, basename = '/') {
|
||||
return true;
|
||||
}
|
||||
|
||||
function getDisplayBoundaries() {
|
||||
const {screen} = electron;
|
||||
|
||||
const displays = screen.getAllDisplays();
|
||||
|
||||
return displays.map((display) => {
|
||||
return {
|
||||
maxX: display.workArea.x + display.workArea.width,
|
||||
maxY: display.workArea.y + display.workArea.height,
|
||||
minX: display.workArea.x,
|
||||
minY: display.workArea.y,
|
||||
maxWidth: display.workArea.width,
|
||||
maxHeight: display.workArea.height,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export default {
|
||||
getDomain,
|
||||
isValidURL,
|
||||
isValidURI,
|
||||
isInternalURL,
|
||||
getDisplayBoundaries,
|
||||
};
|
||||
|
Reference in New Issue
Block a user