From 60faa01769ab3713b6f71a49c3f277b0658dc390 Mon Sep 17 00:00:00 2001 From: heixiansen Date: Mon, 9 Jun 2025 15:49:43 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=91=E5=90=AC=E7=AA=97=E5=8F=A3=E7=BC=A9?= =?UTF-8?q?=E6=94=BE=E6=AF=94=E4=BE=8B=EF=BC=8C=E9=BB=98=E8=AE=A4=E6=8C=89?= =?UTF-8?q?=E7=85=A7=E7=BC=A9=E6=94=BE=E8=AE=A1=E7=AE=97=E5=B9=B6=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E4=B8=80=E6=AC=A1=E7=AA=97=E5=8F=A3=E5=A4=A7=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composables/windows.ts | 13 ++++++---- pages/index.vue | 39 +++++++++++++++++++---------- src-tauri/capabilities/default.json | 1 + 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/composables/windows.ts b/composables/windows.ts index 106cd91..a4f5501 100644 --- a/composables/windows.ts +++ b/composables/windows.ts @@ -1,5 +1,5 @@ import { type UnlistenFn } from "@tauri-apps/api/event"; -import { getCurrentWindow, PhysicalPosition, type WindowOptions, Window, currentMonitor } from "@tauri-apps/api/window"; +import { getCurrentWindow, PhysicalPosition, type WindowOptions, Window, currentMonitor, PhysicalSize } from "@tauri-apps/api/window"; import { WebviewWindow } from "@tauri-apps/api/webviewWindow"; import type { WebviewLabel, WebviewOptions } from "@tauri-apps/api/webview"; import useMainStore from "@/stores/index"; @@ -44,18 +44,21 @@ export default async ( defaultOpts.parent = appWindow; // console.error(logicalPosition); if (defaultOpts.x == 0 && defaultOpts.y == 0) { - const appSize = await appWindow.outerSize(); + const logicalAppSize = { + width: 340, + height: 305 + } const factor = await appWindow.scaleFactor(); const appPosition = await appWindow.outerPosition(); - const logicalPosition = new PhysicalPosition(appPosition.x + appSize.width, appPosition.y).toLogical(factor); + const logicalPosition = new PhysicalPosition(appPosition.x + Math.ceil((logicalAppSize.width + 5) * factor), appPosition.y).toLogical(factor); defaultOpts.x = logicalPosition.x; defaultOpts.y = logicalPosition.y; } } dialog = new WebviewWindow(label, { ...defaultOpts, ...options }); await dealCloseListener(dialog, label, beforeCloseFunc); - afterCreatedFunc && (await afterCreatedFunc(dialog, appWindow)); await dialog.show(); + afterCreatedFunc && (await afterCreatedFunc(dialog, appWindow)); } else { const visible = await dialog.isVisible(); if (visible) { @@ -63,8 +66,8 @@ export default async ( } else { const appWindow = getCurrentWindow(); await dealCloseListener(dialog, label, beforeCloseFunc); - afterCreatedFunc && (await afterCreatedFunc(dialog, appWindow)); await dialog.show(); + afterCreatedFunc && (await afterCreatedFunc(dialog, appWindow)); } } }; diff --git a/pages/index.vue b/pages/index.vue index 1909777..3476b01 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -726,7 +726,7 @@ import { initStartWinIpBroadcast } from "~/composables/netcard"; import useMainStore from "@/stores/index"; import { ElMessage, ElMessageBox, ElTooltip } from "element-plus"; - import { getCurrentWindow, type Window } from "@tauri-apps/api/window"; + import { getCurrentWindow, PhysicalSize, type Window } from "@tauri-apps/api/window"; import { getAllWebviewWindows, WebviewWindow } from "@tauri-apps/api/webviewWindow"; import etWindows, { dataSubscribe } from "@/composables/windows"; import { resourceDir as getResourceDir, join } from "@tauri-apps/api/path"; @@ -1233,6 +1233,18 @@ await appWindow.show(); await appWindow.setFocus(); } + const appWindow = getCurrentWindow(); + const logicalAppSize = { + width: 340, + height: 305 + } + const scaleFactor = await appWindow.scaleFactor(); + const size = new PhysicalSize(Math.ceil(logicalAppSize.width * scaleFactor), Math.ceil(logicalAppSize.height * scaleFactor)); + appWindow.setSize(size); + appWindow.onScaleChanged(({ payload: { scaleFactor } }) => { + console.log("scaleFactor", scaleFactor); + appWindow.setSize(new PhysicalSize(Math.ceil(logicalAppSize.width * scaleFactor), Math.ceil(logicalAppSize.height * scaleFactor))); + }); }; let logsTimer: NodeJS.Timeout | null = null; @@ -1705,18 +1717,18 @@ const handleReconnect = async () => { if (data.isStart) { - ElMessage.info({ - message: "正在重新联机...", - duration: 2200 - }); - await handleConnection(); - setTimeout(() => { - handleConnection(); - }, 2000); - }else { + ElMessage.info({ + message: "正在重新联机...", + duration: 2200 + }); + await handleConnection(); + setTimeout(() => { handleConnection(); - } - } + }, 2000); + } else { + handleConnection(); + } + }; const handleDeleteAdminConfig = async () => { const path = configAdminData.fileName; @@ -1957,7 +1969,7 @@ await etWindows( "storage-listener", { - title: "自建服务器", + title: "存储监听", minWidth: 0, minHeight: 0, width: 0, @@ -1968,6 +1980,7 @@ transparent: true, hiddenTitle: true, alwaysOnBottom: true, + visible: false, url: "#/storage-listener" }, dialog => { diff --git a/src-tauri/capabilities/default.json b/src-tauri/capabilities/default.json index 52f92bb..5f96aaf 100644 --- a/src-tauri/capabilities/default.json +++ b/src-tauri/capabilities/default.json @@ -26,6 +26,7 @@ "core:tray:allow-get-by-id", "core:tray:allow-set-icon", "core:tray:allow-new", + "core:window:allow-set-size", { "identifier": "shell:allow-spawn", "allow": [