mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-12 09:18:14 +08:00
💄 根据屏幕缩放调整应用缩放
This commit is contained in:
24
src/App.vue
24
src/App.vue
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { app, event, core, webviewWindow } from "@tauri-apps/api";
|
import { app, event, core, webviewWindow } from "@tauri-apps/api";
|
||||||
|
import { PhysicalSize } from "@tauri-apps/api/dpi";
|
||||||
import { UnlistenFn, Event } from "@tauri-apps/api/event";
|
import { UnlistenFn, Event } from "@tauri-apps/api/event";
|
||||||
import { mkdir } from "@tauri-apps/plugin-fs";
|
import { mkdir } from "@tauri-apps/plugin-fs";
|
||||||
import { storeToRefs } from "pinia";
|
import { storeToRefs } from "pinia";
|
||||||
@@ -52,8 +53,31 @@ onBeforeMount(async () => {
|
|||||||
urlListener = await getDeepLink();
|
urlListener = await getDeepLink();
|
||||||
}
|
}
|
||||||
await win.show();
|
await win.show();
|
||||||
|
await checkResize();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
async function checkResize(): Promise<void> {
|
||||||
|
const windowCur = await webviewWindow.getCurrent();
|
||||||
|
const winScale = await windowCur.scaleFactor();
|
||||||
|
if (winScale > 1) {
|
||||||
|
const newSize = getSize(windowCur.label);
|
||||||
|
await windowCur.setSize(newSize);
|
||||||
|
await windowCur.setZoom(1 / winScale);
|
||||||
|
await windowCur.center();
|
||||||
|
} else if (winScale === 1) {
|
||||||
|
const newSize = getSize(windowCur.label);
|
||||||
|
await windowCur.setSize(newSize);
|
||||||
|
await windowCur.setZoom(1);
|
||||||
|
await windowCur.center();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
document.documentElement.className = theme.value;
|
document.documentElement.className = theme.value;
|
||||||
themeListener = event.listen("readTheme", async (e: Event<string>) => {
|
themeListener = event.listen("readTheme", async (e: Event<string>) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user