From 739d1f2455de16c8fd536b73d19cb1cadfce43c5 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Tue, 28 Dec 2021 14:12:24 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E5=AE=A2=E6=88=B7=E7=AB=AF=E5=AD=90?= =?UTF-8?q?=E7=AA=97=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/main.js | 26 +++++++++++++++---- .../js/pages/manage/components/TaskDetail.vue | 2 +- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/electron/main.js b/electron/main.js index 78806c1a..5fc1f466 100644 --- a/electron/main.js +++ b/electron/main.js @@ -1,7 +1,7 @@ const fs = require('fs') const path = require('path') const XLSX = require('xlsx'); -const {app, BrowserWindow, ipcMain, dialog} = require('electron') +const {app, BrowserWindow, ipcMain, dialog, screen} = require('electron') let mainWindow = null, subWindow = [], @@ -176,7 +176,26 @@ ipcMain.on('windowSize', (event, args) => { const win = BrowserWindow.fromWebContents(event.sender); if (win) { if (args.width || args.height) { - win.setSize(args.width || win.getSize()[0], args.height || win.getSize()[1], args.animate === true) + let [w, h] = win.getSize() + const width = args.width || w + const height = args.height || h + win.setSize(width, height, args.animate === true) + // + if (args.autoZoom === true) { + let move = false + let [x, y] = win.getPosition() + if (Math.abs(width - w) > 10) { + move = true + x -= (width - w) / 2 + } + if (Math.abs(height - h) > 10) { + move = true + y -= (height - h) / 2 + } + if (move) { + win.setPosition(Math.max(0, Math.floor(x)), Math.max(0, Math.floor(y))) + } + } } if (args.minWidth || args.minHeight) { win.setMinimumSize(args.minWidth || win.getMinimumSize()[0], args.minHeight || win.getMinimumSize()[1]) @@ -184,9 +203,6 @@ ipcMain.on('windowSize', (event, args) => { if (args.maxWidth || args.maxHeight) { win.setMaximumSize(args.maxWidth || win.getMaximumSize()[0], args.maxHeight || win.getMaximumSize()[1]) } - if (args.center === true) { - win.center(); - } } event.returnValue = "ok" }) diff --git a/resources/assets/js/pages/manage/components/TaskDetail.vue b/resources/assets/js/pages/manage/components/TaskDetail.vue index 11deb56f..752abd18 100644 --- a/resources/assets/js/pages/manage/components/TaskDetail.vue +++ b/resources/assets/js/pages/manage/components/TaskDetail.vue @@ -1201,7 +1201,7 @@ export default { height: Math.max(720, window.innerHeight), minWidth: 800, minHeight: 600, - center: true, + autoZoom: true, }); if (this.msgText) { let num = 0;