From 3fca7d16bbd998bf0a6afe08cb12bdfbfd2fdbd8 Mon Sep 17 00:00:00 2001 From: memorydream <34763046+memorydream@users.noreply.github.com> Date: Mon, 4 Apr 2022 22:06:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20APP=E5=90=AF=E5=8A=A8=E6=97=B6=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E7=AA=97=E5=8F=A3=E4=BD=8D=E7=BD=AE=EF=BC=8C=E9=81=BF?= =?UTF-8?q?=E5=85=8D=E7=AA=97=E5=8F=A3=E5=90=AF=E5=8A=A8=E5=9C=A8=E5=B1=8F?= =?UTF-8?q?=E5=B9=95=E5=A4=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/background.js | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/background.js b/src/background.js index 276d790..aa33918 100644 --- a/src/background.js +++ b/src/background.js @@ -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 => {