diff --git a/src-tauri/src/client/utils.rs b/src-tauri/src/client/utils.rs index 3041f8b0..34d06754 100644 --- a/src-tauri/src/client/utils.rs +++ b/src-tauri/src/client/utils.rs @@ -1,6 +1,6 @@ //! @file src/client/utils.rs //! @desc 结合屏幕分辨率获取窗口大小 -//! @since Beta v0.5.5 +//! @since Beta v0.7.6 use tauri::{AppHandle, Manager, Monitor}; @@ -17,7 +17,15 @@ pub fn get_window_size2(monitor: Monitor, width: f64, height: f64) -> (f64, f64) let monitor_scale = monitor.scale_factor(); let width_scale = monitor_width / 1920.0; let height_scale = monitor_height / 1080.0; - let get_width = (width * width_scale / monitor_scale).round(); - let get_height = (height * height_scale / monitor_scale).round(); + let mut get_width: f64 = 0.0; + let mut get_height: f64 = 0.0; + dbg!(get_width, get_height); // 防止never read + get_width = (width * width_scale / monitor_scale).round(); + get_height = (height * height_scale / monitor_scale).round(); + #[cfg(target_os = "macos")] + { + get_width = (width * width_scale).round(); + get_height = (height * height_scale).round(); + } (get_width, get_height) } diff --git a/src/App.vue b/src/App.vue index fed412c3..ff5d8ff9 100644 --- a/src/App.vue +++ b/src/App.vue @@ -60,7 +60,7 @@ onMounted(async () => { document.documentElement.className = theme.value; }); resizeListener = await event.listen("needResize", async (e: Event) => { - console.log(needResize); + console.log(needResize.value); const windowCur = webviewWindow.getCurrentWebviewWindow(); if (e.payload !== "false") { await resizeWindow(); diff --git a/src/utils/TGWindow.ts b/src/utils/TGWindow.ts index 5990dcc5..282e1737 100644 --- a/src/utils/TGWindow.ts +++ b/src/utils/TGWindow.ts @@ -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 */ export async function resizeWindow(): Promise { @@ -116,12 +117,13 @@ export async function resizeWindow(): Promise { 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(); }