|
@@ -1,4 +1,4 @@
|
|
|
-import { BrowserWindow, screen } from "electron";
|
|
|
+import { BrowserWindow, ipcMain, screen } from "electron";
|
|
|
import { join } from "node:path";
|
|
|
import { ICON, DIST, preload, url } from "../main/utils";
|
|
|
import log from "electron-log/main";
|
|
@@ -41,6 +41,12 @@ const createWindow = (): BrowserWindow => {
|
|
|
// webSecurity: false,
|
|
|
},
|
|
|
});
|
|
|
+ ipcMain.handle("get-window-info", async (event) => {
|
|
|
+ const [width] = mainWindow?.getSize() || [0, 0]; // 获取当前窗口宽度
|
|
|
+ const display = screen.getPrimaryDisplay();
|
|
|
+ const scaleFactor = display.scaleFactor; // 缩放因子,例如 1.5
|
|
|
+ return { width, scaleFactor }; // 返回宽度值
|
|
|
+ });
|
|
|
|
|
|
mainWindow.setMenu(null); // 去掉顶部菜单
|
|
|
// log.info("Log from the main process");
|
|
@@ -118,10 +124,15 @@ function middleMainWin() {
|
|
|
if (mainWindow?.isMaximized()) {
|
|
|
mainWindow.unmaximize();
|
|
|
}
|
|
|
-
|
|
|
- const { width } = screen.getPrimaryDisplay().workAreaSize;
|
|
|
- const currentWidth = mainWindow?.getBounds().width;
|
|
|
- if (currentWidth && currentWidth > 420) {
|
|
|
+ const display = screen.getPrimaryDisplay();
|
|
|
+ const { width } = display.workAreaSize; // 逻辑像素
|
|
|
+ const scaleFactor = display.scaleFactor; // 缩放因子,例如 1.5
|
|
|
+ let currentWidth = mainWindow?.getBounds().width || 0;
|
|
|
+ const winSys = process.platform === "win32";
|
|
|
+
|
|
|
+ const baseWidth = winSys ? 420 * scaleFactor : 420;
|
|
|
+
|
|
|
+ if (currentWidth && currentWidth > baseWidth) {
|
|
|
mainWindow?.setBounds({
|
|
|
width: 420,
|
|
|
x: width - 420,
|