Files
TeyvatGuide/src-tauri/src/utils.rs
BTMuli e3f3a038f4 🎨 code fmt
2026-01-16 19:39:27 +08:00

29 lines
794 B
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 杂项
// @since Beta v0.9.2
/// 获取当前系统的文本缩放比例TextScaleFactor
/// 返回值示例1.0 表示 100%1.25 表示 125%
pub fn read_text_scale_factor() -> Result<f64, String> {
#[cfg(not(target_os = "windows"))]
{
Ok(1.0)
}
#[cfg(target_os = "windows")]
{
use winreg::RegKey;
use winreg::enums::*;
let hkcu = RegKey::predef(HKEY_CURRENT_USER);
// 如果打开失败,直接返回默认值 1.0
let key = match hkcu.open_subkey("Software\\Microsoft\\Accessibility") {
Ok(k) => k,
Err(e) => {
log::error!("无法打开注册表: {}", e);
return Ok(1.0);
}
};
let value: u32 = key.get_value("TextScaleFactor").unwrap_or(100u32); // 默认值为 100%
Ok(value as f64 / 100.0)
}
}