refactor(主题): 将主题相关逻辑提取到ThemeHelper类中
重构主题相关代码,将重复的IsSystemThemeLight方法和主题应用逻辑提取到新的ThemeHelper工具类中 简化多个窗口的主题处理代码,统一使用ThemeHelper进行主题管理
This commit is contained in:
@@ -819,21 +819,8 @@ namespace Ink_Canvas.Windows
|
||||
{
|
||||
try
|
||||
{
|
||||
bool isDarkTheme = false;
|
||||
|
||||
if (settings.Appearance.Theme == 0) // 浅色主题
|
||||
{
|
||||
isDarkTheme = false;
|
||||
}
|
||||
else if (settings.Appearance.Theme == 1) // 深色主题
|
||||
{
|
||||
isDarkTheme = true;
|
||||
}
|
||||
else // 跟随系统主题
|
||||
{
|
||||
bool isSystemLight = IsSystemThemeLight();
|
||||
isDarkTheme = !isSystemLight;
|
||||
}
|
||||
bool isDarkTheme = settings.Appearance.Theme == 1 ||
|
||||
(settings.Appearance.Theme == 2 && !ThemeHelper.IsSystemThemeLight());
|
||||
|
||||
if (isDarkTheme)
|
||||
{
|
||||
@@ -864,31 +851,6 @@ namespace Ink_Canvas.Windows
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsSystemThemeLight()
|
||||
{
|
||||
var light = false;
|
||||
try
|
||||
{
|
||||
var registryKey = Microsoft.Win32.Registry.CurrentUser;
|
||||
var themeKey = registryKey.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize");
|
||||
if (themeKey != null)
|
||||
{
|
||||
var value = themeKey.GetValue("AppsUseLightTheme");
|
||||
if (value != null)
|
||||
{
|
||||
light = (int)value == 1;
|
||||
}
|
||||
themeKey.Close();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// 如果读取注册表失败,默认为浅色主题
|
||||
light = true;
|
||||
}
|
||||
return light;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前倒计时状态
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user