fix: APP启动时检查窗口位置,避免窗口启动在屏幕外

master
memorydream 3 years ago committed by qier222
parent 7d64dea29b
commit 3fca7d16bb

@ -7,6 +7,7 @@ import {
dialog,
globalShortcut,
nativeTheme,
screen,
} from 'electron';
import {
isWindows,
@ -201,8 +202,42 @@ class Background {
};
if (this.store.get('window.x') && this.store.get('window.y')) {
options.x = this.store.get('window.x');
options.y = this.store.get('window.y');
let x = this.store.get('window.x');
let y = this.store.get('window.y');
let displays = screen.getAllDisplays();
let isResetWindiw = false;
if (displays.length === 1) {
let { bounds } = displays[0];
if (
x < bounds.x ||
x > bounds.x + bounds.width - 50 ||
y < bounds.y ||
y > bounds.y + bounds.height - 50
) {
isResetWindiw = true;
}
} else {
isResetWindiw = true;
for (let i = 0; i < displays.length; i++) {
let { bounds } = displays[i];
if (
x > bounds.x &&
x < bounds.x + bounds.width &&
y > bounds.y &&
y < bounds.y - bounds.height
) {
// 检测到APP窗口当前处于一个可用的屏幕里break
isResetWindiw = false;
break;
}
}
}
if (!isResetWindiw) {
options.x = x;
options.y = y;
}
}
this.window = new BrowserWindow(options);
@ -261,6 +296,7 @@ class Background {
this.window.once('ready-to-show', () => {
log('window ready-to-show event');
this.window.show();
this.store.set('window', this.window.getBounds());
});
this.window.on('close', e => {

Loading…
Cancel
Save