From 4e3947ab7e48fac843edeb1c91deb17f78706f97 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 22 Sep 2024 22:49:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D'=E9=94=81=E5=AE=9A=E5=B0=BA?= =?UTF-8?q?=E5=AF=B8'=E5=9C=A8=E6=9F=90=E4=BA=9B=E7=8A=B6=E5=86=B5?= =?UTF-8?q?=E4=B8=8B=E6=B2=A1=E6=9C=89=E6=88=90=E5=8A=9F=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/main/main/index.ts | 36 ++++++++++++++++++++++++++----- electron/main/setting/ipcEvent.ts | 8 +++++++ 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/electron/main/main/index.ts b/electron/main/main/index.ts index d202678..6d41445 100644 --- a/electron/main/main/index.ts +++ b/electron/main/main/index.ts @@ -67,11 +67,6 @@ function createMainWindow() { global.addon.removeWindowAnimation( mainWindow.getNativeWindowHandle().readInt32LE(0) ); - // 恢复上一次的位置 - let bounds = cacheData.cacheStore.get("mainWindowBounds"); - if (bounds) { - mainWindow.setBounds(bounds); - } // 永远居中不可移动 if (global.setting.general.alwaysCenter) { mainWindow.setMovable(false); @@ -82,8 +77,39 @@ function createMainWindow() { if (global.setting.general.alwaysTop) { mainWindow.setAlwaysOnTop(true, "screen-saver"); } + // 恢复上一次的位置 + let bounds: any = cacheData.cacheStore.get("mainWindowBounds"); // 锁定尺寸 mainWindow.setResizable(!global.setting.general.lockSize); + // 如果是锁定尺寸的话,使用锁定尺寸来设置窗口尺寸 + if (global.setting.general.lockSize) { + let lockSizeBounds: any = cacheData.cacheStore.get( + "mainWindowLockSizeBounds" + ); + if (lockSizeBounds) { + if (bounds) { + bounds.width = lockSizeBounds.width; + bounds.height = lockSizeBounds.height; + } else { + bounds = { + width: lockSizeBounds.width, + height: lockSizeBounds.height, + }; + } + } else { + if (bounds) { + cacheData.cacheStore.set("mainWindowLockSizeBounds", bounds); + } else { + cacheData.cacheStore.set( + "mainWindowLockSizeBounds", + mainWindow.getBounds() + ); + } + } + } + if (bounds) { + mainWindow.setBounds(bounds); + } // 托盘 createTray(!global.setting.general.hideTray); // 永远居中 diff --git a/electron/main/setting/ipcEvent.ts b/electron/main/setting/ipcEvent.ts index a9f37b9..88a67f7 100644 --- a/electron/main/setting/ipcEvent.ts +++ b/electron/main/setting/ipcEvent.ts @@ -16,6 +16,7 @@ import { statSync, mkdirSync, copyFileSync, readFileSync } from "node:fs"; import mime from "mime"; import { checkInvalid } from "../item"; import { updateItemOpenNumberSortToDefualt } from "../classification"; +import cacheData from "../commons/cacheData"; export default function () { // 创建设置窗口 @@ -91,6 +92,13 @@ export default function () { // 锁定尺寸 ipcMain.on("setLockSize", (event, args) => { global.mainWindow.setResizable(!args); + if (args) { + // 存储主窗口尺寸 + cacheData.cacheStore.set( + "mainWindowLockSizeBounds", + global.mainWindow.getBounds() + ); + } }); // 固定位置 ipcMain.on("setFixedPosition", (event, args) => {