mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-03-31 06:29:46 +08:00
@@ -1,7 +1,7 @@
|
||||
//! @file src/client/utils.rs
|
||||
//! @desc 结合屏幕分辨率获取窗口大小
|
||||
//! @since Beta v0.7.6
|
||||
// 结合屏幕分辨率获取窗口大小
|
||||
// @since Beta v0.9.1
|
||||
|
||||
use crate::utils;
|
||||
use tauri::{AppHandle, Manager, Monitor};
|
||||
|
||||
pub fn get_window_size(app: AppHandle, width: f64, height: f64) -> (f64, f64) {
|
||||
@@ -17,12 +17,13 @@ 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 mut text_scale = utils::read_text_scale_factor().unwrap_or(1.0);
|
||||
let mut get_width: f64 = 0.0;
|
||||
let mut get_height: f64 = 0.0;
|
||||
// 忽略未使用
|
||||
println!("{} {}", get_width, get_height);
|
||||
get_width = (width * width_scale / monitor_scale).round();
|
||||
get_height = (height * height_scale / monitor_scale).round();
|
||||
get_width = (width * width_scale / (monitor_scale * text_scale)).round();
|
||||
get_height = (height * height_scale / (monitor_scale * text_scale)).round();
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
get_width = (width * width_scale).round();
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// 监听系统文本放缩
|
||||
// @since Beta v0.9.1
|
||||
|
||||
use crate::utils;
|
||||
use std::{thread, time::Duration};
|
||||
use tauri::{AppHandle, Emitter};
|
||||
use widestring::U16CString;
|
||||
@@ -29,9 +28,7 @@ pub fn init(app: AppHandle) {
|
||||
RegNotifyChangeKeyValue(hkey, 0, REG_NOTIFY_CHANGE_LAST_SET, std::ptr::null_mut(), 0);
|
||||
|
||||
if notify_status == ERROR_SUCCESS {
|
||||
if let Ok(scale) = utils::read_text_scale_factor() {
|
||||
let _ = app.emit("text_scale_change", scale);
|
||||
}
|
||||
let _ = app.emit("text_scale_change", "");
|
||||
} else {
|
||||
eprintln!("❌ 注册表监听失败: {}", notify_status);
|
||||
break;
|
||||
|
||||
@@ -48,6 +48,7 @@ let dpListener: UnlistenFn | null = null;
|
||||
let resizeListener: UnlistenFn | null = null;
|
||||
let yaeListener: UnlistenFn | null = null;
|
||||
let closeListener: UnlistenFn | null = null;
|
||||
let textScaleListener: UnlistenFn | null = null;
|
||||
let yaeFlag: Array<string> = [];
|
||||
|
||||
onMounted(async () => {
|
||||
@@ -67,6 +68,7 @@ onMounted(async () => {
|
||||
document.documentElement.className = theme.value;
|
||||
themeListener = await event.listen<string>("readTheme", handleThemeListen);
|
||||
resizeListener = await event.listen<string>("needResize", handleResizeListen);
|
||||
textScaleListener = await event.listen<void>("text_scale_change", resizeWindow);
|
||||
const isShow = await win.isVisible();
|
||||
if (!isShow) {
|
||||
await win.center();
|
||||
@@ -95,6 +97,10 @@ onUnmounted(() => {
|
||||
closeListener();
|
||||
closeListener = null;
|
||||
}
|
||||
if (textScaleListener !== null) {
|
||||
textScaleListener();
|
||||
textScaleListener = null;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,29 +19,26 @@
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { fetch } from "@tauri-apps/plugin-http";
|
||||
import { parseBirthGal, parseBirthSrc } from "@utils/birthParser.js";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { listen, type UnlistenFn } from "@tauri-apps/api/event";
|
||||
import { onMounted, onUnmounted } from "vue";
|
||||
|
||||
import { ArcBirDraw } from "@/data/index.js";
|
||||
let textScaleListener: UnlistenFn | null = null;
|
||||
onMounted(async () => {
|
||||
textScaleListener = await listen("text_scale_change", (payload) => {
|
||||
console.log(payload);
|
||||
});
|
||||
});
|
||||
onUnmounted(() => {
|
||||
if (textScaleListener !== null) {
|
||||
textScaleListener();
|
||||
textScaleListener = null;
|
||||
}
|
||||
});
|
||||
|
||||
async function test() {
|
||||
for (const item of ArcBirDraw) {
|
||||
console.log("尝试解析", item.op_id, item.role_name);
|
||||
const srcResp = await fetch(item.gal_resource, {
|
||||
method: "GET",
|
||||
headers: { "Content-Type": "text/xml" },
|
||||
});
|
||||
const srcRes = await srcResp.text();
|
||||
const parseSrc = parseBirthSrc(new DOMParser().parseFromString(srcRes, "text/xml"));
|
||||
console.log("parsedSrc", parseSrc);
|
||||
const galResp = await fetch(item.gal_xml, {
|
||||
method: "GET",
|
||||
headers: { "Content-Type": "text/xml" },
|
||||
});
|
||||
const galRes = await galResp.text();
|
||||
const parseGal = parseBirthGal(new DOMParser().parseFromString(galRes, "text/xml"), parseSrc);
|
||||
console.log("parsedScene", parseGal);
|
||||
}
|
||||
const res = await invoke("read_text_scale");
|
||||
console.log(res);
|
||||
}
|
||||
</script>
|
||||
<style lang="css" scoped>
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
/**
|
||||
* 窗口创建相关工具函数
|
||||
* @since Beta v0.7.9
|
||||
* @since Beta v0.9.1
|
||||
*/
|
||||
|
||||
import type { RenderCard } from "@comp/app/t-postcard.vue";
|
||||
import showSnackbar from "@comp/func/snackbar.js";
|
||||
import { core, webviewWindow, window as TauriWindow } from "@tauri-apps/api";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { PhysicalSize } from "@tauri-apps/api/dpi";
|
||||
import { currentMonitor, WindowOptions } from "@tauri-apps/api/window";
|
||||
import { openUrl } from "@tauri-apps/plugin-opener";
|
||||
@@ -100,7 +101,7 @@ export function getWindowSize(label: string): PhysicalSize {
|
||||
|
||||
/**
|
||||
* 窗口适配
|
||||
* @since Beta v0.7.9
|
||||
* @since Beta v0.9.1
|
||||
* @returns 无返回值
|
||||
*/
|
||||
export async function resizeWindow(): Promise<void> {
|
||||
@@ -110,6 +111,7 @@ export async function resizeWindow(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
const windowCur = webviewWindow.getCurrentWebviewWindow();
|
||||
const textScale = await invoke<number>("read_text_scale");
|
||||
if (await windowCur.isMaximized()) return;
|
||||
const designSize = getWindowSize(windowCur.label);
|
||||
const widthScale = screen.size.width / 1920;
|
||||
@@ -117,7 +119,7 @@ export async function resizeWindow(): Promise<void> {
|
||||
const targetWidth = Math.round(designSize.width * widthScale);
|
||||
const targetHeight = Math.round(designSize.height * heightScale);
|
||||
await windowCur.setSize(new PhysicalSize(targetWidth, targetHeight));
|
||||
const targetZoom = Math.min(widthScale, heightScale) / screen.scaleFactor;
|
||||
const targetZoom = Math.min(widthScale, heightScale) / (screen.scaleFactor * textScale);
|
||||
await windowCur.setZoom(targetZoom);
|
||||
await windowCur.setFocus();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user