From ac4d2a319f7ad946f81f2d0aad50b7987d3a6c50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9B=AE=E6=A3=83?= Date: Sat, 8 Mar 2025 16:06:06 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=B8=20=E5=8D=B3=E6=97=B6=E5=93=8D?= =?UTF-8?q?=E5=BA=94=E9=A1=B5=E9=9D=A2=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 52 ++++++++------------ src/components/pageHome/ph-position-card.vue | 8 ++- src/pages/common/PageConfig.vue | 13 +++-- src/utils/TGWindow.ts | 52 ++++++++++++++++++-- 4 files changed, 79 insertions(+), 46 deletions(-) diff --git a/src/App.vue b/src/App.vue index 17ed114a..e2484219 100644 --- a/src/App.vue +++ b/src/App.vue @@ -18,9 +18,8 @@ import showSnackbar from "@comp/func/snackbar.js"; import TGSqlite from "@Sqlite/index.js"; import TSUserAccount from "@Sqlite/modules/userAccount.js"; import { app, core, event, webviewWindow } from "@tauri-apps/api"; -import { PhysicalSize } from "@tauri-apps/api/dpi"; import type { Event, UnlistenFn } from "@tauri-apps/api/event"; -import { currentMonitor, getCurrentWindow } from "@tauri-apps/api/window"; +import { getCurrentWindow, LogicalSize } from "@tauri-apps/api/window"; import { mkdir } from "@tauri-apps/plugin-fs"; import { storeToRefs } from "pinia"; import { computed, onMounted, onUnmounted, ref } from "vue"; @@ -30,6 +29,7 @@ import { useAppStore } from "@/store/modules/app.js"; import { useUserStore } from "@/store/modules/user.js"; import { getBuildTime } from "@/utils/TGBuild.js"; import TGLogger from "@/utils/TGLogger.js"; +import { getWindowSize, resizeWindow } from "@/utils/TGWindow.js"; import OtherApi from "@/web/request/otherReq.js"; const router = useRouter(); @@ -40,6 +40,7 @@ const vuetifyTheme = computed(() => (theme.value === "dark" ? "dark" : " let themeListener: UnlistenFn | null = null; let urlListener: UnlistenFn | null = null; +let resizeListener: UnlistenFn | null = null; onMounted(async () => { const win = getCurrentWindow(); @@ -51,43 +52,28 @@ onMounted(async () => { await core.invoke("init_app"); urlListener = await getDeepLink(); } - if (needResize.value !== "false") await checkResize(); + if (needResize.value !== "false") await resizeWindow(); document.documentElement.className = theme.value; themeListener = await event.listen("readTheme", (e: Event) => { theme.value = e.payload; document.documentElement.className = theme.value; }); + resizeListener = await event.listen("needResize", async (e: Event) => { + console.log(needResize); + const windowCur = webviewWindow.getCurrentWebviewWindow(); + if (e.payload !== "false") { + await resizeWindow(); + } else { + const size = getWindowSize(windowCur.label); + await windowCur.setSize(new LogicalSize(size.width, size.height)); + await windowCur.setZoom(1); + } + await windowCur.center(); + }); await getCurrentWindow().show(); + await getCurrentWindow().center(); }); -async function checkResize(): Promise { - const screen = await currentMonitor(); - if (screen === null) { - showSnackbar.error("获取屏幕信息失败!", 3000); - return; - } - const windowCur = webviewWindow.getCurrentWebviewWindow(); - if (await windowCur.isMaximized()) return; - const designSize = getSize(windowCur.label); - const widthScale = screen.size.width / 1920; - const heightScale = screen.size.height / 1080; - await windowCur.setSize( - new PhysicalSize( - Math.round(designSize.width * widthScale), - Math.round(designSize.height * heightScale), - ), - ); - await windowCur.setZoom((1 / screen.scaleFactor) * Math.min(widthScale, heightScale)); - await windowCur.setFocus(); - return; -} - -function getSize(label: string): PhysicalSize { - if (label === "TeyvatGuide") return new PhysicalSize(1600, 900); - if (label === "Sub_window" || label === "Dev_JSON") return new PhysicalSize(960, 720); - return new PhysicalSize(1280, 720); -} - // 启动后只执行一次的监听 async function listenOnInit(): Promise { console.info("[App][listenOnInit] 监听初始化事件!"); @@ -261,6 +247,10 @@ onUnmounted(() => { urlListener(); urlListener = null; } + if (resizeListener !== null) { + resizeListener(); + resizeListener = null; + } });