监听窗口缩放比例,默认按照缩放计算并设置一次窗口大小

This commit is contained in:
heixiansen
2025-06-09 15:49:43 +08:00
parent bdeda8bebd
commit 136ce06c33
3 changed files with 35 additions and 18 deletions
+8 -5
View File
@@ -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));
}
}
};
+26 -13
View File
@@ -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 => {
+1
View File
@@ -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": [