mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-03-15 03:53:16 +08:00
🥅 当无法读取注册表时返回1.0
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// 杂项
|
||||
// @since Beta v0.9.1
|
||||
// @since Beta v0.9.2
|
||||
|
||||
/// 获取当前系统的文本缩放比例(TextScaleFactor)
|
||||
/// 返回值示例:1.0 表示 100%,1.25 表示 125%
|
||||
@@ -13,10 +13,14 @@ pub fn read_text_scale_factor() -> Result<f64, String> {
|
||||
use winreg::enums::*;
|
||||
use winreg::RegKey;
|
||||
let hkcu = RegKey::predef(HKEY_CURRENT_USER);
|
||||
let key = hkcu
|
||||
.open_subkey("Software\\Microsoft\\Accessibility")
|
||||
.map_err(|e| format!("无法打开注册表: {}", e))?;
|
||||
|
||||
// 如果打开失败,直接返回默认值 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)
|
||||
|
||||
Reference in New Issue
Block a user