Fix some issues caused by i18n addition (#2209)
* Fix some issues caused by i18n addition * Couple more small changes
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
import fs from 'fs-extra';
|
||||
|
||||
import {dialog} from 'electron';
|
||||
import {dialog, screen} from 'electron';
|
||||
|
||||
import Config from 'common/config';
|
||||
import JsonFileManager from 'common/JsonFileManager';
|
||||
@@ -34,6 +34,9 @@ jest.mock('electron', () => ({
|
||||
showOpenDialogSync: jest.fn(),
|
||||
showMessageBoxSync: jest.fn(),
|
||||
},
|
||||
screen: {
|
||||
getAllDisplays: jest.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
jest.mock('common/config', () => ({
|
||||
@@ -42,7 +45,6 @@ jest.mock('common/config', () => ({
|
||||
jest.mock('common/JsonFileManager');
|
||||
jest.mock('common/utils/util', () => ({
|
||||
isVersionGreaterThanOrEqualTo: jest.fn(),
|
||||
getDisplayBoundaries: jest.fn(),
|
||||
}));
|
||||
|
||||
jest.mock('main/autoUpdater', () => ({}));
|
||||
@@ -182,13 +184,13 @@ describe('main/app/utils', () => {
|
||||
|
||||
describe('resizeScreen', () => {
|
||||
beforeEach(() => {
|
||||
Utils.getDisplayBoundaries.mockReturnValue([{
|
||||
minX: 400,
|
||||
minY: 300,
|
||||
maxX: 2320,
|
||||
maxY: 1380,
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
screen.getAllDisplays.mockReturnValue([{
|
||||
workArea: {
|
||||
x: 400,
|
||||
y: 300,
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
},
|
||||
}]);
|
||||
});
|
||||
it('should keep the same position if it is within a display', () => {
|
||||
|
@@ -5,7 +5,7 @@ import path from 'path';
|
||||
|
||||
import fs from 'fs-extra';
|
||||
|
||||
import {app, BrowserWindow, Menu, Rectangle, Session, session, dialog, nativeImage} from 'electron';
|
||||
import {app, BrowserWindow, Menu, Rectangle, Session, session, dialog, nativeImage, screen} from 'electron';
|
||||
import log, {LevelOption} from 'electron-log';
|
||||
|
||||
import {MigrationInfo, TeamWithTabs} from 'types/config';
|
||||
@@ -147,10 +147,25 @@ function isWithinDisplay(state: Rectangle, display: Boundaries) {
|
||||
return !(midX > display.maxX || midY > display.maxY);
|
||||
}
|
||||
|
||||
function getDisplayBoundaries() {
|
||||
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,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function getValidWindowPosition(state: Rectangle) {
|
||||
// Check if the previous position is out of the viewable area
|
||||
// (e.g. because the screen has been plugged off)
|
||||
const boundaries = Utils.getDisplayBoundaries();
|
||||
const boundaries = getDisplayBoundaries();
|
||||
const display = boundaries.find((boundary) => {
|
||||
return isWithinDisplay(state, boundary);
|
||||
});
|
||||
|
Reference in New Issue
Block a user