初始化 monorepo: Go后端(7微服务) + Unity客户端(9模块) + 启动器 HTML5原型: Three.js 3D体素世界, Perlin噪声地形, 原版材质, 22种方块 Minecraft创造模式背包: 双栏布局, 拖拽移动物品, 方向性元件引脚 AI助搭策划文档 + 客户端/服务端骨架 + Docker Compose + CI
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Security;
|
||||
using Microsoft.Win32;
|
||||
using PCL.Core.Logging;
|
||||
|
||||
namespace PCL.Core.Utils.OS;
|
||||
|
||||
public class SystemTheme {
|
||||
private const string ThemeRegistryPath = @"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize";
|
||||
private const string AppsUseLightThemeKey = "AppsUseLightTheme";
|
||||
|
||||
/// <summary>
|
||||
/// 检查系统是否处于深色模式。
|
||||
/// </summary>
|
||||
/// <returns>如果系统使用深色模式,则返回 true;否则返回 false(包括注册表不可访问的情况)。</returns>
|
||||
public static bool IsSystemInDarkMode() {
|
||||
try {
|
||||
using var registryKey = Registry.CurrentUser.OpenSubKey(ThemeRegistryPath);
|
||||
if (registryKey is null) {
|
||||
LogWrapper.Warn($"注册表键 {ThemeRegistryPath} 不存在");
|
||||
return false;
|
||||
}
|
||||
|
||||
var value = registryKey.GetValue(AppsUseLightThemeKey) as int?;
|
||||
return value == 0; // 0 表示深色模式(AppsUseLightTheme = false)
|
||||
} catch (Exception ex) when (ex is SecurityException or IOException) {
|
||||
LogWrapper.Warn(ex, $"无法访问注册表键 {ThemeRegistryPath}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user