Fixed isInsideRectangle to actually work, and removed null check for matchingScreen since it will always return something (#3093)
This commit is contained in:
parent
35665dee33
commit
2dee9b6bc8
|
@ -162,4 +162,19 @@ describe('main/utils', () => {
|
||||||
expect(Utils.shouldIncrementFilename('filename.txt')).toBe('filename (1).txt');
|
expect(Utils.shouldIncrementFilename('filename.txt')).toBe('filename (1).txt');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('isInsideRectangle', () => {
|
||||||
|
it.each([
|
||||||
|
[{x: 0, y: 0, width: 1920, height: 1080}, {x: 100, y: 100, width: 1280, height: 720}, true],
|
||||||
|
[{x: 0, y: 0, width: 1920, height: 1080}, {x: -100, y: 100, width: 1280, height: 720}, false],
|
||||||
|
[{x: 0, y: 0, width: 1920, height: 1080}, {x: 100, y: -100, width: 1280, height: 720}, false],
|
||||||
|
[{x: 0, y: 0, width: 1920, height: 1080}, {x: 100, y: 100, width: 2560, height: 720}, false],
|
||||||
|
[{x: 0, y: 0, width: 1920, height: 1080}, {x: 100, y: 100, width: 1280, height: 1440}, false],
|
||||||
|
[{x: -1920, y: 0, width: 1920, height: 1080}, {x: 100, y: 100, width: 1280, height: 720}, false],
|
||||||
|
[{x: -1920, y: 0, width: 1920, height: 1080}, {x: -1820, y: 100, width: 1280, height: 720}, true],
|
||||||
|
[{x: 0, y: -1080, width: 1920, height: 1080}, {x: 100, y: -980, width: 1280, height: 720}, true],
|
||||||
|
])('should match case', (a, b, expected) => {
|
||||||
|
expect(Utils.isInsideRectangle(a, b)).toBe(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -18,7 +18,23 @@ import Utils from 'common/utils/util';
|
||||||
import type {Args} from 'types/args';
|
import type {Args} from 'types/args';
|
||||||
|
|
||||||
export function isInsideRectangle(container: Electron.Rectangle, rect: Electron.Rectangle) {
|
export 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;
|
if (container.x > rect.x) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (container.x + container.width < rect.x + rect.width) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (container.y > rect.y) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (container.y + container.height < rect.y + rect.height) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function shouldBeHiddenOnStartup(parsedArgv: Args) {
|
export function shouldBeHiddenOnStartup(parsedArgv: Args) {
|
||||||
|
|
|
@ -254,8 +254,8 @@ export class MainWindow extends EventEmitter {
|
||||||
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);
|
const matchingScreen = screen.getDisplayMatching(savedWindowState);
|
||||||
log.debug('matching screen for main window', matchingScreen);
|
log.debug('closest matching screen for main window', matchingScreen);
|
||||||
if (!(matchingScreen && (isInsideRectangle(matchingScreen.bounds, savedWindowState) || savedWindowState.maximized))) {
|
if (!(isInsideRectangle(matchingScreen.bounds, savedWindowState) || savedWindowState.maximized)) {
|
||||||
throw new Error('Provided bounds info are outside the bounds of your screen, using defaults instead.');
|
throw new Error('Provided bounds info are outside the bounds of your screen, using defaults instead.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue