🐛 修复macOS平台的窗口大小适配逻辑

This commit is contained in:
BTMuli
2025-05-09 23:11:06 +08:00
parent 652a92a0da
commit 16332793ef
3 changed files with 22 additions and 12 deletions

View File

@@ -1,7 +1,7 @@
/**
* @file utils/TGWindow.ts
* @description 窗口创建相关工具函数
* @since Beta v0.7.4
* @since Beta v0.7.6
*/
import type { RenderCard } from "@comp/app/t-postcard.vue";
@@ -9,6 +9,7 @@ import showSnackbar from "@comp/func/snackbar.js";
import { core, webviewWindow, window as TauriWindow } from "@tauri-apps/api";
import { PhysicalSize } from "@tauri-apps/api/dpi";
import { currentMonitor, WindowOptions } from "@tauri-apps/api/window";
import { type } from "@tauri-apps/plugin-os";
import TGLogger from "./TGLogger.js";
@@ -102,7 +103,7 @@ export function getWindowSize(label: string): PhysicalSize {
/**
* @description 窗口适配
* @since Beta v0.7.4
* @since Beta v0.7.6
* @returns Promise<void>
*/
export async function resizeWindow(): Promise<void> {
@@ -116,12 +117,13 @@ export async function resizeWindow(): Promise<void> {
const designSize = getWindowSize(windowCur.label);
const widthScale = screen.size.width / 1920;
const heightScale = screen.size.height / 1080;
await windowCur.setSize(
new PhysicalSize(
Math.round((designSize.width * widthScale) / screen.scaleFactor),
Math.round((designSize.height * heightScale) / screen.scaleFactor),
),
);
let targetWidth = Math.round((designSize.width * widthScale) / screen.scaleFactor);
let targetHeight = Math.round((designSize.height * heightScale) / screen.scaleFactor);
if (type() === "macos") {
targetWidth = Math.round(designSize.width * widthScale);
targetHeight = Math.round(designSize.height * heightScale);
}
await windowCur.setSize(new PhysicalSize(targetWidth, targetHeight));
await windowCur.setZoom((1 / screen.scaleFactor) * Math.min(widthScale, heightScale));
await windowCur.setFocus();
}