mirror of
https://github.com/GiriNeko/YesPlayMusic.git
synced 2025-12-16 13:17:46 +00:00
fix: APP启动时检查窗口位置,避免窗口启动在屏幕外
This commit is contained in:
parent
7d64dea29b
commit
3fca7d16bb
1 changed files with 38 additions and 2 deletions
|
|
@ -7,6 +7,7 @@ import {
|
||||||
dialog,
|
dialog,
|
||||||
globalShortcut,
|
globalShortcut,
|
||||||
nativeTheme,
|
nativeTheme,
|
||||||
|
screen,
|
||||||
} from 'electron';
|
} from 'electron';
|
||||||
import {
|
import {
|
||||||
isWindows,
|
isWindows,
|
||||||
|
|
@ -201,8 +202,42 @@ class Background {
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.store.get('window.x') && this.store.get('window.y')) {
|
if (this.store.get('window.x') && this.store.get('window.y')) {
|
||||||
options.x = this.store.get('window.x');
|
let x = this.store.get('window.x');
|
||||||
options.y = this.store.get('window.y');
|
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);
|
this.window = new BrowserWindow(options);
|
||||||
|
|
@ -261,6 +296,7 @@ class Background {
|
||||||
this.window.once('ready-to-show', () => {
|
this.window.once('ready-to-show', () => {
|
||||||
log('window ready-to-show event');
|
log('window ready-to-show event');
|
||||||
this.window.show();
|
this.window.show();
|
||||||
|
this.store.set('window', this.window.getBounds());
|
||||||
});
|
});
|
||||||
|
|
||||||
this.window.on('close', e => {
|
this.window.on('close', e => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue